/// <summary>Helper for accessing tree/blob methods.</summary> /// <remarks>Helper for accessing tree/blob methods.</remarks> /// <param name="treeEntry"></param> /// <returns>'/' for Tree entries and NUL for non-treeish objects.</returns> public static int LastChar(NGit.TreeEntry treeEntry) { if (!(treeEntry is Tree)) { return('\0'); } else { return('/'); } }
/// <summary>Add the specified tree entry to this tree.</summary> /// <remarks>Add the specified tree entry to this tree.</remarks> /// <param name="e"></param> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual void AddEntry(TreeEntry e) { int p; EnsureLoaded(); p = BinarySearch(contents, e.GetNameUTF8(), TreeEntry.LastChar(e), 0, e.GetNameUTF8 ().Length); if (p < 0) { e.AttachParent(this); InsertEntry(p, e); } else { throw new EntryExistsException(e.GetName()); } }
private void InsertEntry(int p, TreeEntry e) { TreeEntry[] c = contents; TreeEntry[] 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_1 = p - 1; k_1 >= 0; k_1--) { n[k_1] = c[k_1]; } contents = n; SetModified(); }
/// <summary>Return all members of the tree sorted in Git order.</summary> /// <remarks> /// Return all members of the tree sorted in Git order. /// Entries are sorted by the numerical unsigned byte /// values with (sub)trees having an implicit '/'. An /// example of a tree with three entries. a:b is an /// actual file name here. /// <p> /// 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 a.b /// 040000 tree 4277b6e69d25e5efa77c455340557b384a4c018a a /// 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 a:b /// </remarks> /// <returns>all entries in this Tree, sorted.</returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual TreeEntry[] Members() { EnsureLoaded(); TreeEntry[] c = contents; if (c.Length != 0) { TreeEntry[] r = new TreeEntry[c.Length]; for (int k = c.Length - 1; k >= 0; k--) { r[k] = c[k]; } return(r); } else { return(c); } }
private void AppendFullName(StringBuilder r) { NGit.TreeEntry p = GetParent(); string n = GetName(); if (p != null) { p.AppendFullName(r); if (r.Length > 0) { r.Append('/'); } } if (n != null) { r.Append(n); } }
internal virtual void RemoveEntry(TreeEntry e) { TreeEntry[] c = contents; int p = BinarySearch(c, e.GetNameUTF8(), TreeEntry.LastChar(e), 0, e.GetNameUTF8( ).Length); if (p >= 0) { TreeEntry[] n = new TreeEntry[c.Length - 1]; for (int k = c.Length - 1; k > p; k--) { n[k - 1] = c[k]; } for (int k_1 = p - 1; k_1 >= 0; k_1--) { n[k_1] = c[k_1]; } contents = n; SetModified(); } }
/// <exception cref="System.IO.IOException"></exception> private TreeEntry FindMember(byte[] s, byte slast, int offset) { int slash; int p; for (slash = offset; slash < s.Length && s[slash] != '/'; slash++) { } // search for path component terminator EnsureLoaded(); byte xlast = slash < s.Length ? unchecked ((byte)(byte)('/')) : slast; p = BinarySearch(contents, s, xlast, offset, slash); if (p >= 0) { TreeEntry r = contents[p]; if (slash < s.Length - 1) { return(r is NGit.Tree ? ((NGit.Tree)r).FindMember(s, slast, slash + 1) : null); } return(r); } return(null); }
/// <exception cref="System.IO.IOException"></exception> public override void VisitEntry(TreeEntry m, GitIndex.Entry i, FilePath file) { if (m != null) { if (!file.IsFile()) { this._enclosing.CheckConflictsWithFile(file); } } else { if (file.Exists()) { this._enclosing.removed.AddItem(i.GetName()); this._enclosing.conflicts.Remove(i.GetName()); } } }
/// <exception cref="System.IO.IOException"></exception> public override void VisitEntry(TreeEntry m, GitIndex.Entry i, FilePath f) { // TODO remove this once we support submodules if (f.GetName().Equals(".gitmodules")) { throw new NotSupportedException(JGitText.Get().submodulesNotSupported); } if (m == null) { this._enclosing.index.Remove(this._enclosing.root, f); return; } bool needsCheckout = false; if (i == null) { needsCheckout = true; } else { if (i.GetObjectId().Equals(m.GetId())) { if (i.IsModified(this._enclosing.root, true)) { needsCheckout = true; } } else { needsCheckout = true; } } if (needsCheckout) { GitIndex.Entry newEntry = this._enclosing.index.AddEntry(m); this._enclosing.index.CheckoutEntry(this._enclosing.root, newEntry); } }
/// <exception cref="System.IO.IOException"></exception> private void ReadTree(byte[] raw) { int rawSize = raw.Length; int rawPtr = 0; TreeEntry[] temp; int nextIndex = 0; while (rawPtr < rawSize) { while (rawPtr < rawSize && raw[rawPtr] != 0) { rawPtr++; } rawPtr++; rawPtr += Constants.OBJECT_ID_LENGTH; nextIndex++; } temp = new TreeEntry[nextIndex]; rawPtr = 0; nextIndex = 0; while (rawPtr < rawSize) { int c = raw[rawPtr++]; if (c < '0' || c > '7') { throw new CorruptObjectException(GetId(), JGitText.Get().corruptObjectInvalidEntryMode ); } int mode = c - '0'; for (; ; ) { c = raw[rawPtr++]; if (' ' == c) { break; } else { if (c < '0' || c > '7') { throw new CorruptObjectException(GetId(), JGitText.Get().corruptObjectInvalidMode ); } } mode <<= 3; mode += c - '0'; } int nameLen = 0; while (raw[rawPtr + nameLen] != 0) { nameLen++; } byte[] name = new byte[nameLen]; System.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.REGULAR_FILE.Equals(mode)) { ent = new FileTreeEntry(this, id, name, false); } else { if (FileMode.EXECUTABLE_FILE.Equals(mode)) { ent = new FileTreeEntry(this, id, name, true); } else { if (FileMode.TREE.Equals(mode)) { ent = new NGit.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(GetId(), MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode2 , Sharpen.Extensions.ToOctalString(mode))); } } } } } temp[nextIndex++] = ent; } contents = temp; }
/// <summary>Return all members of the tree sorted in Git order.</summary> /// <remarks> /// Return all members of the tree sorted in Git order. /// Entries are sorted by the numerical unsigned byte /// values with (sub)trees having an implicit '/'. An /// example of a tree with three entries. a:b is an /// actual file name here. /// <p> /// 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 a.b /// 040000 tree 4277b6e69d25e5efa77c455340557b384a4c018a a /// 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 a:b /// </remarks> /// <returns>all entries in this Tree, sorted.</returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual TreeEntry[] Members() { EnsureLoaded(); TreeEntry[] c = contents; if (c.Length != 0) { TreeEntry[] r = new TreeEntry[c.Length]; for (int k = c.Length - 1; k >= 0; k--) { r[k] = c[k]; } return r; } else { return c; } }
/// <exception cref="System.IO.IOException"></exception> private void FinishVisitTree(TreeEntry t1, TreeEntry t2, int curIndexPos) { if (t1 != null && t1.GetParent() == null) { t1 = null; } if (t2 != null && t2.GetParent() == null) { t2 = null; } FilePath f = null; string c = null; if (t1 != null) { c = t1.GetFullName(); f = new FilePath(root, c); } else { if (t2 != null) { c = t2.GetFullName(); f = new FilePath(root, c); } } if (t1 is Tree || t2 is Tree) { if (threeTrees) { visitor.FinishVisitTree((Tree)t1, (Tree)t2, c); } else { visitor.FinishVisitTree((Tree)t1, indexCounter - curIndexPos, c); } } else { if (t1 != null || t2 != null) { if (threeTrees) { visitor.VisitEntry(t1, t2, null, f); } else { visitor.VisitEntry(t1, null, f); } } } }
internal static bool Eq(TreeEntry t1, TreeEntry t2) { return Compare(t1, t2) == 0; }
internal static bool Lt(TreeEntry h, GitIndex.Entry i) { return Compare(h, i) < 0; }
internal static bool Lt(GitIndex.Entry i, TreeEntry t) { return Compare(t, i) > 0; }
// Empty /// <exception cref="System.IO.IOException"></exception> public virtual void VisitEntry(TreeEntry treeEntry, TreeEntry auxEntry, GitIndex.Entry indexEntry, FilePath file) { }
internal static int Compare(TreeEntry t1, TreeEntry t2) { if (t1 != null && t1.GetParent() == null && t2 != null && t2.GetParent() == null) { return 0; } if (t1 != null && t1.GetParent() == null) { return -1; } if (t2 != null && t2.GetParent() == null) { return 1; } if (t1 == null && t2 == null) { return 0; } if (t1 == null) { return 1; } if (t2 == null) { return -1; } return Tree.CompareNames(t1.GetFullNameUTF8(), t2.GetFullNameUTF8(), TreeEntry.LastChar (t1), TreeEntry.LastChar(t2)); }
internal 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.GetFullNameUTF8(), i.GetNameUTF8(), TreeEntry.LastChar (t), TreeEntry.LastChar(i)); }
internal static bool Eq(TreeEntry t1, GitIndex.Entry e) { return Compare(t1, e) == 0; }
/// <exception cref="System.IO.IOException"></exception> public override void VisitEntry(TreeEntry treeEntry, TreeEntry auxEntry, GitIndex.Entry indexEntry, FilePath file) { if (treeEntry is Tree || auxEntry is Tree) { throw new ArgumentException(JGitText.Get().cantPassMeATree); } this._enclosing.ProcessEntry(treeEntry, auxEntry, indexEntry); }
/// <exception cref="System.IO.IOException"></exception> internal virtual void ProcessEntry(TreeEntry h, TreeEntry m, GitIndex.Entry i) { ObjectId iId = (i == null ? null : i.GetObjectId()); ObjectId mId = (m == null ? null : m.GetId()); ObjectId hId = (h == null ? null : h.GetId()); string name = (i != null ? i.GetName() : (h != null ? h.GetFullName() : m.GetFullName ())); if (i == null) { if (h == null) { updated.Put(name, mId); } else { if (m == null) { removed.AddItem(name); } else { updated.Put(name, mId); } } } else { if (h == null) { if (m == null || mId.Equals(iId)) { if (HasParentBlob(merge, name)) { if (i.IsModified(root, true)) { conflicts.AddItem(name); } else { removed.AddItem(name); } } } else { conflicts.AddItem(name); } } else { if (m == null) { if (hId.Equals(iId)) { if (i.IsModified(root, true)) { conflicts.AddItem(name); } else { removed.AddItem(name); } } else { conflicts.AddItem(name); } } else { if (!hId.Equals(mId) && !hId.Equals(iId) && !mId.Equals(iId)) { conflicts.AddItem(name); } else { if (hId.Equals(iId) && !mId.Equals(iId)) { if (i.IsModified(root, true)) { conflicts.AddItem(name); } else { updated.Put(name, mId); } } } } } } }
public override void VisitEntry(TreeEntry treeEntry, GitIndex.Entry indexEntry, FilePath file) { if (treeEntry == null) { this._enclosing.indexOnlyEntriesVisited.AddItem(indexEntry.GetName()); } else { if (indexEntry == null) { this._enclosing.treeOnlyEntriesVisited.AddItem(treeEntry.GetFullName()); } else { this._enclosing.bothVisited.AddItem(indexEntry.GetName()); } } }
private static int BinarySearch(TreeEntry[] entries, byte[] nameUTF8, int nameUTF8last , int nameStart, int nameEnd) { if (entries.Length == 0) { return -1; } int high = entries.Length; int low = 0; do { int mid = (int)(((uint)(low + high)) >> 1); int cmp = CompareNames(entries[mid].GetNameUTF8(), nameUTF8, nameStart, nameEnd, TreeEntry.LastChar(entries[mid]), nameUTF8last); if (cmp < 0) { low = mid + 1; } else { if (cmp == 0) { return mid; } else { high = mid; } } } while (low < high); return -(low + 1); }
internal static bool Lt(TreeEntry h, TreeEntry m) { return Compare(h, m) < 0; }
/// <exception cref="System.IO.IOException"></exception> private void ReadTree(byte[] raw) { int rawSize = raw.Length; int rawPtr = 0; TreeEntry[] temp; int nextIndex = 0; while (rawPtr < rawSize) { while (rawPtr < rawSize && raw[rawPtr] != 0) { rawPtr++; } rawPtr++; rawPtr += Constants.OBJECT_ID_LENGTH; nextIndex++; } temp = new TreeEntry[nextIndex]; rawPtr = 0; nextIndex = 0; while (rawPtr < rawSize) { int c = raw[rawPtr++]; if (c < '0' || c > '7') { throw new CorruptObjectException(GetId(), JGitText.Get().corruptObjectInvalidEntryMode ); } int mode = c - '0'; for (; ;) { c = raw[rawPtr++]; if (' ' == c) { break; } else { if (c < '0' || c > '7') { throw new CorruptObjectException(GetId(), JGitText.Get().corruptObjectInvalidMode ); } } mode <<= 3; mode += c - '0'; } int nameLen = 0; while (raw[rawPtr + nameLen] != 0) { nameLen++; } byte[] name = new byte[nameLen]; System.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.REGULAR_FILE.Equals(mode)) { ent = new FileTreeEntry(this, id, name, false); } else { if (FileMode.EXECUTABLE_FILE.Equals(mode)) { ent = new FileTreeEntry(this, id, name, true); } else { if (FileMode.TREE.Equals(mode)) { ent = new NGit.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(GetId(), MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode2 , Sharpen.Extensions.ToOctalString(mode))); } } } } } temp[nextIndex++] = ent; } contents = temp; }
public override void VisitEntry(TreeEntry entry, GitIndex.Entry indexEntry, FilePath f) { if (entry == null || indexEntry == null) { NUnit.Framework.Assert.Fail(); } }
/// <exception cref="System.IO.IOException"></exception> private void VisitEntry(TreeEntry t1, TreeEntry t2, GitIndex.Entry i) { // assert t1 != null || t2 != null || i != null : // org.eclipse.jgit.JGitText.get().needsAtLeastOneEntry; // assert root != null : JGitText.get().needsWorkdir; if (t1 != null && t1.GetParent() == null) { t1 = null; } if (t2 != null && t2.GetParent() == null) { t2 = null; } FilePath f = null; if (i != null) { f = new FilePath(root, i.GetName()); } else { if (t1 != null) { f = new FilePath(root, t1.GetFullName()); } else { if (t2 != null) { f = new FilePath(root, t2.GetFullName()); } } } if (t1 != null || t2 != null || i != null) { if (threeTrees) { visitor.VisitEntry(t1, t2, i, f); } else { visitor.VisitEntry(t1, i, f); } } }