Пример #1
0
        private void BuildAuthorLine(GitBlameLine line, StringBuilder lineBuilder, string dateTimeFormat,
                                     string filename, bool showAuthor, bool showAuthorDate, bool showOriginalFilePath, bool displayAuthorFirst)
        {
            if (showAuthor && displayAuthorFirst)
            {
                lineBuilder.Append(line.Commit.Author);
                if (showAuthorDate)
                {
                    lineBuilder.Append(" - ");
                }
            }

            if (showAuthorDate)
            {
                lineBuilder.Append(line.Commit.AuthorTime.ToString(dateTimeFormat));
            }

            if (showAuthor && !displayAuthorFirst)
            {
                if (showAuthorDate)
                {
                    lineBuilder.Append(" - ");
                }

                lineBuilder.Append(line.Commit.Author);
            }

            if (showOriginalFilePath && filename != line.Commit.FileName)
            {
                lineBuilder.Append(" - ");
                lineBuilder.Append(line.Commit.FileName);
            }
        }
Пример #2
0
        public void LoadBlame(string guid, string fileName, RevisionGrid revGrid)
        {
            var scrollpos = BlameFile.ScrollPos;

            var blameCommitter = new StringBuilder();
            var blameFile      = new StringBuilder();

            _revGrid = revGrid;

            _blame = GitCommandHelpers.Blame(fileName, guid);

            for (int i = 0; i < _blame.Lines.Count; i++)
            {
                GitBlameLine   blameLine   = _blame.Lines[i];
                GitBlameHeader blameHeader = _blame.FindHeaderForCommitGuid(blameLine.CommitGuid);
                if (i > 0 && _blame.Lines[i - 1].CommitGuid == blameLine.CommitGuid)
                {
                    blameCommitter.AppendLine(new string(' ', 200));
                }
                else
                {
                    blameCommitter.AppendLine((blameHeader.Author + " - " + blameHeader.AuthorTime.ToString() + " - " + blameHeader.FileName + new string(' ', 100)).Trim(new char[] { '\r', '\n' }));
                }
                blameFile.AppendLine(blameLine.LineText.Trim(new char[] { '\r', '\n' }));
            }

            BlameCommitter.ViewText("committer.txt", blameCommitter.ToString());
            BlameFile.ViewText(fileName, blameFile.ToString());
            BlameFile.ScrollPos = scrollpos;

            BlameFile_SelectedLineChanged(null, 0);
        }
Пример #3
0
        private void ProcessBlame(string filename, GitRevision revision, IReadOnlyList <ObjectId> children, Control controlToMask, int lineNumber, int scrollpos)
        {
            var avatarSize = BlameAuthor.Font.Height + 1;

            var(gutter, body, avatars) = BuildBlameContents(filename, avatarSize);

            BlameAuthor.SetGitBlameGutter(avatars);

            ThreadHelper.JoinableTaskFactory.RunAsync(
                () => BlameAuthor.ViewTextAsync("committer.txt", gutter));
            ThreadHelper.JoinableTaskFactory.RunAsync(
                () => BlameFile.ViewTextAsync(_fileName, body));

            if (lineNumber > 0)
            {
                BlameFile.GoToLine(lineNumber - 1);
            }
            else
            {
                BlameFile.VScrollPosition = scrollpos;
            }

            _clickedBlameLine = null;

            _blameId = revision.ObjectId;
            CommitInfo.SetRevisionWithChildren(revision, children);

            controlToMask?.UnMask();
        }
Пример #4
0
        private void blamePreviousRevisionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int line = (int?)contextMenu.Tag ?? -1;

            if (line < 0)
            {
                return;
            }
            string   commit       = _blame.Lines[line].CommitGuid;
            int      originalLine = _blame.Lines[line].OriginLineNumber;
            GitBlame blame        = Module.Blame(_fileName, commit + "^", originalLine + ",+1", _encoding);

            if (blame.Lines.Count > 0)
            {
                var revision = blame.Lines[0].CommitGuid;
                if (_revGrid != null)
                {
                    _clickedBlameLine = blame.Lines[0];
                    _revGrid.SetSelectedRevision(revision);
                }
                else
                {
                    using (var frm = new FormCommitDiff(UICommands, revision))
                        frm.ShowDialog(this);
                }
            }
        }
