void IndexTreeVisitor.VisitEntry(TreeEntry treeEntry, TreeEntry auxEntry, GitIndex.Entry indexEntry, FileInfo file) { VisitEntryAuxDelegate handler = VisitEntryAux; if (handler != null) { handler(treeEntry, auxEntry, indexEntry, file); } }
private void CheckoutTwoTrees() { foreach (string path in Removed) { _index.remove(_root, new FileInfo(Path.Combine(_root.FullName, path))); } foreach (KeyValuePair <string, ObjectId> entry in _updated) { GitIndex.Entry newEntry = _index.addEntry(_merge.FindBlobMember(entry.Key)); _index.checkoutEntry(_root, newEntry); } }
private static int Compare(TreeEntry t, GitIndex.Entry i) { if ((t == null) && (i == null)) { return(0); } if (t == null) { return(1); } if (i == null) { return(-1); } return(Tree.CompareNames(t.FullNameUTF8, i.NameUTF8, TreeEntry.LastChar(t), TreeEntry.LastChar(i))); }
private void Walk(Tree tree, Tree auxTree) { var mi = new TreeIterator(tree, TreeIterator.Order.POSTORDER); var ai = new TreeIterator(auxTree, TreeIterator.Order.POSTORDER); TreeEntry m = mi.hasNext() ? mi.next() : null; TreeEntry a = ai.hasNext() ? ai.next() : null; int curIndexPos = IndexCounter; GitIndex.Entry entry = (IndexCounter < _indexMembers.Count) ? _indexMembers[IndexCounter++] : null; while (((m != null) || (a != null)) || (entry != null)) { int cmpma = Compare(m, a); int cmpmi = Compare(m, entry); int cmpai = Compare(a, entry); TreeEntry pm = ((cmpma <= 0) && (cmpmi <= 0)) ? m : null; TreeEntry pa = ((cmpma >= 0) && (cmpai <= 0)) ? a : null; GitIndex.Entry pi = ((cmpmi >= 0) && (cmpai >= 0)) ? entry : null; if (pi != null) { VisitEntry(pm, pa, pi); } else { FinishVisitTree(pm, pa, curIndexPos); } if (pm != null) { m = mi.hasNext() ? mi.next() : null; } if (pa != null) { a = ai.hasNext() ? ai.next() : null; } if (pi != null) { entry = (IndexCounter < _indexMembers.Count) ? _indexMembers[IndexCounter++] : null; } } }
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(); }
private void VisitEntry(TreeEntry t1, TreeEntry t2, GitIndex.Entry i) { Debug.Assert(((t1 != null) || (t2 != null)) || (i != null), "Needs at least one entry"); Debug.Assert(_root != null, "Needs workdir"); if ((t1 != null) && (t1.Parent == null)) { t1 = null; } if ((t2 != null) && (t2.Parent == null)) { t2 = null; } FileInfo file = null; if (i != null) { file = new FileInfo(Path.Combine(_root.FullName, i.Name)); } else if (t1 != null) { file = new FileInfo(Path.Combine(_root.FullName, t1.FullName)); } else if (t2 != null) { file = new FileInfo(Path.Combine(_root.FullName, t2.FullName)); } if (((t1 != null) || (t2 != null)) || (i != null)) { if (_threeTrees) { _visitor.VisitEntry(t1, t2, i, file); } else { _visitor.VisitEntry(t1, i, file); } } }
private static bool lt(TreeEntry h, GitIndex.Entry i) { return(Compare(h, i) < 0); }
private static bool lt(GitIndex.Entry i, TreeEntry t) { return(Compare(t, i) > 0); }
private static bool eq(TreeEntry t1, GitIndex.Entry e) { return(Compare(t1, e) == 0); }
public static int LastChar(GitIndex.Entry i) { return(FileMode.Tree.Equals(i.getModeBits()) ? 0x2f : 0); }
private void ProcessEntry(TreeEntry h, TreeEntry m, GitIndex.Entry i) { ObjectId iId = (i == null ? null : i.ObjectId); ObjectId mId = (m == null ? null : m.Id); ObjectId hId = (h == null ? null : h.Id); string name = (i != null ? i.Name : (h != null ? h.FullName : m.FullName)); if (i == null) { // // I (index) H M Result // ------------------------------------------------------- // 0 nothing nothing nothing (does not happen) // 1 nothing nothing exists use M // 2 nothing exists nothing remove path from index // 3 nothing exists exists use M if (h == null) { _updated.Add(name, mId); } else if (m == null) { Removed.Add(name); } else { _updated.Add(name, mId); } } else if (h == null) { // // clean I==H I==M H M Result // ----------------------------------------------------- // 4 yes N/A N/A nothing nothing keep index // 5 no N/A N/A nothing nothing keep index // // 6 yes N/A yes nothing exists keep index // 7 no N/A yes nothing exists keep index // 8 yes N/A no nothing exists fail // 9 no N/A no nothing exists fail if (m == null || mId.Equals(iId)) { if (HasParentBlob(_merge, name)) { if (i.IsModified(_root, true)) { Conflicts.Add(name); } else { Removed.Add(name); } } } else { Conflicts.Add(name); } } else if (m == null) { // // 10 yes yes N/A exists nothing remove path from index // 11 no yes N/A exists nothing fail // 12 yes no N/A exists nothing fail // 13 no no N/A exists nothing fail // if (hId.Equals(iId)) { if (i.IsModified(_root, true)) { Conflicts.Add(name); } else { Removed.Add(name); } } else { Conflicts.Add(name); } } else { if (!hId.Equals(mId) && !hId.Equals(iId) && !mId.Equals(iId)) { Conflicts.Add(name); } else if (hId.Equals(iId) && !mId.Equals(iId)) { if (i.IsModified(_root, true)) { Conflicts.Add(name); } else { _updated.Add(name, mId); } } } }