Example #1
0
        void PrintModifications(HgCli hg, DateTime integrationDate, DateTime prevIntegrationDate)
        {
            var range = _state.DateRangeToHashRange(prevIntegrationDate, integrationDate);

            _logger.PutToFile("range: " + range);
            if (range.IsGood())
            {
                PrintModifications(hg, integrationDate, "(" + _extra.RevSet + ") and (" + range.ToRevSet() + ")");
            }
            else
            {
                _logger.PutToFile("range is empty or not defined");
            }
        }
Example #2
0
        void PrintModifications(HgCli hg, DateTime integrationDate, string revset)
        {
            var log = hg.GetModifications(revset, NormalizeInclude(_extra.Include));

            _logger.PutToFile("hg log entries: " + log.Entries.Count);

            foreach (var entry in log.Entries)
            {
                foreach (var path in entry.PathItems)
                {
                    var element = new XElement("Modification");
                    element.Add(new XElement("Comment", entry.Msg));
                    element.Add(new XElement("FileName", path.Path));
                    element.Add(new XElement("ModifiedTime", integrationDate));
                    element.Add(new XElement("Type", entry.Hash.Substring(0, 12) + " (" + path.Action + ")"));
                    element.Add(new XElement("UserName", entry.Author.Name));
                    StdOut.Write(element);
                }
            }
        }
Example #3
0
        internal int Run(string[] args)
        {
            try {
                _extra = new ExtraArguments(args);

                var uid = CalcFileDifferentiator();

                _logger = new Logger("HgAdapter." + uid + ".log", StdErr);
                _logger.PutToFile("----------");

                _stateFileName = "HgAdapterState." + uid + ".xml";
                _state         = LoadState();

                var action = args[0];

                if (action == "GETMODS")
                {
                    // Executed on the master CCNet server
                    // State is saved to \\ciserver\LocalProjects
                    // CCNet ops confirm that projects with shared LocalProject are allowed

                    var hg = new HgCli(_extra.RepoPath, _logger);
                    var integrationDate     = ParseDate(args[1]);
                    var prevIntegrationDate = ParseDate(args[2]);
                    var prevTip             = _state.GetTip();
                    var isInitialCheck      = String.IsNullOrEmpty(prevTip);

                    _logger.PutToFile("checking modifications from " + prevIntegrationDate.ToString("s") + " to " + integrationDate.ToString("s"));

                    const int changeCheckDiff = -123;
                    if (isInitialCheck || new HgInternals(_extra.RepoPath, this._extra.TimeoutInMilliseconds, _logger).HasRepoChangedSince(prevIntegrationDate.AddSeconds(changeCheckDiff)))
                    {
                        var newTip = hg.GetTip(_extra.RevSet, prevTip);
                        if (!String.IsNullOrEmpty(newTip) && newTip != prevTip)
                        {
                            _logger.PutToFile("new checkpoint: " + newTip);
                            _state.AddCheckpoint(integrationDate, newTip);
                        }
                        else
                        {
                            _logger.PutToFile("no new changesets");
                        }
                    }

                    var trimCount = _state.Checkpoints.RemoveAll(c => (DateTime.Now - c.Date).TotalDays > 7);
                    if (trimCount > 0)
                    {
                        _logger.PutToFile(trimCount + " old checkpoints trimmed");
                    }

                    StdOut.Write("<ArrayOfModification>");
                    PrintModifications(hg, integrationDate, prevIntegrationDate);
                    StdOut.Write("</ArrayOfModification>");

                    SaveState();
                    return(0);
                }


                if (action == "GETSOURCE")
                {
                    // Executed on a worker VM
                    // State changes are not saved

                    GetSource(ParseDate(args[2]), args[1]);
                    return(0);
                }

                throw new NotSupportedException();
            } catch (Exception x) {
                if (_logger != null)
                {
                    _logger.Error(x.Message);
                }
                else
                {
                    StdErr.WriteLine(x);
                }
                return(1);
            } finally {
                DeleteTempListFile();
            }
        }