Пример #5
0
        private void ProcessBlame(GitRevision revision, IReadOnlyList <ObjectId> children, Control controlToMask, int lineNumber, int scrollpos)
        {
            var gutter = new StringBuilder(capacity: 4096);
            var body   = new StringBuilder(capacity: 4096);

            GitBlameCommit lastCommit = null;

            // NOTE EOL white-space supports highlight on mouse-over.
            // Highlighting is done via text background colour.
            // If it could be done with a solid rectangle around the text,
            // the extra spaces added here could be omitted.

            foreach (var line in _blame.Lines)
            {
                if (line.Commit == lastCommit)
                {
                    gutter.Append(' ', 200).AppendLine();
                }
                else
                {
                    gutter.Append(line.Commit.Author);
                    gutter.Append(" - ");
                    gutter.Append(line.Commit.AuthorTime.ToString(CultureInfo.CurrentUICulture));
                    gutter.Append(" - ");
                    gutter.Append(line.Commit.FileName);
                    gutter.Append(' ', 100).AppendLine();
                }

                body.AppendLine(line.Text);

                lastCommit = line.Commit;
            }

            ThreadHelper.JoinableTaskFactory.RunAsync(
                () => BlameCommitter.ViewTextAsync("committer.txt", gutter.ToString()));
            ThreadHelper.JoinableTaskFactory.RunAsync(
                () => BlameFile.ViewTextAsync(_fileName, body.ToString()));

            if (lineNumber > 0)
            {
                BlameFile.GoToLine(lineNumber - 1);
            }
            else
            {
                BlameFile.ScrollPos = scrollpos;
            }

            _clickedBlameLine = null;

            _blameId = revision.ObjectId;
            CommitInfo.SetRevisionWithChildren(revision, children);

            controlToMask?.UnMask();
        }
Пример #6
0
        private void ProcessBlame(GitRevision revision, List <string> children, Control controlToMask, int line, int scrollpos)
        {
            var blameCommitter = new StringBuilder();
            var blameFile      = new StringBuilder();

            for (int i = 0; i < _blame.Lines.Count; i++)
            {
                GitBlameLine   blameLine   = _blame.Lines[i];
                GitBlameHeader blameHeader = _blame.FindHeaderForCommitGuid(blameLine.CommitGuid);
                if (i > 0 && _blame.Lines[i - 1].CommitGuid == blameLine.CommitGuid)
                {
                    blameCommitter.AppendLine(new string(' ', 200));
                }
                else
                {
                    blameCommitter.AppendLine(
                        (blameHeader.Author + " - " + blameHeader.AuthorTime + " - " + blameHeader.FileName +
                         new string(' ', 100)).Trim(new[] { '\r', '\n' }));
                }
                if (blameLine.LineText == null)
                {
                    blameFile.AppendLine("");
                }
                else
                {
                    blameFile.AppendLine(blameLine.LineText.Trim(new[] { '\r', '\n' }));
                }
            }

            BlameCommitter.ViewText("committer.txt", blameCommitter.ToString());
            BlameFile.ViewText(_fileName, blameFile.ToString());
            if (line > 0)
            {
                BlameFile.GoToLine(line - 1);
            }
            else
            {
                BlameFile.ScrollPos = scrollpos;
            }

            _clickedBlameLine = new GitBlameLine();

            _blameHash = revision.Guid;
            CommitInfo.SetRevisionWithChildren(revision, children);

            if (controlToMask != null)
            {
                controlToMask.UnMask();
            }
        }
        public void SetUp()
        {
            CultureInfo.CurrentCulture = new CultureInfo("EN-GB");
            var blameControlTask = ThreadHelper.JoinableTaskContext.Factory.RunAsync(async() =>
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                return(new BlameControl());
            });

            var blameControl = blameControlTask.Join();

            _sut = new BlameControl.TestAccessor(blameControl);

            var blameCommit1 = new GitBlameCommit(
                ObjectId.Random(),
                "author1",
                "*****@*****.**",
                new DateTime(2010, 2, 3, 12, 01, 02),
                "authorTimeZone",
                "committer1",
                "*****@*****.**",
                new DateTime(2010, 2, 3, 13, 01, 02),
                "committerTimeZone",
                "test summary commit1",
                "fileName.txt");

            var blameCommit2 = new GitBlameCommit(
                ObjectId.Random(),
                "author2",
                "*****@*****.**",
                new DateTime(2011, 2, 3, 12, 01, 02),
                "authorTimeZone",
                "committer2",
                "*****@*****.**",
                new DateTime(2011, 2, 3, 13, 01, 02),
                "committerTimeZone",
                "test summary commit2",
                "fileName.txt");

            _gitBlameLine = new GitBlameLine(blameCommit1, 1, 1, "line1");
            _sut.Blame    = new GitBlame(new GitBlameLine[]
            {
                _gitBlameLine,
                new GitBlameLine(blameCommit1, 2, 2, "line2"),
                new GitBlameLine(blameCommit2, 3, 3, "line3"),
                new GitBlameLine(blameCommit2, 4, 4, "line4"),
            });
        }
