public void TestToString() { var committerTime = DateTime.Now; var authorTime = DateTime.Now; var commitHash = ObjectId.Random(); var str = new StringBuilder(); str.AppendLine("Author: Author"); str.AppendLine("Author date: " + authorTime); str.AppendLine("Committer: committer"); str.AppendLine("Commit date: " + committerTime); str.AppendLine("Commit hash: " + commitHash.ToShortString()); str.AppendLine("Summary: test summary"); str.AppendLine(); str.Append("FileName: fileName.txt"); var commit = new GitBlameCommit( commitHash, "Author", "*****@*****.**", authorTime, "authorTimeZone", "committer", "*****@*****.**", committerTime, "committerTimeZone", "test summary", "fileName.txt"); Assert.AreEqual(str.ToString(), commit.ToString()); }
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(); }
private void HighlightLinesForCommit([CanBeNull] GitBlameCommit commit) { if (commit == _highlightedCommit) { return; } _highlightedCommit = commit; BlameAuthor.ClearHighlighting(); BlameFile.ClearHighlighting(); if (commit is null) { return; } int startLine = -1; int prevLine = -1; for (int i = 0; i < _blame.Lines.Count; i++) { if (ReferenceEquals(_blame.Lines[i].Commit, commit)) { if (prevLine != i - 1 && startLine != -1) { BlameAuthor.HighlightLines(startLine, prevLine, SystemColors.ControlLight); BlameFile.HighlightLines(startLine, prevLine, SystemColors.ControlLight); startLine = -1; } prevLine = i; if (startLine == -1) { startLine = i; } } } if (startLine != -1) { BlameAuthor.HighlightLines(startLine, prevLine, SystemColors.ControlLight); BlameFile.HighlightLines(startLine, prevLine, SystemColors.ControlLight); } BlameAuthor.Refresh(); BlameFile.Refresh(); }
private (string gutter, string body) BuildBlameContents(string filename) { var body = new StringBuilder(capacity: 4096); GitBlameCommit lastCommit = null; var dateTimeFormat = AppSettings.BlameShowAuthorTime ? CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " + CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern : CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; // 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. var filePathLengthEstimate = _blame.Lines.Where(l => filename != l.Commit.FileName) .Select(l => l.Commit.FileName.Length) .DefaultIfEmpty(0) .Max(); var lineLengthEstimate = 25 + _blame.Lines.Max(l => l.Commit.Author?.Length ?? 0) + filePathLengthEstimate; var lineLength = Math.Max(80, lineLengthEstimate); var lineBuilder = new StringBuilder(lineLength + 2); var gutter = new StringBuilder(capacity: lineBuilder.Capacity * _blame.Lines.Count); var emptyLine = new string(' ', lineLength); foreach (var line in _blame.Lines) { if (line.Commit == lastCommit) { gutter.AppendLine(emptyLine); } else { BuildAuthorLine(line, lineBuilder, dateTimeFormat, filename, AppSettings.BlameShowAuthor, AppSettings.BlameShowAuthorDate, AppSettings.BlameShowOriginalFilePath, AppSettings.BlameDisplayAuthorFirst); gutter.Append(lineBuilder); gutter.Append(' ', lineLength - lineBuilder.Length).AppendLine(); lineBuilder.Clear(); } body.AppendLine(line.Text); lastCommit = line.Commit; } return(gutter.ToString(), body.ToString()); }
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"), }); }
public void SetUp() { var blameCommit1 = new GitBlameCommit( 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"); var blameCommit2 = new GitBlameCommit( 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"), }); }
private void BlameAuthor_MouseMove(object sender, MouseEventArgs e) { if (!BlameFile.Focused) { BlameFile.Focus(); } if (_blame is null) { return; } _lineIndex = BlameAuthor.GetLineFromVisualPosY(e.Y); var blameCommit = _lineIndex < _blame.Lines.Count ? _blame.Lines[_lineIndex].Commit : null; HighlightLinesForCommit(blameCommit); if (blameCommit is null) { return; } int newTooltipX = splitContainer2.SplitterDistance + 60; int newTooltipY = e.Y + splitContainer1.SplitterDistance + 20; if (_tooltipCommit != blameCommit || Math.Abs(_lastTooltipX - newTooltipX) > 5 || Math.Abs(_lastTooltipY - newTooltipY) > 5) { _tooltipCommit = blameCommit; _lastTooltipX = newTooltipX; _lastTooltipY = newTooltipY; blameTooltip.Show(blameCommit.ToString(), this, newTooltipX, newTooltipY); } }
private (string gutter, string body, List <GitBlameEntry> gitBlameDisplays) BuildBlameContents(string filename, int avatarSize) { if (_blame.Lines.Count == 0) { return("", "", new List <GitBlameEntry>(0)); } var body = new StringBuilder(capacity: 4096); GitBlameCommit lastCommit = null; bool showAuthorAvatar = AppSettings.BlameShowAuthorAvatar; var gitBlameDisplays = showAuthorAvatar ? CalculateBlameGutterData(_blame.Lines) : new List <GitBlameEntry>(0); var dateTimeFormat = AppSettings.BlameShowAuthorTime ? CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " + CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern : CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; // 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. var filePathLengthEstimate = _blame.Lines.Where(l => filename != l.Commit.FileName) .Select(l => l.Commit.FileName.Length) .DefaultIfEmpty(0) .Max(); var lineLengthEstimate = 25 + _blame.Lines.Max(l => l.Commit.Author?.Length ?? 0) + filePathLengthEstimate; var lineLength = Math.Max(80, lineLengthEstimate); var lineBuilder = new StringBuilder(lineLength + 2); var gutter = new StringBuilder(capacity: lineBuilder.Capacity * _blame.Lines.Count); var emptyLine = new string(' ', lineLength); var cacheAvatars = new Dictionary <string, Image>(); var noAuthorImage = (Image) new Bitmap(Images.User80, avatarSize, avatarSize); for (var index = 0; index < _blame.Lines.Count; index++) { var line = _blame.Lines[index]; if (line.Commit == lastCommit) { gutter.AppendLine(emptyLine); } else { var authorEmail = line.Commit.AuthorMail?.Trim('<', '>'); if (showAuthorAvatar) { if (authorEmail is not null) { if (cacheAvatars.ContainsKey(authorEmail)) { gitBlameDisplays[index].Avatar = cacheAvatars[authorEmail]; } else { var avatar = ThreadHelper.JoinableTaskFactory.Run(() => AvatarService.Default.GetAvatarAsync(authorEmail, line.Commit.Author, avatarSize)); cacheAvatars.Add(authorEmail, avatar); gitBlameDisplays[index].Avatar = avatar; } } else { gitBlameDisplays[index].Avatar = noAuthorImage; } } BuildAuthorLine(line, lineBuilder, dateTimeFormat, filename, AppSettings.BlameShowAuthor, AppSettings.BlameShowAuthorDate, AppSettings.BlameShowOriginalFilePath, AppSettings.BlameDisplayAuthorFirst); gutter.Append(lineBuilder); gutter.Append(' ', lineLength - lineBuilder.Length).AppendLine(); lineBuilder.Clear(); } body.AppendLine(line.Text); lastCommit = line.Commit; } return(gutter.ToString(), body.ToString(), gitBlameDisplays); }