public virtual void TestDeleteMiddleLines() { Git git = new Git(db); string[] content1 = new string[] { "a", "b", "c", "d", "e" }; string[] content2 = new string[] { "a", "c", "e" }; WriteTrashFile("file.txt", Join(content2)); git.Add().AddFilepattern("file.txt").Call(); RevCommit commit1 = git.Commit().SetMessage("edit file").Call(); WriteTrashFile("file.txt", Join(content1)); git.Add().AddFilepattern("file.txt").Call(); git.Commit().SetMessage("edit file").Call(); WriteTrashFile("file.txt", Join(content2)); git.Add().AddFilepattern("file.txt").Call(); git.Commit().SetMessage("edit file").Call(); BlameCommand command = new BlameCommand(db); command.SetFilePath("file.txt"); BlameResult lines = command.Call(); NUnit.Framework.Assert.AreEqual(content2.Length, lines.GetResultContents().Size() ); NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(0)); NUnit.Framework.Assert.AreEqual(0, lines.GetSourceLine(0)); NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(1)); NUnit.Framework.Assert.AreEqual(1, lines.GetSourceLine(1)); NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(2)); NUnit.Framework.Assert.AreEqual(2, lines.GetSourceLine(2)); }
public virtual void TestTwoRevisions() { Git git = new Git(db); string[] content1 = new string[] { "first", "second" }; WriteTrashFile("file.txt", Join(content1)); git.Add().AddFilepattern("file.txt").Call(); RevCommit commit1 = git.Commit().SetMessage("create file").Call(); string[] content2 = new string[] { "first", "second", "third" }; WriteTrashFile("file.txt", Join(content2)); git.Add().AddFilepattern("file.txt").Call(); RevCommit commit2 = git.Commit().SetMessage("create file").Call(); BlameCommand command = new BlameCommand(db); command.SetFilePath("file.txt"); BlameResult lines = command.Call(); NUnit.Framework.Assert.AreEqual(3, lines.GetResultContents().Size()); NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(0)); NUnit.Framework.Assert.AreEqual(0, lines.GetSourceLine(0)); NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(1)); NUnit.Framework.Assert.AreEqual(1, lines.GetSourceLine(1)); NUnit.Framework.Assert.AreEqual(commit2, lines.GetSourceCommit(2)); NUnit.Framework.Assert.AreEqual(2, lines.GetSourceLine(2)); }
public virtual void TestMiddleClearAllLines() { Git git = new Git(db); string[] content1 = new string[] { "a", "b", "c" }; WriteTrashFile("file.txt", Join(content1)); git.Add().AddFilepattern("file.txt").Call(); git.Commit().SetMessage("edit file").Call(); WriteTrashFile("file.txt", string.Empty); git.Add().AddFilepattern("file.txt").Call(); git.Commit().SetMessage("create file").Call(); WriteTrashFile("file.txt", Join(content1)); git.Add().AddFilepattern("file.txt").Call(); RevCommit commit3 = git.Commit().SetMessage("edit file").Call(); BlameCommand command = new BlameCommand(db); command.SetFilePath("file.txt"); BlameResult lines = command.Call(); NUnit.Framework.Assert.AreEqual(content1.Length, lines.GetResultContents().Size() ); NUnit.Framework.Assert.AreEqual(commit3, lines.GetSourceCommit(0)); NUnit.Framework.Assert.AreEqual(commit3, lines.GetSourceCommit(1)); NUnit.Framework.Assert.AreEqual(commit3, lines.GetSourceCommit(2)); }
/// <exception cref="System.Exception"></exception> private void TestRename(string sourcePath, string destPath) { Git git = new Git(db); string[] content1 = new string[] { "a", "b", "c" }; WriteTrashFile(sourcePath, Join(content1)); git.Add().AddFilepattern(sourcePath).Call(); RevCommit commit1 = git.Commit().SetMessage("create file").Call(); WriteTrashFile(destPath, Join(content1)); git.Add().AddFilepattern(destPath).Call(); git.Rm().AddFilepattern(sourcePath).Call(); git.Commit().SetMessage("moving file").Call(); string[] content2 = new string[] { "a", "b", "c2" }; WriteTrashFile(destPath, Join(content2)); git.Add().AddFilepattern(destPath).Call(); RevCommit commit3 = git.Commit().SetMessage("editing file").Call(); BlameCommand command = new BlameCommand(db); command.SetFollowFileRenames(true); command.SetFilePath(destPath); BlameResult lines = command.Call(); NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(0)); NUnit.Framework.Assert.AreEqual(0, lines.GetSourceLine(0)); NUnit.Framework.Assert.AreEqual(sourcePath, lines.GetSourcePath(0)); NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(1)); NUnit.Framework.Assert.AreEqual(1, lines.GetSourceLine(1)); NUnit.Framework.Assert.AreEqual(sourcePath, lines.GetSourcePath(1)); NUnit.Framework.Assert.AreEqual(commit3, lines.GetSourceCommit(2)); NUnit.Framework.Assert.AreEqual(2, lines.GetSourceLine(2)); NUnit.Framework.Assert.AreEqual(destPath, lines.GetSourcePath(2)); }
private static Dictionary <Person, int> GetBlameAuthors(BlameResult blame) { return(blame.Commits .GroupBy(c => c.Author) .OrderByDescending(g => g.Count()) .Select((g, n) => new KeyValuePair <Person, int>(g.Key, n)) .ToDictionary()); }
public BlameLayout(BlameResult blame) : this(blame, GetBlameAuthors(blame), s_defaultColumnWidths) { // track commit age (for fading out the blocks for each commit) m_oldestCommit = GetOldestCommit(m_blame); m_dateScale = GetDateScale(m_blame, m_oldestCommit); // set default values LineHeight = 1; TopLineNumber = 1; }
private BlameLayout(BlameResult blame, Dictionary <Person, int> authorIndex, double[] columnWidths) { m_blame = blame; m_authorIndex = authorIndex; m_columnWidths = columnWidths; m_blocks = new List <DisplayBlock>(); m_blocksReadOnly = m_blocks.AsReadOnly(); m_lines = new List <DisplayLine>(); m_linesReadOnly = m_lines.AsReadOnly(); m_newLines = new List <Rect>(); m_newLinesReadOnly = m_newLines.AsReadOnly(); }
private void RunBlame(BlamePositionModel position) { if (position == null || position.RepoPath == null) { Blame.ClearBlameResult(); } else { ProfileOptimization.StartProfile("Blame"); BlameResult blame = GitWrapper.GetBlameOutput(position.RepoPath, position.FileName, position.CommitId); Blame.SetBlameResult(blame, position.LineNumber ?? 1); } }
public BlameLayout(BlameResult blame) : this() { // get basic information from "blame" output m_blame = blame; m_authorIndex = GetBlameAuthors(m_blame); // track commit age (for fading out the blocks for each commit) m_oldestCommit = GetOldestCommit(m_blame); m_dateScale = GetDateScale(m_blame, m_oldestCommit); // set up default column widths m_columnWidths = new double[] { 210, 10, 0, 10, 5, 0 }; // set default values m_lineHeight = 1; m_topLineNumber = 1; }
public virtual void TestSingleRevision() { Git git = new Git(db); string[] content = new string[] { "first", "second", "third" }; WriteTrashFile("file.txt", Join(content)); git.Add().AddFilepattern("file.txt").Call(); RevCommit commit = git.Commit().SetMessage("create file").Call(); BlameCommand command = new BlameCommand(db); command.SetFilePath("file.txt"); BlameResult lines = command.Call(); NUnit.Framework.Assert.IsNotNull(lines); NUnit.Framework.Assert.AreEqual(3, lines.GetResultContents().Size()); for (int i = 0; i < 3; i++) { NUnit.Framework.Assert.AreEqual(commit, lines.GetSourceCommit(i)); NUnit.Framework.Assert.AreEqual(i, lines.GetSourceLine(i)); } }
public virtual void TestTwoRenames() { Git git = new Git(db); // Commit 1: Add file.txt string[] content1 = new string[] { "a" }; WriteTrashFile("file.txt", Join(content1)); git.Add().AddFilepattern("file.txt").Call(); RevCommit commit1 = git.Commit().SetMessage("create file").Call(); // Commit 2: Rename to file1.txt WriteTrashFile("file1.txt", Join(content1)); git.Add().AddFilepattern("file1.txt").Call(); git.Rm().AddFilepattern("file.txt").Call(); git.Commit().SetMessage("moving file").Call(); // Commit 3: Edit file1.txt string[] content2 = new string[] { "a", "b" }; WriteTrashFile("file1.txt", Join(content2)); git.Add().AddFilepattern("file1.txt").Call(); RevCommit commit3 = git.Commit().SetMessage("editing file").Call(); // Commit 4: Rename to file2.txt WriteTrashFile("file2.txt", Join(content2)); git.Add().AddFilepattern("file2.txt").Call(); git.Rm().AddFilepattern("file1.txt").Call(); git.Commit().SetMessage("moving file again").Call(); BlameCommand command = new BlameCommand(db); command.SetFollowFileRenames(true); command.SetFilePath("file2.txt"); BlameResult lines = command.Call(); NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(0)); NUnit.Framework.Assert.AreEqual(0, lines.GetSourceLine(0)); NUnit.Framework.Assert.AreEqual("file.txt", lines.GetSourcePath(0)); NUnit.Framework.Assert.AreEqual(commit3, lines.GetSourceCommit(1)); NUnit.Framework.Assert.AreEqual(1, lines.GetSourceLine(1)); NUnit.Framework.Assert.AreEqual("file1.txt", lines.GetSourcePath(1)); }
internal void SetBlameResult(BlameResult blame, int topLineNumber = 1) { if (m_blameSubscription != null) { m_blameSubscription.Dispose(); } double oldLineHeight = m_layout == null ? 1.0 : m_layout.LineHeight; m_blame = blame; m_layout = new BlameLayout(blame).WithTopLineNumber(1).WithLineHeight(oldLineHeight); m_lineCount = blame.Blocks.Sum(b => b.LineCount); m_blameSubscription = Observable.FromEventPattern <PropertyChangedEventArgs>(m_blame, "PropertyChanged").ObserveOnDispatcher().Subscribe(x => OnBlameResultPropertyChanged(x.EventArgs)); m_hoverCommitId = null; m_selectedCommitId = null; m_personBrush.Clear(); m_commitBrush.Clear(); m_commitAlpha.Clear(); CreateBrushesForAuthors(m_layout.AuthorCount); GoToLineNumber(topLineNumber - 1); }
public virtual void TestRenamedBoundLineDelete() { Git git = new Git(db); string FILENAME_1 = "subdir/file1.txt"; string FILENAME_2 = "subdir/file2.txt"; string[] content1 = new string[] { "first", "second" }; WriteTrashFile(FILENAME_1, Join(content1)); git.Add().AddFilepattern(FILENAME_1).Call(); RevCommit c1 = git.Commit().SetMessage("create file1").Call(); // rename it WriteTrashFile(FILENAME_2, Join(content1)); git.Add().AddFilepattern(FILENAME_2).Call(); DeleteTrashFile(FILENAME_1); git.Rm().AddFilepattern(FILENAME_1).Call(); git.Commit().SetMessage("rename file1.txt to file2.txt").Call(); // and change the new file string[] content2 = new string[] { "third", "first", "second" }; WriteTrashFile(FILENAME_2, Join(content2)); git.Add().AddFilepattern(FILENAME_2).Call(); RevCommit c2 = git.Commit().SetMessage("change file2").Call(); BlameGenerator generator = new BlameGenerator(db, FILENAME_2); try { generator.Push(null, db.Resolve(Constants.HEAD)); NUnit.Framework.Assert.AreEqual(3, generator.GetResultContents().Size()); NUnit.Framework.Assert.IsTrue(generator.Next()); NUnit.Framework.Assert.AreEqual(c2, generator.GetSourceCommit()); NUnit.Framework.Assert.AreEqual(1, generator.GetRegionLength()); NUnit.Framework.Assert.AreEqual(0, generator.GetResultStart()); NUnit.Framework.Assert.AreEqual(1, generator.GetResultEnd()); NUnit.Framework.Assert.AreEqual(0, generator.GetSourceStart()); NUnit.Framework.Assert.AreEqual(1, generator.GetSourceEnd()); NUnit.Framework.Assert.AreEqual(FILENAME_2, generator.GetSourcePath()); NUnit.Framework.Assert.IsTrue(generator.Next()); NUnit.Framework.Assert.AreEqual(c1, generator.GetSourceCommit()); NUnit.Framework.Assert.AreEqual(2, generator.GetRegionLength()); NUnit.Framework.Assert.AreEqual(1, generator.GetResultStart()); NUnit.Framework.Assert.AreEqual(3, generator.GetResultEnd()); NUnit.Framework.Assert.AreEqual(0, generator.GetSourceStart()); NUnit.Framework.Assert.AreEqual(2, generator.GetSourceEnd()); NUnit.Framework.Assert.AreEqual(FILENAME_1, generator.GetSourcePath()); NUnit.Framework.Assert.IsFalse(generator.Next()); } finally { generator.Release(); } // and test again with other BlameGenerator API: generator = new BlameGenerator(db, FILENAME_2); try { generator.Push(null, db.Resolve(Constants.HEAD)); BlameResult result = generator.ComputeBlameResult(); NUnit.Framework.Assert.AreEqual(3, result.GetResultContents().Size()); NUnit.Framework.Assert.AreEqual(c2, result.GetSourceCommit(0)); NUnit.Framework.Assert.AreEqual(FILENAME_2, result.GetSourcePath(0)); NUnit.Framework.Assert.AreEqual(c1, result.GetSourceCommit(1)); NUnit.Framework.Assert.AreEqual(FILENAME_1, result.GetSourcePath(1)); NUnit.Framework.Assert.AreEqual(c1, result.GetSourceCommit(2)); NUnit.Framework.Assert.AreEqual(FILENAME_1, result.GetSourcePath(2)); } finally { generator.Release(); } }
private static double GetDateScale(BlameResult blame, DateTimeOffset oldestCommit) { DateTimeOffset newestCommit = blame.Commits.Max(c => c.AuthorDate); return(0.65 / (newestCommit - oldestCommit).TotalDays); }
private static DateTimeOffset GetOldestCommit(BlameResult blame) { return(blame.Commits.Min(c => c.AuthorDate)); }