/// <summary> /// Add the specified tree entry to this tree. /// </summary> /// <param name="e"> </param> /// <exception cref="IOException"></exception> public void AddEntry(TreeEntry e) { EnsureLoaded(); int p = BinarySearch(_contents, e.NameUTF8, GitSharp.Core.TreeEntry.LastChar(e), 0, e.NameUTF8.Length); if (p < 0) { e.AttachParent(this); InsertEntry(p, e); } else { throw new EntryExistsException(e.Name); } }
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 InsertEntry(int p, TreeEntry e) { TreeEntry[] c = _contents; var n = new TreeEntry[c.Length + 1]; p = -(p + 1); for (int k = c.Length - 1; k >= p; k--) { n[k + 1] = c[k]; } n[p] = e; for (int k = p - 1; k >= 0; k--) { n[k] = c[k]; } _contents = n; SetModified(); }
internal void RemoveEntry(TreeEntry e) { TreeEntry[] c = _contents; int p = BinarySearch(c, e.NameUTF8, GitSharp.Core.TreeEntry.LastChar(e), 0, e.NameUTF8.Length); if (p >= 0) { var n = new TreeEntry[c.Length - 1]; for (int k = c.Length - 1; k > p; k--) { n[k - 1] = c[k]; } for (int k = p - 1; k >= 0; k--) { n[k] = c[k]; } _contents = n; SetModified(); } }
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); } } }
internal Entry(Repository repository, TreeEntry f, int stage) : this(repository) { Ctime = -1; // hmm Mtime = -1; _dev = -1; _ino = -1; Mode = f.Mode.Bits; _uid = -1; _gid = -1; try { _size = (int)Repository.OpenBlob(f.Id).Size; } catch (IOException e) { e.printStackTrace(); _size = -1; } ObjectId = f.Id; _name = Constants.encode(f.FullName); _flags = (short)((stage << 12) | _name.Length); // TODO: fix _flags }
private void ReadTree(byte[] raw) { int rawSize = raw.Length; int rawPtr = 0; int nextIndex = 0; while (rawPtr < rawSize) { while (rawPtr < rawSize && raw[rawPtr] != 0) { rawPtr++; } rawPtr++; rawPtr += Constants.OBJECT_ID_LENGTH; nextIndex++; } var temp = new TreeEntry[nextIndex]; rawPtr = 0; nextIndex = 0; while (rawPtr < rawSize) { int c = raw[rawPtr++]; if (c < '0' || c > '7') { throw new CorruptObjectException(Id, "invalid entry mode"); } int mode = c - '0'; while (true) { c = raw[rawPtr++]; if (' ' == c) { break; } if (c < '0' || c > '7') { throw new CorruptObjectException(Id, "invalid mode"); } mode <<= 3; mode += c - '0'; } int nameLen = 0; while (raw[rawPtr + nameLen] != 0) { nameLen++; } var name = new byte[nameLen]; Array.Copy(raw, rawPtr, name, 0, nameLen); rawPtr += nameLen + 1; ObjectId id = ObjectId.FromRaw(raw, rawPtr); rawPtr += Constants.OBJECT_ID_LENGTH; TreeEntry ent; if (FileMode.RegularFile.Equals(mode)) { ent = new FileTreeEntry(this, id, name, false); } else if (FileMode.ExecutableFile.Equals(mode)) { ent = new FileTreeEntry(this, id, name, true); } else if (FileMode.Tree.Equals(mode)) { ent = new Tree(this, id, name); } else if (FileMode.Symlink.Equals(mode)) { ent = new SymlinkTreeEntry(this, id, name); } else if (FileMode.GitLink.Equals(mode)) { ent = new GitLinkTreeEntry(this, id, name); } else { throw new CorruptObjectException(Id, "Invalid mode: " + Convert.ToString(mode, 8)); } temp[nextIndex++] = ent; } _contents = temp; }
private static int Compare(TreeEntry t1, TreeEntry t2) { if ((((t1 != null) && (t1.Parent == null)) && (t2 != null)) && (t2.Parent == null)) { return(0); } if ((t1 != null) && (t1.Parent == null)) { return(-1); } if ((t2 != null) && (t2.Parent == null)) { return(1); } if ((t1 == null) && (t2 == null)) { return(0); } if (t1 == null) { return(1); } if (t2 == null) { return(-1); } return(Tree.CompareNames(t1.FullNameUTF8, t2.FullNameUTF8, TreeEntry.LastChar(t1), TreeEntry.LastChar(t2))); }
private static bool lt(TreeEntry h, TreeEntry m) { return(Compare(h, m) < 0); }
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, TreeEntry t2) { return(Compare(t1, t2) == 0); }
private static bool eq(TreeEntry t1, GitIndex.Entry e) { return(Compare(t1, e) == 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); } } } }