Пример #8
0
 private void ActiveTextAreaControlDoubleClick(object sender, EventArgs e)
 {
     if (_lastBlameLine.CommitGuid == null)
     {
         return;
     }
     if (_revGrid != null)
     {
         _clickedBlameLine = _lastBlameLine;
         _revGrid.SetSelectedRevision(_lastBlameLine.CommitGuid);
     }
     else
     {
         using (var frm = new FormCommitDiff(UICommands, _lastBlameLine.CommitGuid))
             frm.ShowDialog(this);
     }
 }
Пример #9
0
        void SelectedLineChanged(object sender, int selectedLine)
        {
            if (_blame == null || selectedLine >= _blame.Lines.Count)
            {
                return;
            }

            //TODO: Request GitRevision from RevisionGrid that contain all commits
            var newBlameLine = _blame.Lines[selectedLine];

            if (_lastBlameLine.CommitGuid == newBlameLine.CommitGuid)
            {
                return;
            }

            _lastBlameLine      = newBlameLine;
            CommitInfo.Revision = Module.GetRevision(_lastBlameLine.CommitGuid);
        }
        public void SetUp()
        {
            GitBlameCommit blameCommit1 = new(
                ObjectId.Random(),
                "author1",
                "*****@*****.**",
                new DateTime(2010, 3, 22, 12, 01, 02),
                "authorTimeZone",
                "committer1",
                "*****@*****.**",
                new DateTime(2010, 3, 22, 13, 01, 02),
                "committerTimeZone",
                "test summary commit1",
                "fileName.txt");

            GitBlameCommit blameCommit2 = new(
                ObjectId.Random(),
                "author2",
                "*****@*****.**",
                new DateTime(2011, 3, 22, 12, 01, 02),
                "authorTimeZone",
                "committer2",
                "*****@*****.**",
                new DateTime(2011, 3, 22, 13, 01, 02),
                "committerTimeZone",
                "test summary commit2",
                "fileName.txt");

            _gitBlameLine = new GitBlameLine(blameCommit1, 1, 1, "line1");

            _blameControl = new BlameControl();

            var blameControlTestAccessor = _blameControl.GetTestAccessor();

            blameControlTestAccessor.Blame = new GitBlame(new GitBlameLine[]
            {
                _gitBlameLine,
                new GitBlameLine(blameCommit1, 2, 2, "line2"),
                new GitBlameLine(blameCommit2, 3, 3, "line3"),
                new GitBlameLine(blameCommit2, 4, 4, "line4"),
            });
        }
Пример #11
0
        private void SelectedLineChanged(object sender, SelectedLineEventArgs e)
        {
            int selectedLine = e.SelectedLine;

            if (_blame is null || selectedLine >= _blame.Lines.Count)
            {
                return;
            }

            // TODO: Request GitRevision from RevisionGrid that contain all commits
            var newBlameLine = _blame.Lines[selectedLine];

            if (ReferenceEquals(_lastBlameLine?.Commit, newBlameLine.Commit))
            {
                return;
            }

            _lastBlameLine      = newBlameLine;
            CommitInfo.Revision = Module.GetRevision(_lastBlameLine.Commit.ObjectId);
        }
Пример #12
0
        public void LoadBlame(string guid, string fileName, RevisionGrid revGrid)
        {
            var scrollpos = BlameFile.ScrollPos;

            var blameCommitter = new StringBuilder();
            var blameFile      = new StringBuilder();

            _revGrid = revGrid;

            _blame = Settings.Module.Blame(fileName, guid);

            for (int i = 0; i < _blame.Lines.Count; i++)
            {
                GitBlameLine   blameLine   = _blame.Lines[i];
                GitBlameHeader blameHeader = _blame.FindHeaderForCommitGuid(blameLine.CommitGuid);
                if (i > 0 && _blame.Lines[i - 1].CommitGuid == blameLine.CommitGuid)
                {
                    blameCommitter.AppendLine(new string(' ', 200));
                }
                else
                {
                    blameCommitter.AppendLine((blameHeader.Author + " - " + blameHeader.AuthorTime + " - " + blameHeader.FileName + new string(' ', 100)).Trim(new[] { '\r', '\n' }));
                }
                if (blameLine.LineText == null)
                {
                    blameFile.AppendLine("");
                }
                else
                {
                    blameFile.AppendLine(blameLine.LineText.Trim(new char[] { '\r', '\n' }));
                }
            }

            BlameCommitter.ViewText("committer.txt", blameCommitter.ToString());
            BlameFile.ViewText(fileName, blameFile.ToString());
            BlameFile.ScrollPos = scrollpos;

            commitInfo.SetRevision(guid);
        }
Пример #13
0
 public void BuildAuthorLine(GitBlameLine line, StringBuilder lineBuilder, string dateTimeFormat, string filename, bool showAuthor, bool showAuthorDate, bool showOriginalFilePath, bool displayAuthorFirst)
 => _control.BuildAuthorLine(line, lineBuilder, dateTimeFormat, filename, showAuthor, showAuthorDate, showOriginalFilePath, displayAuthorFirst);
