public bool Diff() { DirectoryInfo root = _index.Repository.WorkingDirectory; AbstractIndexTreeVisitor visitor = new AbstractIndexTreeVisitor(); visitor.VisitEntry = delegate(TreeEntry treeEntry, GitIndex.Entry indexEntry, FileInfo file) { if (treeEntry == null) { this.Added.Add(indexEntry.Name); anyChanges = true; } else if (indexEntry == null) { if (!(treeEntry is Tree)) Removed.Add(treeEntry.FullName); anyChanges = true; } else { if (!treeEntry.Id.Equals(indexEntry.ObjectId)) { Changed.Add(indexEntry.Name); anyChanges = true; } } if (indexEntry != null) { if (!file.Exists) { Missing.Add(indexEntry.Name); anyChanges = true; } else { if (indexEntry.IsModified(root, true)) { Modified.Add(indexEntry.Name); anyChanges = true; } } } }; new IndexTreeWalker(_index, _tree, root, visitor).Walk(); return anyChanges; }
private void CheckoutOutIndexNoHead() { var visitor = new AbstractIndexTreeVisitor { VisitEntry = (m, i, f) => { if (m == null) { _index.remove(_root, f); return; } bool needsCheckout = false; if (i == null) { needsCheckout = true; } else if (i.ObjectId.Equals(m.Id)) { if (i.IsModified(_root, true)) { needsCheckout = true; } } else { needsCheckout = true; } if (needsCheckout) { GitIndex.Entry newEntry = _index.addEntry(m); _index.checkoutEntry(_root, newEntry); } } }; new IndexTreeWalker(_index, _merge, _root, visitor).Walk(); }
internal void PrescanTwoTrees() { var visitor = new AbstractIndexTreeVisitor { VisitEntryAux = (treeEntry, auxEntry, indexEntry, file) => { if (treeEntry is Tree || auxEntry is Tree) { throw new ArgumentException("Can't pass me a tree!"); } ProcessEntry(treeEntry, auxEntry, indexEntry); }, FinishVisitTree = (tree, auxTree, currentDirectory) => { if (currentDirectory.Length == 0) return; if (auxTree == null) return; if (_index.GetEntry(currentDirectory) != null) { Removed.Add(currentDirectory); } } }; new IndexTreeWalker(_index, _head, _merge, _root, visitor).Walk(); // if there's a conflict, don't list it under // to-be-removed, since that messed up our next // section Removed.RemoveAll(removed => Conflicts.Contains(removed)); foreach (string path in _updated.Keys) { if (_index.GetEntry(path) == null) { FileSystemInfo file = new FileInfo(Path.Combine(_root.DirectoryName(), path)); if (file.IsFile()) { Conflicts.Add(path); } else if (file.IsDirectory()) { CheckConflictsWithFile(file); } } } Conflicts.RemoveAll(conflict => Removed.Contains(conflict)); }
internal void PrescanOneTree() { var visitor = new AbstractIndexTreeVisitor { VisitEntry = (m, i, f) => { if (m != null) { if (!f.IsFile()) { CheckConflictsWithFile(f); } } else { if (f.Exists) { Removed.Add(i.Name); Conflicts.Remove(i.Name); } } } }; new IndexTreeWalker(_index, _merge, _root, visitor).Walk(); Conflicts.RemoveAll(conflict => Removed.Contains(conflict)); }