public TreeViewItem(TreeEntryChanges change) { name = new FileInfo(change.Path).Name; path = change.Path; status = change.Status.ToString(); patchDiff = change.Patch; }
public void CanCompareTwoVersionsOfAFileWithADiffOfTwoHunks(int contextLines, int interhunkLines) { var compareOptions = new CompareOptions { ContextLines = contextLines, InterhunkLines = interhunkLines, }; using (var repo = new Repository(StandardTestRepoPath)) { Tree rootCommitTree = repo.Lookup <Commit>("f8d44d7").Tree; Tree mergedCommitTree = repo.Lookup <Commit>("7252fe2").Tree; TreeChanges changes = repo.Diff.Compare(rootCommitTree, mergedCommitTree, compareOptions: compareOptions); Assert.Equal(3, changes.Count()); Assert.Equal(1, changes.Modified.Count()); Assert.Equal(1, changes.Deleted.Count()); Assert.Equal(1, changes.Added.Count()); TreeEntryChanges treeEntryChanges = changes["numbers.txt"]; Assert.Equal(3, treeEntryChanges.LinesAdded); Assert.Equal(1, treeEntryChanges.LinesDeleted); Assert.Equal(Mode.Nonexistent, changes["my-name-does-not-feel-right.txt"].Mode); Assert.Equal(Expected("f8d44d7...7252fe2/numbers.txt-{0}-{1}.diff", contextLines, interhunkLines), treeEntryChanges.Patch); Assert.Equal(Expected("f8d44d7...7252fe2/full-{0}-{1}.diff", contextLines, interhunkLines), changes.Patch); } }
private static void ApplyChangesToScope(Scope scope, TreeEntryChanges change, IDictionary <string, string> deleted) { // Single parent if (change.Status == ChangeKind.Added) { scope.Add(change.Path); } else if (change.Status == ChangeKind.Modified) { // Scope is not affected } else if (change.Status == ChangeKind.Deleted) { var id = scope.GetId(change.Path); scope.Remove(change.Path); deleted.Add(change.Path, id); } else if (change.Status == ChangeKind.Renamed) { scope.Update(change.OldPath, change.Path); } else { Debug.Fail("Not handled!"); } }
public void CanHandleTwoTreeEntryChangesWithTheSamePathUsingSimilarityDefault() { // $ git diff-tree --name-status --find-renames -r 2ccccf8 e829333 // T include/Nu/Nu.h // D objc/Nu.h CanHandleTwoTreeEntryChangesWithTheSamePath(SimilarityOptions.Default, (path, changes) => { Assert.Equal(2, changes.Count()); Assert.Equal(1, changes.Deleted.Count()); Assert.Equal(1, changes.Renamed.Count()); TreeEntryChanges renamed = changes.Renamed.Single(); Assert.Equal(Mode.NonExecutableFile, renamed.OldMode); Assert.Equal(Mode.NonExecutableFile, renamed.Mode); Assert.Equal(ChangeKind.Renamed, renamed.Status); Assert.Equal(path, renamed.Path); TreeEntryChanges deleted = changes.Deleted.Single(); Assert.Equal(Mode.SymbolicLink, deleted.OldMode); Assert.Equal(Mode.Nonexistent, deleted.Mode); Assert.Equal(ChangeKind.Deleted, deleted.Status); Assert.Equal(path, deleted.Path); }); }
public void CanCompareACommitTreeAgainstItsParent() { using (var repo = new Repository(StandardTestRepoPath)) { Tree commitTree = repo.Head.Tip.Tree; Tree parentCommitTree = repo.Head.Tip.Parents.Single().Tree; var changes = repo.Diff.Compare <TreeChanges>(parentCommitTree, commitTree); Assert.Equal(1, changes.Count()); Assert.Equal(1, changes.Added.Count()); TreeEntryChanges treeEntryChanges = changes["1.txt"]; var patch = repo.Diff.Compare <Patch>(parentCommitTree, commitTree); Assert.False(patch["1.txt"].IsBinaryComparison); Assert.Equal("1.txt", treeEntryChanges.Path); Assert.Equal(ChangeKind.Added, treeEntryChanges.Status); Assert.Equal(treeEntryChanges, changes.Added.Single()); Assert.Equal(Mode.Nonexistent, treeEntryChanges.OldMode); } }
public static string Theme_FileChange(this TreeEntryChanges change) { var path = change.Path == change.OldPath ? change.Path : $"{change.OldPath} > {change.Path}"; var color = change.Status.Theme_Change(); return($"{change.Status.ToString().PadLeft(11)} : {path}".Pastel(color)); }
internal GitDiffFile(TreeEntryChanges change) { Path = change.Path; OldPath = change.OldPath; Status = (GitChangeKind)change.Status; Exists = change.Exists; OldExists = change.OldExists; }
public static FileStatusViewModel FromTreeEntryChange(TreeEntryChanges changes) { return(new FileStatusViewModel() { Path = changes.Path, State = GetState(changes.Status) }); }
private void ApplyModified(TreeEntryChanges changeEntry, string tfsFilePath, string tfsFileName) { if (changeEntry.OldOid != changeEntry.Oid) { _host.Verbose("Pending edit {0}", tfsFileName); _workspace.PendEdit(tfsFilePath); CopyObjectToFile(tfsFilePath, changeEntry.Oid, changeEntry.Path); } }
private void buildTreeView(TreeEntryChanges change) { int index = change.Path.LastIndexOf("\\"); string folder = (index >= 0) ? change.Path.Substring(0, index) : "\\"; TreeViewNode node = new TreeViewNode(folder.Trim()); TreeViewItem item = new TreeViewItem(change); treeView.tryAdd(node).tryAdd(item); }
public ChangeInfo(Commit commit, TreeEntryChanges change) { Author = commit.Author.Name; CommitId = commit.Id; Directory = Path.GetDirectoryName(change.Path); Extension = Path.GetExtension(change.Path); FileName = Path.GetFileName(change.Path); FullPath = change.Path; Kind = change.Status; When = commit.Author.When; }
private IDictionary <string, object> GetFileChangedDetails(Commit commit, TreeEntryChanges change) { return(new Dictionary <string, object>() { { "Type", "File" }, { "ChangeStatus", change.Status }, { "OldPath", change.OldPath }, { "LinesAdded", change.LinesAdded }, { "LinesDeleted", change.LinesDeleted }, { "LinesChanged", change.LinesAdded + change.LinesDeleted } }.Merge(GetSharedCommitDetails(commit))); }
private bool IsIgnorable(TreeEntryChanges change) { // Filter out changes we're not interested in: // - files outside monitored directories // - files without monitored extension // - change kinds that won't break code includes return(!AcceptableDirectories.Any( d => change.Path.StartsWith(d, StringComparison.InvariantCultureIgnoreCase)) || !AcceptableExtensions.Any( f => change.Path.EndsWith(f, StringComparison.InvariantCultureIgnoreCase)) || !_changesOfInterest.Contains(change.Status)); }
internal GitDiffFile(TreeEntryChanges change) { if (change == null) { throw new ArgumentNullException(nameof(change)); } Path = change.Path; OldPath = change.OldPath; Status = (GitChangeKind)change.Status; Exists = change.Exists; OldExists = change.OldExists; }
private void btnCargar_Click(object sender, RoutedEventArgs e) { var cam = from u in cambios where u.Path == cmbFicheros.Text select u; TreeEntryChanges cambio = cam.First(); txt.SelectAll(); txt.Selection.Text = cambio.Patch; detectarColoreado(cambio); }
private static bool fileFilterMatch(TreeEntryChanges entry) { var filterFilePath = LocalSettings.Instance().GitFilterFilePath; if (File.Exists(filterFilePath)) { var regexFilters = File.ReadAllLines(filterFilePath); foreach (var regexPattern in regexFilters) { if (!Regex.Match(entry.Path, regexPattern, RegexOptions.IgnoreCase).Success) { return(false); } } } return(true); }
public void CanCompareTwoVersionsOfAFileWithATrailingNewlineDeletion() { using (var repo = new Repository(StandardTestRepoPath)) { Tree rootCommitTree = repo.Lookup <Commit>("f8d44d7").Tree; Tree commitTreeWithUpdatedFile = repo.Lookup <Commit>("ec9e401").Tree; TreeChanges changes = repo.Diff.Compare(rootCommitTree, commitTreeWithUpdatedFile); Assert.Equal(1, changes.Count()); Assert.Equal(1, changes.Modified.Count()); TreeEntryChanges treeEntryChanges = changes.Modified.Single(); Assert.Equal(2, treeEntryChanges.LinesAdded); Assert.Equal(1, treeEntryChanges.LinesDeleted); } }
public void CanHandleTwoTreeEntryChangesWithTheSamePathUsingSimilarityNone() { // $ git diff-tree --name-status --no-renames -r 2ccccf8 e829333 // T include/Nu/Nu.h // D objc/Nu.h CanHandleTwoTreeEntryChangesWithTheSamePath(SimilarityOptions.None, (path, changes) => { Assert.Equal(2, changes.Count()); Assert.Equal(1, changes.Deleted.Count()); Assert.Equal(1, changes.TypeChanged.Count()); TreeEntryChanges change = changes.Single(c => c.Path == path); Assert.Equal(Mode.SymbolicLink, change.OldMode); Assert.Equal(Mode.NonExecutableFile, change.Mode); Assert.Equal(ChangeKind.TypeChanged, change.Status); Assert.Equal(path, change.Path); }); }
private ChangeItem CreateChangeItem(TreeEntryChanges change, Scope scope, Dictionary <string, string> deletedServerPathToId) { var item = new ChangeItem(); item.Kind = ToChangeKind(change.Status); item.ServerPath = change.Path; item.FromServerPath = change.OldPath; item.LocalPath = _mapper.MapToLocalFile(change.Path); // Assign id item.Id = scope.GetIdOrDefault(change.Path); if (item.Id == null) { Debug.Assert(change.Status == ChangeKind.Deleted); item.Id = deletedServerPathToId[change.Path]; } return(item); }
private bool ApplyCommitInternal(Commit commit, TreeChanges changes, Repository repo) { this.CommitCountSinceVersionChange++; // return false if this is a version number root TreeEntryChanges projectFileChange = changes.Where(x => x.Path?.Equals(this.ProjectFilePath, StringComparison.OrdinalIgnoreCase) == true).FirstOrDefault(); if (projectFileChange != null) { if (projectFileChange.Status == ChangeKind.Added) { // the version must have been set here return(false); } else { Blob blob = repo.Lookup <Blob>(projectFileChange.Oid); using (Stream s = blob.GetContentStream()) { using (XmlReader reader = XmlReader.Create(s)) { ProjectRootElement proj = ProjectRootElement.Create(reader); NuGetVersion version = new NuGetVersion(proj.Properties.FirstOrDefault(x => x.Name == "VersionPrefix").Value); if (version != this.Version) { // version changed return(false); } } } } // version must have been the same lets carry on return(true); } return(true); }
private bool CheckForRename(TreeChanges treeChanges, TreeEntryChanges fileChange, out TreeEntryChanges renameSourceChange) { if (fileChange == null || fileChange.Status != ChangeKind.Added) { renameSourceChange = (TreeEntryChanges)null; return false; } List<TreeEntryChanges> list = Enumerable.ToList<TreeEntryChanges>(Enumerable.Where<TreeEntryChanges>(treeChanges.Deleted, (Func<TreeEntryChanges, bool>)(d => d.OldOid == fileChange.Oid))); if (list.Count == 1) { renameSourceChange = list[0]; //trace "GitRepository.CheckForRename rename detected relTarget={0} relSource={1}", (object)fileChange.Path, (object)renameSourceChange.Path); return true; } if (list.Count > 1) { //trace "GitRepository.CheckForRename rename detected but there are {0} possible sources", (object)list.Count); } renameSourceChange = (TreeEntryChanges)null; return false; }
public void CanCompareTwoVersionsOfAFileWithADiffOfTwoHunks() { using (var repo = new Repository(StandardTestRepoPath)) { Tree rootCommitTree = repo.Lookup <Commit>("f8d44d7").Tree; Tree mergedCommitTree = repo.Lookup <Commit>("7252fe2").Tree; TreeChanges changes = repo.Diff.Compare(rootCommitTree, mergedCommitTree); Assert.Equal(3, changes.Count()); Assert.Equal(1, changes.Modified.Count()); Assert.Equal(1, changes.Deleted.Count()); Assert.Equal(1, changes.Added.Count()); TreeEntryChanges treeEntryChanges = changes["numbers.txt"]; Assert.Equal(3, treeEntryChanges.LinesAdded); Assert.Equal(1, treeEntryChanges.LinesDeleted); Assert.Equal(Mode.Nonexistent, changes["my-name-does-not-feel-right.txt"].Mode); var expected = new StringBuilder() .Append("diff --git a/numbers.txt b/numbers.txt\n") .Append("index 7909961..4e935b7 100644\n") .Append("--- a/numbers.txt\n") .Append("+++ b/numbers.txt\n") .Append("@@ -1,4 +1,5 @@\n") .Append(" 1\n") .Append("+2\n") .Append(" 3\n") .Append(" 4\n") .Append(" 5\n") .Append("@@ -8,8 +9,9 @@\n") .Append(" 8\n") .Append(" 9\n") .Append(" 10\n") .Append("-12\n") .Append("+11\n") .Append(" 12\n") .Append(" 13\n") .Append(" 14\n") .Append(" 15\n") .Append("+16\n"); Assert.Equal(expected.ToString(), treeEntryChanges.Patch); expected = new StringBuilder() .Append("diff --git a/my-name-does-not-feel-right.txt b/my-name-does-not-feel-right.txt\n") .Append("deleted file mode 100644\n") .Append("index e8953ab..0000000\n") .Append("--- a/my-name-does-not-feel-right.txt\n") .Append("+++ /dev/null\n") .Append("@@ -1,4 +0,0 @@\n") .Append("-That's a terrible name!\n") .Append("-I don't like it.\n") .Append("-People look down at me and laugh. :-(\n") .Append("-Really!!!!\n") .Append("diff --git a/numbers.txt b/numbers.txt\n") .Append("index 7909961..4e935b7 100644\n") .Append("--- a/numbers.txt\n") .Append("+++ b/numbers.txt\n") .Append("@@ -1,4 +1,5 @@\n") .Append(" 1\n") .Append("+2\n") .Append(" 3\n") .Append(" 4\n") .Append(" 5\n") .Append("@@ -8,8 +9,9 @@\n") .Append(" 8\n") .Append(" 9\n") .Append(" 10\n") .Append("-12\n") .Append("+11\n") .Append(" 12\n") .Append(" 13\n") .Append(" 14\n") .Append(" 15\n") .Append("+16\n") .Append("diff --git a/super-file.txt b/super-file.txt\n") .Append("new file mode 100644\n") .Append("index 0000000..16bdf1d\n") .Append("--- /dev/null\n") .Append("+++ b/super-file.txt\n") .Append("@@ -0,0 +1,5 @@\n") .Append("+That's a terrible name!\n") .Append("+I don't like it.\n") .Append("+People look down at me and laugh. :-(\n") .Append("+Really!!!!\n") .Append("+Yeah! Better!\n"); Assert.Equal(expected.ToString(), changes.Patch); } }
public void CanHandleTwoTreeEntryChangesWithTheSamePath() { SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); using (Repository repo = Repository.Init(scd.DirectoryPath)) { Blob mainContent = CreateBlob(repo, "awesome content\n"); Blob linkContent = CreateBlob(repo, "../../objc/Nu.h"); string path = string.Format("include{0}Nu{0}Nu.h", Path.DirectorySeparatorChar); var tdOld = new TreeDefinition() .Add(path, linkContent, Mode.SymbolicLink) .Add("objc/Nu.h", mainContent, Mode.NonExecutableFile); Tree treeOld = repo.ObjectDatabase.CreateTree(tdOld); var tdNew = new TreeDefinition() .Add(path, mainContent, Mode.NonExecutableFile); Tree treeNew = repo.ObjectDatabase.CreateTree(tdNew); TreeChanges changes = repo.Diff.Compare(treeOld, treeNew); /* * $ git diff-tree -p 5c87b67 d5278d0 * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h * deleted file mode 120000 * index 19bf568..0000000 * --- a/include/Nu/Nu.h * +++ /dev/null * @@ -1 +0,0 @@ * -../../objc/Nu.h * \ No newline at end of file * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h * new file mode 100644 * index 0000000..f9e6561 * --- /dev/null * +++ b/include/Nu/Nu.h * @@ -0,0 +1 @@ * +awesome content * diff --git a/objc/Nu.h b/objc/Nu.h * deleted file mode 100644 * index f9e6561..0000000 * --- a/objc/Nu.h * +++ /dev/null * @@ -1 +0,0 @@ * -awesome content */ Assert.Equal(1, changes.Deleted.Count()); Assert.Equal(0, changes.Modified.Count()); Assert.Equal(1, changes.TypeChanged.Count()); TreeEntryChanges change = changes[path]; Assert.Equal(Mode.SymbolicLink, change.OldMode); Assert.Equal(Mode.NonExecutableFile, change.Mode); Assert.Equal(ChangeKind.TypeChanged, change.Status); Assert.Equal(path, change.Path); } }
private static byte[] GetNewVersion(Commit commit, TreeEntryChanges change) { return(((Blob)commit[change.Path].Target).Content); }
private static byte[] GetOldVersion(Commit commit, TreeEntryChanges change) { return(((Blob)commit.Parents.First()[change.OldPath].Target).Content); }
internal PatchEntryChanges(bool isBinaryComparison, TreeEntryChanges treeEntryChanges) : base(isBinaryComparison) { this.treeEntryChanges = treeEntryChanges; }
private void detectarColoreado(TreeEntryChanges cambio) { List <int> lineasVerdes = new List <int>(); List <int> lineasRojas = new List <int>(); string strCambios = cambio.Patch; int numlinea = 0; String linea = ""; bool paraEscritura = false; for (int i = 0; i < strCambios.Length - 1; i++) { char c = strCambios[i]; if (c.ToString() == "@" && strCambios[i + 1].ToString() == "@") { paraEscritura = !paraEscritura; } if (((int)c) != 10) { if (paraEscritura == false) { linea += c.ToString(); } } else { if (linea[0].ToString() == "-") { Console.ForegroundColor = ConsoleColor.Red; lineasRojas.Add(numlinea); } if (linea[0].ToString() == "+") { Console.ForegroundColor = ConsoleColor.Green; lineasVerdes.Add(numlinea); } linea = linea.Replace("@@", ""); Console.WriteLine(linea); linea = ""; numlinea++; // Console.ForegroundColor = normal; } } //txt.SelectAll(); numlinea++; txt.CaretPosition = txt.CaretPosition.DocumentStart; for (int nlinea = 0; nlinea < numlinea; nlinea++) { txt.LineDown(); if (lineasVerdes.Contains(nlinea)) { colorearLinea(nlinea, Colors.Green); } else if (lineasRojas.Contains(nlinea)) { colorearLinea(nlinea, Colors.Red); } else { colorearLinea(nlinea, Colors.Gray); } } /*foreach (int n in lineasRojas) * { * colorearRojaLinea(n); * }*/ }
internal PatchEntryChanges(bool isBinaryComparison, TreeEntryChanges treeEntryChanges) : base(isBinaryComparison) { this.treeEntryChanges = treeEntryChanges; }
public CancellableChanges(TreeEntryChanges treeEntryChanges) => (TreeEntryChanges, Cancellation) = (treeEntryChanges, new CancellationTokenSource());
private void UpdateScopeFromMergeSource(GraphNode mergeInto, GraphNode mergeFrom, TreeEntryChanges change, IDictionary <string, string> deleted) { // Merge changes from feature branch. Apply all Ids we can find without ambiguity. var mergeFromScope = mergeFrom.Scope; var mergeIntoScope = mergeInto.Scope; if (change.Status == ChangeKind.Added) { var idFrom = mergeFromScope.GetIdOrDefault(change.Path); var idInto = mergeIntoScope.GetIdOrDefault(change.Path); if (idFrom != null && idInto == null && mergeIntoScope.GetServerPathOrDefault(Guid.Parse(idFrom)) == null) { // Take the Id from the (feature) branch where the file was added. // File is known in "from scope" but not in "into scope" and the id in "from scope" is not in "into scope" mergeIntoScope.MergeAdd(change.Path, Guid.Parse(idFrom)); return; } if (idFrom != null && idFrom == idInto && mergeIntoScope.GetServerPath(Guid.Parse(idInto)) == change.Path) { // Nothing to update return; } // In all other cases reset tracking mergeIntoScope.Remove(change.Path); mergeIntoScope.Add(change.Path); _stats.ResetRenameTrackingOnFile++; Warnings.Add(new WarningMessage(mergeInto.CommitHash, $"Reset tracking due to added file {change.Path}")); } else if (change.Status == ChangeKind.Modified) { // Id must be known in main branch. Debug.Assert(mergeIntoScope.IsKnown(change.Path)); } else if (change.Status == ChangeKind.Deleted) { // Neither of the (verified against the tree) parent scopes know this file!?! var id = mergeIntoScope.GetIdOrDefault(change.Path); if (id != null) { mergeIntoScope.Remove(change.Path); deleted.Add(change.Path, id); } } else if (change.Status == ChangeKind.Renamed) { if (mergeIntoScope.IsKnown(change.OldPath) is false) { mergeIntoScope.Remove(change.Path); mergeIntoScope.Add(change.Path); } else { mergeIntoScope.Update(change.OldPath, change.Path); } } else { Debug.Fail("Not handled!"); } }