Пример #14
0
        public void LoadBlame(GitRevision revision, List <string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding)
        {
            string guid = revision.Guid;

            //refresh only when something changed
            if (guid.Equals(CommitInfo.Revision) && fileName.Equals(fileName) && revGrid == _revGrid && encoding == _encoding)
            {
                return;
            }

            if (controlToMask != null)
            {
                controlToMask.Mask();
            }

            var scrollpos = BlameFile.ScrollPos;

            var blameCommitter = new StringBuilder();
            var blameFile      = new StringBuilder();

            _revGrid  = revGrid;
            _fileName = fileName;
            _encoding = encoding;

            blameLoader.Load(() =>
            {
                _blame = Module.Blame(fileName, guid, encoding);
            },
                             () =>
            {
                for (int i = 0; i < _blame.Lines.Count; i++)
                {
                    GitBlameLine blameLine     = _blame.Lines[i];
                    GitBlameHeader blameHeader = _blame.FindHeaderForCommitGuid(blameLine.CommitGuid);
                    if (i > 0 && _blame.Lines[i - 1].CommitGuid == blameLine.CommitGuid)
                    {
                        blameCommitter.AppendLine(new string(' ', 200));
                    }
                    else
                    {
                        blameCommitter.AppendLine((blameHeader.Author + " - " + blameHeader.AuthorTime + " - " + blameHeader.FileName + new string(' ', 100)).Trim(new[] { '\r', '\n' }));
                    }
                    if (blameLine.LineText == null)
                    {
                        blameFile.AppendLine("");
                    }
                    else
                    {
                        blameFile.AppendLine(blameLine.LineText.Trim(new char[] { '\r', '\n' }));
                    }
                }

                BlameCommitter.ViewText("committer.txt", blameCommitter.ToString());
                BlameFile.ViewText(fileName, blameFile.ToString());
                BlameFile.ScrollPos = scrollpos;

                CommitInfo.SetRevisionWithChildren(revision, children);

                if (controlToMask != null)
                {
                    controlToMask.UnMask();
                }
            });
        }
Пример #15
0
        public void SetUp()
        {
            GitBlameCommit blameCommit1 = new(
                ObjectId.Random(),
                "author1",
                "*****@*****.**",
                new DateTime(2010, 3, 22, 12, 01, 02),
                "authorTimeZone",
                "committer1",
                "*****@*****.**",
                new DateTime(2010, 3, 22, 13, 01, 02),
                "committerTimeZone",
                "test summary commit1",
                "fileName.txt");

            GitBlameCommit blameCommit2 = new(
                ObjectId.Random(),
                "author2",
                "*****@*****.**",
                new DateTime(2011, 3, 22, 12, 01, 02),
                "authorTimeZone",
                "committer2",
                "*****@*****.**",
                new DateTime(2011, 3, 22, 13, 01, 02),
                "committerTimeZone",
                "test summary commit2",
                "fileName.txt");

            _gitBlameLine = new GitBlameLine(blameCommit1, 1, 1, "line1");

            _blameControl = new BlameControl();

            var blameControlTestAccessor = _blameControl.GetTestAccessor();

            blameControlTestAccessor.Blame = new GitBlame(new GitBlameLine[]
            {
                _gitBlameLine,
                new GitBlameLine(blameCommit1, 2, 2, "line2"),
                new GitBlameLine(blameCommit2, 3, 3, "line3"),
                new GitBlameLine(blameCommit2, 4, 4, "line4"),
            });

            if (_referenceRepository is null)
            {
                _referenceRepository = new ReferenceRepository();
            }
            else
            {
                _referenceRepository.Reset();
            }

            // Creates/updates a file with name in DefaultRepoFileName
            _referenceRepository.CreateCommit("1",
                                              "1\n2\n3\n4\n5\n6\n7\n8\n", _fileName1,
                                              "1\n2\n3\n4\n5\n6\n7\n8\n", _fileName2);
            _commit2 = _referenceRepository.CreateCommit("2",
                                                         "1\nb\n3\nd\n5\n6\n7\n8\n", _fileName1,
                                                         "1\nb\n3\nd\n5\n6\n7\n8\n", _fileName2);
            _commit3 = _referenceRepository.CreateCommit("3",
                                                         "1\nb\nc\nd\ne\n6\n7\n8\n", _fileName1,
                                                         "1\nb\nc\nd\ne\n6\n7\n8\n", _fileName2);

            IGitUICommandsSource uiCommandsSource = Substitute.For <IGitUICommandsSource>();
            GitUICommands        uiCommands       = new(_referenceRepository.Module);

            uiCommandsSource.UICommands.Returns(x => uiCommands);
            _blameControl.UICommandsSource = uiCommandsSource;
        }