示例#1
0
        public void Render_should_render_minimal_info_for_artificial_commits(string artificialGuid)
        {
            var author     = "John Doe (Acme Inc) <*****@*****.**>";
            var committer  = author;
            var authorDate = DateTime.Parse("2017-06-17T16:38:40+03");
            var commitDate = authorDate;
            var data       = new CommitData(artificialGuid,
                                            Guid.NewGuid().ToString("N"),
                                            new ReadOnlyCollection <string>(new List <string> {
                "3b6ce324e30ed7fda24483fd56a180c34a262202", "2a8788ff15071a202505a96f80796dbff5750ddf", "8e66fa8095a86138a7c7fb22318d2f819669831e"
            }),
                                            author, authorDate,
                                            committer, commitDate, "");

            _linkFactory.CreateLink(author, Arg.Any <string>()).Returns(x => author);

            var result = _renderer.Render(data, false);

            result.Should().Be($"Author:        John Doe (Acme Inc) <*****@*****.**>{Environment.NewLine}Parent(s):     3b6ce324e3 2a8788ff15 8e66fa8095");
            _labelFormatter.Received(1).FormatLabel(Strings.GetAuthorText(), Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(Strings.GetDateText(), Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(Strings.GetCommitHashText(), Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(Strings.GetAuthorDateText(), Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(Strings.GetCommitterText(), Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(Strings.GetCommitDateText(), Arg.Any <int>());
        }
        /// <summary>
        /// Generate header.
        /// </summary>
        public string RenderPlain(CommitData commitData)
        {
            if (commitData is null)
            {
                throw new ArgumentNullException(nameof(commitData));
            }

            bool authorIsCommitter = string.Equals(commitData.Author, commitData.Committer, StringComparison.CurrentCulture);
            bool datesEqual        = commitData.AuthorDate.EqualsExact(commitData.CommitDate);
            var  padding           = _headerRendererStyleProvider.GetMaxWidth();

            var header = new StringBuilder();

            header.AppendLine(_labelFormatter.FormatLabel(TranslatedStrings.Author, padding) + commitData.Author);
            header.AppendLine(_labelFormatter.FormatLabel(datesEqual ? TranslatedStrings.Date : TranslatedStrings.AuthorDate, padding) + _dateFormatter.FormatDateAsRelativeLocal(commitData.AuthorDate));
            if (!authorIsCommitter)
            {
                header.AppendLine(_labelFormatter.FormatLabel(TranslatedStrings.Committer, padding) + commitData.Committer);
            }

            if (!datesEqual)
            {
                header.AppendLine(_labelFormatter.FormatLabel(TranslatedStrings.CommitDate, padding) + _dateFormatter.FormatDateAsRelativeLocal(commitData.CommitDate));
            }

            header.Append(_labelFormatter.FormatLabel(TranslatedStrings.CommitHash, padding) + commitData.ObjectId);

            return(header.ToString());
        }
        public void RenderPlain_should_render_commit_date_if_different_from_author_date()
        {
            var author     = "John Doe (Acme Inc) <*****@*****.**>";
            var committer  = author;
            var authorDate = DateTime.Parse("2017-06-17T16:38:40+03");
            var commitDate = DateTime.Parse("2017-10-23T06:17:11+05");
            var data       = new CommitData(
                ObjectId.Parse("7fa3109989e0523aeacb178995a2a3aa6c302a2c"),
                ObjectId.Random(),
                Array.Empty <ObjectId>(),
                author, authorDate,
                committer, commitDate, "");

            _linkFactory.CreateLink(author, Arg.Any <string>()).Returns(x => author);
            _dateFormatter.FormatDateAsRelativeLocal(authorDate).Returns("6 months ago (06/17/2017 23:38:40)");
            _dateFormatter.FormatDateAsRelativeLocal(commitDate).Returns("2 months ago (10/23/2017 12:17:11)");

            var result = _renderer.RenderPlain(data);

            result.Should().Be($"Author:        John Doe (Acme Inc) <*****@*****.**>{Environment.NewLine}Author date:   6 months ago (06/17/2017 23:38:40){Environment.NewLine}Commit date:   2 months ago (10/23/2017 12:17:11){Environment.NewLine}Commit hash:   7fa3109989e0523aeacb178995a2a3aa6c302a2c");
            _labelFormatter.Received(1).FormatLabel(TranslatedStrings.Author, Arg.Any <int>());
            _labelFormatter.Received(1).FormatLabel(TranslatedStrings.AuthorDate, Arg.Any <int>());
            _labelFormatter.Received(1).FormatLabel(TranslatedStrings.CommitDate, Arg.Any <int>());
            _labelFormatter.Received(1).FormatLabel(TranslatedStrings.CommitHash, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(TranslatedStrings.Date, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(TranslatedStrings.Committer, Arg.Any <int>());
        }
        public void Render_should_render_commit_parents()
        {
            var author     = "John Doe (Acme Inc) <*****@*****.**>";
            var committer  = author;
            var authorDate = DateTime.Parse("2017-06-17T16:38:40+03");
            var commitDate = authorDate;
            var data       = new CommitData(
                ObjectId.Parse("7fa3109989e0523aeacb178995a2a3aa6c302a2c"),
                ObjectId.Random(),
                _parentHashes,
                author, authorDate,
                committer, commitDate, "");

            _linkFactory.CreateLink(author, Arg.Any <string>()).Returns(x => author);
            _dateFormatter.FormatDateAsRelativeLocal(authorDate).Returns("6 months ago (06/17/2017 23:38:40)");

            var result = _renderer.Render(data, false);

            result.Should().Be($"Author:        John Doe (Acme Inc) <*****@*****.**>{Environment.NewLine}Date:          6 months ago (06/17/2017 23:38:40){Environment.NewLine}Commit hash:   7fa3109989e0523aeacb178995a2a3aa6c302a2c{Environment.NewLine}" +
                               $"Parents:       {_parentHashes[0].ToShortString()} {_parentHashes[1].ToShortString()} {_parentHashes[2].ToShortString()}");
            _labelFormatter.Received(1).FormatLabel(TranslatedStrings.Author, Arg.Any <int>());
            _labelFormatter.Received(1).FormatLabel(TranslatedStrings.Date, Arg.Any <int>());
            _labelFormatter.Received(1).FormatLabel(TranslatedStrings.CommitHash, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(TranslatedStrings.AuthorDate, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(TranslatedStrings.Committer, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(TranslatedStrings.CommitDate, Arg.Any <int>());
        }
示例#5
0
        public void Render_should_render_commit_parents()
        {
            var author     = "John Doe (Acme Inc) <*****@*****.**>";
            var committer  = author;
            var authorDate = DateTime.Parse("2017-06-17T16:38:40+03");
            var commitDate = authorDate;
            var data       = new CommitData("8ea78df688ec4719a9756c1199a515d1",
                                            Guid.NewGuid().ToString("N"),
                                            new ReadOnlyCollection <string>(new List <string> {
                "3b6ce324e30ed7fda24483fd56a180c34a262202", "2a8788ff15071a202505a96f80796dbff5750ddf", "8e66fa8095a86138a7c7fb22318d2f819669831e"
            }),
                                            author, authorDate,
                                            committer, commitDate, "");

            _linkFactory.CreateLink(author, Arg.Any <string>()).Returns(x => author);
            _dateFormatter.FormatDateAsRelativeLocal(authorDate).Returns("6 months ago (06/17/2017 23:38:40)");

            var result = _renderer.Render(data, false);

            result.Should().Be($"Author:        John Doe (Acme Inc) <*****@*****.**>{Environment.NewLine}Date:          6 months ago (06/17/2017 23:38:40){Environment.NewLine}Commit hash:   8ea78df688ec4719a9756c1199a515d1{Environment.NewLine}Parent(s):     3b6ce324e3 2a8788ff15 8e66fa8095");
            _labelFormatter.Received(1).FormatLabel(Strings.GetAuthorText(), Arg.Any <int>());
            _labelFormatter.Received(1).FormatLabel(Strings.GetDateText(), Arg.Any <int>());
            _labelFormatter.Received(1).FormatLabel(Strings.GetCommitHashText(), Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(Strings.GetAuthorDateText(), Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(Strings.GetCommitterText(), Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(Strings.GetCommitDateText(), Arg.Any <int>());
        }
示例#6
0
        public static string GetSubmoduleText(GitModule superproject, string name, string hash)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Submodule " + name);
            sb.AppendLine();
            GitModule module = superproject.GetSubmodule(name);

            if (module.IsValidGitWorkingDir())
            {
                // TEMP, will be moved in the follow up refactor
                ICommitDataManager commitDataManager = new CommitDataManager(() => module);

                string     error = "";
                CommitData data  = commitDataManager.GetCommitData(hash, ref error);
                if (data == null)
                {
                    sb.AppendLine("Commit hash:\t" + hash);
                    return(sb.ToString());
                }

                string header = CommitDataHeaderRenderer.RenderPlain(data);
                string body   = "\n" + data.Body.Trim();
                sb.AppendLine(header);
                sb.Append(body);
            }
            else
            {
                sb.AppendLine("Commit hash:\t" + hash);
            }
            return(sb.ToString());
        }
示例#7
0
        private CommitInfo GetCommitInfo(CommitData commit)
        {
            try
            {
                CommitInfo      CommitInformation = new CommitInfo();
                Regex           rx      = new Regex(@"(?i)(#build:(?<build>[yes|y]))");
                MatchCollection matches = rx.Matches(commit.Comment);
                foreach (Match match in matches)
                {
                    GroupCollection groups = match.Groups;
                    if (groups["build"].Value != string.Empty)
                    {
                        CommitInformation.build = groups["build"].Value;
                    }
                }

                Regex           rxUser      = new Regex(@"((?i)(#GXuser:(?<gxuser>[\w]*$)))");
                MatchCollection matchesuser = rxUser.Matches(commit.Comment);
                foreach (Match match in matchesuser)
                {
                    GroupCollection groups = match.Groups;
                    if (groups["gxuser"].Value != string.Empty)
                    {
                        CommitInformation.GxUser = groups["gxuser"].Value;
                    }
                }

                return(CommitInformation);
            }
            catch
            {
                throw new ArgumentException("Parsing of the comment has failed.");
            }
        }
示例#8
0
        public void Render_should_not_render_committer_info_if_same_as_author_info()
        {
            var author     = "John Doe (Acme Inc) <*****@*****.**>";
            var committer  = author;
            var authorDate = DateTime.Parse("2017-06-17T16:38:40+03");
            var commitDate = authorDate;
            var data       = new CommitData("8ea78df688ec4719a9756c1199a515d1",
                                            Guid.NewGuid().ToString("N"),
                                            new ReadOnlyCollection <string>(new List <string>()),
                                            author, authorDate,
                                            committer, commitDate, "");

            _linkFactory.CreateLink(author, Arg.Any <string>()).Returns(x => author);
            _dateFormatter.FormatDateAsRelativeLocal(authorDate).Returns("6 months ago (06/17/2017 23:38:40)");

            var result = _renderer.Render(data, false);

            result.Should().Be($"Author:        John Doe (Acme Inc) <*****@*****.**>{Environment.NewLine}Date:          6 months ago (06/17/2017 23:38:40){Environment.NewLine}Commit hash:   8ea78df688ec4719a9756c1199a515d1");
            _labelFormatter.Received(1).FormatLabel(Strings.GetAuthorText(), Arg.Any <int>());
            _labelFormatter.Received(1).FormatLabel(Strings.GetDateText(), Arg.Any <int>());
            _labelFormatter.Received(1).FormatLabel(Strings.GetCommitHashText(), Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(Strings.GetAuthorDateText(), Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(Strings.GetCommitterText(), Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(Strings.GetCommitDateText(), Arg.Any <int>());
        }
示例#9
0
        private System.Drawing.Rectangle _headerResize; // Cache desired size for commit header

        private void ReloadCommitInfo()
        {
            _RevisionHeader.BackColor = ColorHelper.MakeColorDarker(this.BackColor);

            showContainedInBranchesToolStripMenuItem.Checked                = AppSettings.CommitInfoShowContainedInBranchesLocal;
            showContainedInBranchesRemoteToolStripMenuItem.Checked          = AppSettings.CommitInfoShowContainedInBranchesRemote;
            showContainedInBranchesRemoteIfNoLocalToolStripMenuItem.Checked = AppSettings.CommitInfoShowContainedInBranchesRemoteIfNoLocal;
            showContainedInTagsToolStripMenuItem.Checked         = AppSettings.CommitInfoShowContainedInTags;
            showMessagesOfAnnotatedTagsToolStripMenuItem.Checked = AppSettings.ShowAnnotatedTagsMessages;

            ResetTextAndImage();

            if (string.IsNullOrEmpty(_revision.Guid))
            {
                return; //is it regular case or should throw an exception
            }
            _RevisionHeader.SelectionTabs = GetRevisionHeaderTabStops();
            _RevisionHeader.Text          = string.Empty;
            _RevisionHeader.Refresh();

            string     error = "";
            CommitData data  = CommitData.CreateFromRevision(_revision);

            if (_revision.Body == null)
            {
                CommitData.UpdateCommitMessage(data, Module, _revision.Guid, ref error);
                _revision.Body = data.Body;
            }

            ThreadPool.QueueUserWorkItem(_ => loadLinksForRevision(_revision));

            if (_sortedRefs == null)
            {
                ThreadPool.QueueUserWorkItem(_ => loadSortedRefs());
            }

            data.ChildrenGuids = _children;
            CommitInformation commitInformation = CommitInformation.GetCommitInfo(data, CommandClick != null, Module);

            _RevisionHeader.SetXHTMLText(commitInformation.Header);
            _RevisionHeader.Height = GetRevisionHeaderHeight();
            _revisionInfo          = commitInformation.Body;
            updateText();
            LoadAuthorImage(data.Author ?? data.Committer);

            if (AppSettings.CommitInfoShowContainedInBranches)
            {
                ThreadPool.QueueUserWorkItem(_ => loadBranchInfo(_revision.Guid));
            }

            if (AppSettings.ShowAnnotatedTagsMessages)
            {
                ThreadPool.QueueUserWorkItem(_ => loadAnnotatedTagInfo(_revision));
            }

            if (AppSettings.CommitInfoShowContainedInTags)
            {
                ThreadPool.QueueUserWorkItem(_ => loadTagInfo(_revision.Guid));
            }
        }
            public void CanSerializeToBson()
            {
                var data = new CommitData(HeaderCollection.Empty, EventCollection.Empty);
                var json = WriteBson(data);

                Validate("FQAAAANoAAUAAAAABGUABQAAAAAA", json);
            }
示例#11
0
        public void Setup()
        {
            var commitGuid = ObjectId.Random();
            var treeGuid   = ObjectId.Random();
            var parentId1  = ObjectId.Random();
            var parentId2  = ObjectId.Random();
            var authorTime = DateTime.UtcNow.AddDays(-3);
            var commitTime = DateTime.UtcNow.AddDays(-2);

            _data = new CommitData(
                commitGuid, treeGuid,
                new[] { parentId1, parentId2 },
                "John Doe (Acme Inc) <*****@*****.**>", authorTime,
                "Jane Doe <*****@*****.**>", commitTime,
                "\tI made a really neat change.\n\nNotes (p4notes):\n\tP4@547123")
            {
                ChildIds = new[]
                {
                    ObjectId.Parse("3b6ce324e30ed7fda24483fd56a180c34a262202"),
                    ObjectId.Parse("2a8788ff15071a202505a96f80796dbff5750ddf"),
                    ObjectId.Parse("8e66fa8095a86138a7c7fb22318d2f819669831e")
                }
            };

            _rendererTabs   = new CommitDataHeaderRenderer(new TabbedHeaderLabelFormatter(), new DateFormatter(), new TabbedHeaderRenderStyleProvider(), new LinkFactory());
            _rendererSpaces = new CommitDataHeaderRenderer(new MonospacedHeaderLabelFormatter(), new DateFormatter(), new MonospacedHeaderRenderStyleProvider(), new LinkFactory());
        }
 private void Blame_CommandClick(object sender, CommitInfo.CommandEventArgs e)
 {
     if (e.Command == "gotocommit")
     {
         if (Module.TryResolvePartialCommitId(e.Data, out var objectId))
         {
             FileChanges.SetSelectedRevision(objectId);
         }
     }
     else if (e.Command == "gotobranch" || e.Command == "gototag")
     {
         CommitData commit = _commitDataManager.GetCommitData(e.Data, out _);
         if (commit != null)
         {
             FileChanges.SetSelectedRevision(new GitRevision(commit.ObjectId));
         }
     }
     else if (e.Command == "navigatebackward")
     {
         FileChanges.NavigateBackward();
     }
     else if (e.Command == "navigateforward")
     {
         FileChanges.NavigateForward();
     }
 }
        public void Render_should_not_render_committer_info_if_same_as_author_info()
        {
            var author     = "John Doe (Acme Inc) <*****@*****.**>";
            var committer  = author;
            var authorDate = DateTime.Parse("2017-06-17T16:38:40+03");
            var commitDate = authorDate;
            var data       = new CommitData(
                ObjectId.Parse("7fa3109989e0523aeacb178995a2a3aa6c302a2c"),
                ObjectId.Random(),
                Array.Empty <ObjectId>(),
                author, authorDate,
                committer, commitDate, "");

            _linkFactory.CreateLink(author, Arg.Any <string>()).Returns(x => author);
            _dateFormatter.FormatDateAsRelativeLocal(authorDate).Returns("6 months ago (06/17/2017 23:38:40)");

            var result = _renderer.Render(data, false);

            result.Should().Be($"Author:        John Doe (Acme Inc) <*****@*****.**>{Environment.NewLine}Date:          6 months ago (06/17/2017 23:38:40){Environment.NewLine}Commit hash:   7fa3109989e0523aeacb178995a2a3aa6c302a2c");
            _labelFormatter.Received(1).FormatLabel(ResourceManager.Strings.Author, Arg.Any <int>());
            _labelFormatter.Received(1).FormatLabel(ResourceManager.Strings.Date, Arg.Any <int>());
            _labelFormatter.Received(1).FormatLabel(ResourceManager.Strings.CommitHash, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(ResourceManager.Strings.AuthorDate, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(ResourceManager.Strings.Committer, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(ResourceManager.Strings.CommitDate, Arg.Any <int>());
        }
        public void Render_should_render_minimal_info_for_artificial_commits(string artificialGuid)
        {
            var author     = "John Doe (Acme Inc) <*****@*****.**>";
            var committer  = author;
            var authorDate = DateTime.Parse("2017-06-17T16:38:40+03");
            var commitDate = authorDate;
            var data       = new CommitData(
                ObjectId.Parse(artificialGuid),
                ObjectId.Random(),
                _parentHashes,
                author, authorDate,
                committer, commitDate, "");

            _linkFactory.CreateLink(author, Arg.Any <string>()).Returns(x => author);

            var result = _renderer.Render(data, false);

            result.Should().Be($"Author:        John Doe (Acme Inc) <*****@*****.**>{Environment.NewLine}" +
                               $"Parents:       {_parentHashes[0].ToShortString()} {_parentHashes[1].ToShortString()} {_parentHashes[2].ToShortString()}");
            _labelFormatter.Received(1).FormatLabel(ResourceManager.Strings.Author, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(ResourceManager.Strings.Date, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(ResourceManager.Strings.CommitHash, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(ResourceManager.Strings.AuthorDate, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(ResourceManager.Strings.Committer, Arg.Any <int>());
            _labelFormatter.DidNotReceive().FormatLabel(ResourceManager.Strings.CommitDate, Arg.Any <int>());
        }
示例#15
0
        public static string GetSubmoduleText(GitModule superproject, string name, string hash, bool cache)
        {
            var sb = new StringBuilder();

            sb.AppendLine("Submodule " + name);
            sb.AppendLine();
            GitModule module = superproject.GetSubmodule(name);

            // Submodule directory must exist to run commands, unknown otherwise
            if (module.IsValidGitWorkingDir())
            {
                // TEMP, will be moved in the follow up refactor
                ICommitDataManager commitDataManager = new CommitDataManager(() => module);

                CommitData data = commitDataManager.GetCommitData(hash, out _, cache);
                if (data is null)
                {
                    sb.AppendLine("Commit hash:\t" + hash);
                    return(sb.ToString());
                }

                string header = PlainCommitDataHeaderRenderer.RenderPlain(data);
                string body   = "\n" + data.Body.Trim();
                sb.AppendLine(header);
                sb.Append(body);
            }
            else
            {
                sb.AppendLine("Commit hash:\t" + hash);
            }

            return(sb.ToString());
        }
示例#16
0
        public static string GetSubmoduleText(VsrModule superproject, string name, string hash)
        {
            var sb = new StringBuilder();

            sb.AppendLine("Submodule " + name);
            sb.AppendLine();
            VsrModule module = superproject.GetSubmodule(name);

            // TODO File access for Git revision access
            if (module.IsValidVersionrWorkingDir())
            {
                // TEMP, will be moved in the follow up refactor
                ICommitDataManager commitDataManager = new CommitDataManager(() => module);

                CommitData data = commitDataManager.GetCommitData(hash, out _);
                if (data == null)
                {
                    sb.AppendLine("Commit hash:\t" + hash);
                    return(sb.ToString());
                }

                string header = PlainCommitDataHeaderRenderer.RenderPlain(data);
                string body   = "\n" + data.Body.Trim();
                sb.AppendLine(header);
                sb.Append(body);
            }
            else
            {
                sb.AppendLine("Commit hash:\t" + hash);
            }

            return(sb.ToString());
        }
        /// <summary>
        /// Finds nearest seen descendents of rev and changes their parent pointers to rev
        /// </summary>
        /// <param name="rev"></param>
        private void UpdateDescendants(GitRevision rev)
        {
            // child, parent
            Queue <Tuple <string, string> > toCheck = new Queue <Tuple <string, string> >();
            // pairs (child, parent) already passed through toCheck
            HashSet <Tuple <string, string> > toCheckDuplicates = new HashSet <Tuple <string, string> >();

            ProvideCommitData(rev.Guid).children.ForEach((g) => {
                Tuple <string, string> t = new Tuple <string, string>(g, rev.Guid);
                toCheck.Enqueue(t);
                toCheckDuplicates.Add(t);
            });
            while (toCheck.Any())
            {
                Tuple <string, string> ct = toCheck.Dequeue();
                string checkChild         = ct.Item1;
                string checkParent        = ct.Item2;

                CommitData cdta             = ProvideCommitData(checkChild);
                bool       allAncestorsSeen = true;
                // cdta was seen and was reached from seen revision (rev)
                // Each of its parents pointing "in the direction" of rev should be replaced with rev
                foreach (string parentId in cdta.parents)
                {
                    if ((parentId == checkParent) && !cdta.rewrittenParents.Contains(rev.Guid))
                    {
                        cdta.rewrittenParents.Add(rev.Guid);
                    }
                    // At the same time we check whether all other parents of cdta are seen or reachable
                    else if (allAncestorsSeen)
                    {
                        CommitData parentDta = ProvideCommitData(parentId);
                        if (!parentDta.WasSeen() && !parentDta.allAncectorsSeen)
                        {
                            allAncestorsSeen = false;
                        }
                    }
                }
                if (allAncestorsSeen)
                {
                    cdta.allAncectorsSeen = true;
                }
                if (!cdta.WasSeen())
                {
                    // If cdta is an unseen revision, then we must continue along its descendants to find
                    // a seen revision
                    cdta.children.ForEach((g) =>
                    {
                        Tuple <string, string> t = new Tuple <string, string>(g, checkChild);
                        if (!toCheckDuplicates.Contains(t))
                        {
                            toCheck.Enqueue(t);
                            toCheckDuplicates.Add(t);
                        }
                    });
                }
            }
        }
示例#18
0
        public Task DispatchAsync(string bucketName, CommitData <IEvent> commit)
        {
            foreach (var @event in commit.Events)
            {
                _dispatcher.TryInvoke(@event);
            }

            return(Task.FromResult(true));
        }
        /// <summary>
        /// Generate header.
        /// </summary>
        public string Render(CommitData commitData, bool showRevisionsAsLinks)
        {
            if (commitData is null)
            {
                throw new ArgumentNullException(nameof(commitData));
            }

            bool   isArtificial      = commitData.ObjectId.IsArtificial;
            bool   authorIsCommitter = string.Equals(commitData.Author, commitData.Committer, StringComparison.CurrentCulture);
            bool   datesEqual        = commitData.AuthorDate.EqualsExact(commitData.CommitDate);
            var    padding           = _headerRendererStyleProvider.GetMaxWidth();
            string authorEmail       = GetEmail(commitData.Author);

            Validates.NotNull(_linkFactory);

            var header = new StringBuilder();

            header.AppendLine(_labelFormatter.FormatLabel(TranslatedStrings.Author, padding) + _linkFactory.CreateLink(commitData.Author, "mailto:" + authorEmail));

            if (!isArtificial)
            {
                header.AppendLine(_labelFormatter.FormatLabel(datesEqual ? TranslatedStrings.Date : TranslatedStrings.AuthorDate, padding) + WebUtility.HtmlEncode(_dateFormatter.FormatDateAsRelativeLocal(commitData.AuthorDate)));
            }

            if (!authorIsCommitter)
            {
                string committerEmail = GetEmail(commitData.Committer);
                header.AppendLine(_labelFormatter.FormatLabel(TranslatedStrings.Committer, padding) + _linkFactory.CreateLink(commitData.Committer, "mailto:" + committerEmail));
            }

            if (!isArtificial)
            {
                if (!datesEqual)
                {
                    header.AppendLine(_labelFormatter.FormatLabel(TranslatedStrings.CommitDate, padding) + WebUtility.HtmlEncode(_dateFormatter.FormatDateAsRelativeLocal(commitData.CommitDate)));
                }

                header.AppendLine(_labelFormatter.FormatLabel(TranslatedStrings.CommitHash, padding) + WebUtility.HtmlEncode(commitData.ObjectId.ToString()));
            }

            if (commitData.ChildIds is not null && commitData.ChildIds.Count != 0)
            {
                header.AppendLine(_labelFormatter.FormatLabel(TranslatedStrings.GetChildren(commitData.ChildIds.Count), padding) + RenderObjectIds(commitData.ChildIds, showRevisionsAsLinks));
            }

            var parentIds = commitData.ParentIds;

            if (parentIds.Count != 0)
            {
                header.AppendLine(_labelFormatter.FormatLabel(TranslatedStrings.GetParents(parentIds.Count), padding) + RenderObjectIds(parentIds, showRevisionsAsLinks));
            }

            // remove the trailing newline character
            header.Length = header.Length - Environment.NewLine.Length;

            return(header.ToString());
        }
示例#20
0
        /// <summary>
        /// Dispatch events of commit
        /// </summary>
        /// <param name="commit">Commit to be dispatched</param>
        private async Task DispatchCommitAsync(CommitData <T> commit)
        {
            var dispatchers = _eventStore.GetDispatchers();

            await Task.WhenAll(dispatchers.Select(x => x.DispatchAsync(BucketName, commit)))
            .ConfigureAwait(false);

            await SetCommitsAsDispatched(commit)
            .ConfigureAwait(false);
        }
示例#21
0
        public void CanCreateCommitInformationFromFormatedData()
        {
            var commitGuid     = Guid.NewGuid();
            var treeGuid       = Guid.NewGuid();
            var parentGuid1    = Guid.NewGuid().ToString();
            var parentGuid2    = Guid.NewGuid().ToString();
            var authorTime     = DateTime.UtcNow.AddDays(-3);
            var commitTime     = DateTime.UtcNow.AddDays(-2);
            var authorUnixTime = (int)(authorTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
            var commitUnixTime = (int)(commitTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;

            var revisionProvider = Substitute.For <IGitRevisionProvider>();
            var parent1Rev       = new GitRevision(aModule: null, guid: parentGuid1)
            {
                Subject = "Parent1"
            };
            var parent2Rev = new GitRevision(aModule: null, guid: parentGuid2)
            {
                Subject = "Parent2"
            };

            revisionProvider.GetRevision(parentGuid1, shortFormat: true).Returns(parent1Rev);
            revisionProvider.GetRevision(parentGuid2, shortFormat: true).Returns(parent2Rev);

            var rawData = commitGuid + "\n" +
                          treeGuid + "\n" +
                          parentGuid1 + " " + parentGuid2 + "\n" +
                          "John Doe (Acme Inc) <*****@*****.**>\n" +
                          authorUnixTime + "\n" +
                          "Jane Doe (Acme Inc) <*****@*****.**>\n" +
                          commitUnixTime + "\n" +
                          "\n" +
                          "\tI made a really neato change.\n\n" +
                          "Notes (p4notes):\n" +
                          "\tP4@547123";

            var expectedHeader = "Author:\t\t<a href='mailto:[email protected]'>John Doe (Acme Inc) &lt;[email protected]&gt;</a>" + Environment.NewLine +
                                 "Author date:\t3 days ago (" + LocalizationHelpers.GetFullDateString(authorTime) + ")" + Environment.NewLine +
                                 "Committer:\t<a href='mailto:[email protected]'>Jane Doe (Acme Inc) &lt;[email protected]&gt;</a>" + Environment.NewLine +
                                 "Commit date:\t2 days ago (" + LocalizationHelpers.GetFullDateString(commitTime) + ")" + Environment.NewLine +
                                 "Commit hash:\t" + commitGuid + Environment.NewLine +
                                 "Parent(s):\t<a href='gitext://gotocommit/" + parentGuid1 + "'>" + parentGuid1.Substring(0, 10) + "</a> " + parent1Rev.Subject +
                                 Environment.NewLine +
                                 " \t\t<a href='gitext://gotocommit/" + parentGuid2 + "'>" + parentGuid2.Substring(0, 10) + "</a> " + parent2Rev.Subject;

            var expectedBody = "\nI made a really neato change." + Environment.NewLine + Environment.NewLine +
                               "Notes (p4notes):" + Environment.NewLine +
                               "\tP4@547123";

            var commitData        = CommitData.CreateFromFormatedData(rawData, new GitModule(""));
            var commitInformation = CommitInformation.GetCommitInfo(revisionProvider, commitData, true);

            Assert.AreEqual(expectedHeader, commitInformation.Header);
            Assert.AreEqual(expectedBody, commitInformation.Body);
        }
示例#22
0
        /// <summary>
        /// Generate header.
        /// </summary>
        /// <returns></returns>
        public string Render(CommitData commitData, bool showRevisionsAsLinks)
        {
            if (commitData == null)
            {
                throw new ArgumentNullException(nameof(commitData));
            }

            bool   isArtificial     = GitRevision.IsArtificial(commitData.Guid);
            bool   authorIsCommiter = string.Equals(commitData.Author, commitData.Committer, StringComparison.CurrentCulture);
            bool   datesEqual       = commitData.AuthorDate.EqualsExact(commitData.CommitDate);
            var    padding          = _headerRendererStyleProvider.GetMaxWidth();
            string authorEmail      = GetEmail(commitData.Author);

            StringBuilder header = new StringBuilder();

            header.AppendLine(_labelFormatter.FormatLabel(Strings.GetAuthorText(), padding) + _linkFactory.CreateLink(commitData.Author, "mailto:" + authorEmail));

            if (!isArtificial)
            {
                header.AppendLine(_labelFormatter.FormatLabel(datesEqual ? Strings.GetDateText() : Strings.GetAuthorDateText(), padding) + WebUtility.HtmlEncode(_dateFormatter.FormatDateAsRelativeLocal(commitData.AuthorDate)));
            }

            if (!authorIsCommiter)
            {
                string committerEmail = GetEmail(commitData.Committer);
                header.AppendLine(_labelFormatter.FormatLabel(Strings.GetCommitterText(), padding) + _linkFactory.CreateLink(commitData.Committer, "mailto:" + committerEmail));
            }

            if (!isArtificial)
            {
                if (!datesEqual)
                {
                    header.AppendLine(_labelFormatter.FormatLabel(Strings.GetCommitDateText(), padding) + WebUtility.HtmlEncode(_dateFormatter.FormatDateAsRelativeLocal(commitData.CommitDate)));
                }

                header.AppendLine(_labelFormatter.FormatLabel(Strings.GetCommitHashText(), padding) + WebUtility.HtmlEncode(commitData.Guid));
            }

            if (commitData.ChildrenGuids != null && commitData.ChildrenGuids.Count != 0)
            {
                header.AppendLine(_labelFormatter.FormatLabel(Strings.GetChildrenText(), padding) + RenderHashCollection(commitData.ChildrenGuids, showRevisionsAsLinks));
            }

            var parentGuids = commitData.ParentGuids.Where(s => !string.IsNullOrEmpty(s)).ToList();

            if (parentGuids.Any())
            {
                header.AppendLine(_labelFormatter.FormatLabel(Strings.GetParentsText(), padding) + RenderHashCollection(parentGuids, showRevisionsAsLinks));
            }

            // remove the trailing newline character
            header.Length = header.Length - Environment.NewLine.Length;

            return(header.ToString());
        }
            public void CanSerializeToJson()
            {
                var data = new CommitData(HeaderCollection.Empty, EventCollection.Empty);
                var json = WriteJson(data);

                Validate(json, @"
{
  ""h"": {},
  ""e"": []
}");
            }
示例#24
0
 private void ParseComments(CommitData commit)
 {
     try
     {
         CommitInformation = GetCommitInfo(commit);
     }
     catch
     {
         throw new ArgumentException("Error parsing the information to be sent.");
     }
 }
示例#25
0
        public CommitData GetOldCommitData(GitModule submodule)
        {
            if (submodule == null || !submodule.IsValidGitWorkingDir())
            {
                return(null);
            }

            string error = "";

            return(CommitData.GetCommitData(submodule, OldCommit, ref error));
        }
            public void CanSerializeToJson()
            {
                var data = new CommitData(HeaderCollection.Empty, EventCollection.Empty);
                var json = WriteJson(data);

                Validate(json, @"
                {
                  ""h"": {},
                  ""e"": []
                }");
            }
示例#27
0
        /// <summary>
        /// Gets the commit info from CommitData.
        /// </summary>
        /// <returns></returns>
        public static CommitInformation GetCommitInfo(IGitRevisionProvider module, CommitData data, bool showRevisionsAsLinks)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            string header = data.GetHeader(module, showRevisionsAsLinks);
            string body   = "\n" + WebUtility.HtmlEncode(data.Body.Trim());

            return(new CommitInformation(header, body));
        }
示例#28
0
        public void Render_should_render_body_without_links()
        {
            var data = new CommitData(ObjectId.Random(), ObjectId.Random(),
                                      new ReadOnlyCollection <string>(new List <string>()),
                                      "John Doe (Acme Inc) <*****@*****.**>", DateTime.UtcNow,
                                      "John Doe <*****@*****.**>", DateTime.UtcNow,
                                      "fix\n\nAllow cherry-picking multiple commits from FormBrowse menu\r\n\r\nThe ability to do so from the RevisionGrid context menu has been added in commit\r\nb3e79447928051cfb3494c9c0ef1a1d0ecde56a8\r\n");

            var result = _rendererReal.Render(data, false);

            result.Should().Be("\nfix\n\nAllow cherry-picking multiple commits from FormBrowse menu\r\n\r\nThe ability to do so from the RevisionGrid context menu has been added in commit\r\nb3e79447928051cfb3494c9c0ef1a1d0ecde56a8");
        }
        public List <Result> CommitEvent(CommitData issue)
        {
            List <Result> listResults = new List <Result>();
            SlackClient   slack       = new SlackClient(this._configuration.Url);

            string        user       = issue.User;
            string        commitDate = issue.CommitDate;
            string        comment    = issue.Comment;
            string        idCommit   = issue.CommitId;
            List <string> objects    = issue.Objects;


            string aSlackUser = this._configuration.Username;
            //string aSlackChannel = this.configuration.Channel;
            //string aPreText = "A new commit has been made by " + user +":";
            string textUser = "******" + user + "*\n\n";
            string aText    = comment + "\n\n";

            if (user != null && user != "")
            {
                aText = textUser + aText;
            }
            string aTitle   = "Commit #" + idCommit;
            string aColor   = "good";
            string gxServer = this._configuration.GxServer;
            string kb       = issue.KBName;
            string aLink    = gxServer + kb;
            string aFooter  = commitDate;

            if (objects != null)
            {
                //slack.AddField(null, String.Join(", ", objects.ToArray()), false);
                aText += String.Join(", ", objects.ToArray());
            }
            foreach (string channel in this._configuration.Channel)
            {
                Result result = slack.PostMessage(
                    username: aSlackUser,
                    channel: channel,
                    text: aText,
                    //preText: aPreText,
                    title: aTitle,
                    title_link: aLink,
                    color: aColor,
                    footer: aFooter
                    //authorName: user
                    );

                listResults.Add(result);
            }
            return(listResults);
        }
 private CommitData ProvideCommitData(string commitId)
 {
     if (!_historyGraph.ContainsKey(commitId))
     {
         CommitData dta = new CommitData();
         _historyGraph.Add(commitId, dta);
         return(dta);
     }
     else
     {
         return(_historyGraph[commitId]);
     }
 }
示例#31
0
        public void Render_should_render_body_without_links()
        {
            var data = new CommitData(ObjectId.Random(), ObjectId.Random(),
                                      Array.Empty <ObjectId>(),
                                      "John Doe (Acme Inc) <*****@*****.**>", DateTime.UtcNow,
                                      "John Doe <*****@*****.**>", DateTime.UtcNow,
                                      "fix\n\nAllow cherry-picking multiple commits from FormBrowse menu\r\n\r\nThe ability to do so from the RevisionGrid context menu has been added in commit\r\nb3e79447928051cfb3494c9c0ef1a1d0ecde56a8\r\n");

            var result = _rendererReal.Render(data, false);

            // TODO remove leading newline and achieve padding at the top via the control layout
            result.Should().Be("fix\n\nAllow cherry-picking multiple commits from FormBrowse menu\r\n\r\nThe ability to do so from the RevisionGrid context menu has been added in commit\r\nb3e79447928051cfb3494c9c0ef1a1d0ecde56a8");
        }
            public void CanSerializeToBson()
            {
                var data = new CommitData(HeaderCollection.Empty, EventCollection.Empty);
                var json = WriteBson(data);

                Validate("FQAAAANoAAUAAAAABGUABQAAAAAA", json);
            }