public virtual void Test006_addDeepTree() { Tree t = new Tree(db); Tree e = t.AddTree("e"); NUnit.Framework.Assert.IsNotNull(e, "have e"); NUnit.Framework.Assert.IsTrue(e.GetParent() == t, "e.parent == t"); Tree f = t.AddTree("f"); NUnit.Framework.Assert.IsNotNull(f, "have f"); NUnit.Framework.Assert.IsTrue(f.GetParent() == t, "f.parent == t"); Tree g = f.AddTree("g"); NUnit.Framework.Assert.IsNotNull(g, "have g"); NUnit.Framework.Assert.IsTrue(g.GetParent() == f, "g.parent == f"); Tree h = g.AddTree("h"); NUnit.Framework.Assert.IsNotNull(h, "have h"); NUnit.Framework.Assert.IsTrue(h.GetParent() == g, "h.parent = g"); h.SetId(SOME_FAKE_ID); NUnit.Framework.Assert.IsTrue(!h.IsModified(), "h not modified"); g.SetId(SOME_FAKE_ID); NUnit.Framework.Assert.IsTrue(!g.IsModified(), "g not modified"); f.SetId(SOME_FAKE_ID); NUnit.Framework.Assert.IsTrue(!f.IsModified(), "f not modified"); e.SetId(SOME_FAKE_ID); NUnit.Framework.Assert.IsTrue(!e.IsModified(), "e not modified"); t.SetId(SOME_FAKE_ID); NUnit.Framework.Assert.IsTrue(!t.IsModified(), "t not modified."); NUnit.Framework.Assert.AreEqual("f/g/h", h.GetFullName(), "full path of h ok"); NUnit.Framework.Assert.IsTrue(t.FindTreeMember(h.GetFullName()) == h, "Can find h" ); NUnit.Framework.Assert.IsTrue(t.FindBlobMember("f/z") == null, "Can't find f/z"); NUnit.Framework.Assert.IsTrue(t.FindBlobMember("y/z") == null, "Can't find y/z"); FileTreeEntry i = h.AddFile("i"); NUnit.Framework.Assert.IsNotNull(i); NUnit.Framework.Assert.AreEqual("f/g/h/i", i.GetFullName(), "full path of i ok"); NUnit.Framework.Assert.IsTrue(t.FindBlobMember(i.GetFullName()) == i, "Can find i" ); NUnit.Framework.Assert.IsTrue(h.IsModified(), "h modified"); NUnit.Framework.Assert.IsTrue(g.IsModified(), "g modified"); NUnit.Framework.Assert.IsTrue(f.IsModified(), "f modified"); NUnit.Framework.Assert.IsTrue(!e.IsModified(), "e not modified"); NUnit.Framework.Assert.IsTrue(t.IsModified(), "t modified"); NUnit.Framework.Assert.IsTrue(h.GetId() == null, "h no id"); NUnit.Framework.Assert.IsTrue(g.GetId() == null, "g no id"); NUnit.Framework.Assert.IsTrue(f.GetId() == null, "f no id"); NUnit.Framework.Assert.IsTrue(e.GetId() != null, "e has id"); NUnit.Framework.Assert.IsTrue(t.GetId() == null, "t no id"); }
public virtual void Test004_addTree() { Tree t = new Tree(db); t.SetId(SOME_FAKE_ID); NUnit.Framework.Assert.IsTrue(t.GetId() != null, "has id"); NUnit.Framework.Assert.IsFalse(t.IsModified(), "not modified"); string n = "bob"; Tree f = t.AddTree(n); NUnit.Framework.Assert.IsNotNull(f, "have tree"); NUnit.Framework.Assert.AreEqual(n, f.GetName(), "name matches"); NUnit.Framework.Assert.AreEqual(f.GetName(), Sharpen.Runtime.GetStringForBytes(f. GetNameUTF8(), "UTF-8"), "name matches"); NUnit.Framework.Assert.AreEqual(n, f.GetFullName(), "full name matches"); NUnit.Framework.Assert.IsTrue(f.GetId() == null, "no id"); NUnit.Framework.Assert.IsTrue(f.GetParent() == t, "parent matches"); NUnit.Framework.Assert.IsTrue(f.GetRepository() == db, "repository matches"); NUnit.Framework.Assert.IsTrue(f.IsLoaded(), "isLoaded"); NUnit.Framework.Assert.IsFalse(f.Members().Length > 0, "has items"); NUnit.Framework.Assert.IsFalse(f.IsRoot(), "is root"); NUnit.Framework.Assert.IsTrue(t.IsModified(), "parent is modified"); NUnit.Framework.Assert.IsTrue(t.GetId() == null, "parent has no id"); NUnit.Framework.Assert.IsTrue(t.FindTreeMember(f.GetName()) == f, "found bob child" ); TreeEntry[] i = t.Members(); NUnit.Framework.Assert.IsTrue(i.Length > 0, "iterator is not empty"); NUnit.Framework.Assert.IsTrue(i[0] == f, "iterator returns file"); NUnit.Framework.Assert.AreEqual(1, i.Length, "iterator is empty"); }
public virtual void Test005_addRecursiveTree() { Tree t = new Tree(db); Tree f = t.AddTree("a/b/c"); NUnit.Framework.Assert.IsNotNull(f, "created f"); NUnit.Framework.Assert.AreEqual("c", f.GetName()); NUnit.Framework.Assert.AreEqual("b", f.GetParent().GetName()); NUnit.Framework.Assert.AreEqual("a", f.GetParent().GetParent().GetName()); NUnit.Framework.Assert.IsTrue(t == f.GetParent().GetParent().GetParent(), "t is great-grandparent" ); }
public virtual void Test008_SubtreeInternalSorting() { Tree t = new Tree(db); FileTreeEntry e0 = t.AddFile("a-b"); FileTreeEntry e1 = t.AddFile("a-"); FileTreeEntry e2 = t.AddFile("a=b"); Tree e3 = t.AddTree("a"); FileTreeEntry e4 = t.AddFile("a="); TreeEntry[] ents = t.Members(); NUnit.Framework.Assert.AreSame(e1, ents[0]); NUnit.Framework.Assert.AreSame(e0, ents[1]); NUnit.Framework.Assert.AreSame(e3, ents[2]); NUnit.Framework.Assert.AreSame(e4, ents[3]); NUnit.Framework.Assert.AreSame(e2, ents[4]); }
/// <summary>Adds a new or existing Tree with the specified name to this tree.</summary> /// <remarks> /// Adds a new or existing Tree with the specified name to this tree. /// Trees are added if necessary as the name may contain '/':s. /// </remarks> /// <param name="s">an array containing the name</param> /// <param name="offset">when the name starts in the tree.</param> /// <returns> /// a /// <see cref="FileTreeEntry">FileTreeEntry</see> /// for the added tree. /// </returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual NGit.Tree AddTree(byte[] s, int offset) { int slash; int p; for (slash = offset; slash < s.Length && s[slash] != '/'; slash++) { } // search for path component terminator EnsureLoaded(); p = BinarySearch(contents, s, unchecked ((byte)'/'), offset, slash); if (p >= 0 && slash < s.Length && contents[p] is NGit.Tree) { return(((NGit.Tree)contents[p]).AddTree(s, slash + 1)); } byte[] newName = Substring(s, offset, slash); if (p >= 0) { throw new EntryExistsException(RawParseUtils.Decode(newName)); } NGit.Tree t = new NGit.Tree(this, newName); InsertEntry(p, t); return(slash == s.Length ? t : t.AddTree(s, slash + 1)); }
/// <summary>Adds a new or existing Tree with the specified name to this tree.</summary> /// <remarks> /// Adds a new or existing Tree with the specified name to this tree. /// Trees are added if necessary as the name may contain '/':s. /// </remarks> /// <param name="s">an array containing the name</param> /// <param name="offset">when the name starts in the tree.</param> /// <returns> /// a /// <see cref="FileTreeEntry">FileTreeEntry</see> /// for the added tree. /// </returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual NGit.Tree AddTree(byte[] s, int offset) { int slash; int p; for (slash = offset; slash < s.Length && s[slash] != '/'; slash++) { } // search for path component terminator EnsureLoaded(); p = BinarySearch(contents, s, unchecked((byte)'/'), offset, slash); if (p >= 0 && slash < s.Length && contents[p] is NGit.Tree) { return ((NGit.Tree)contents[p]).AddTree(s, slash + 1); } byte[] newName = Substring(s, offset, slash); if (p >= 0) { throw new EntryExistsException(RawParseUtils.Decode(newName)); } NGit.Tree t = new NGit.Tree(this, newName); InsertEntry(p, t); return slash == s.Length ? t : t.AddTree(s, slash + 1); }
public virtual void TestSimpleT() { Tree tree = new Tree(db); tree.AddTree("a"); TreeIterator i = MakeIterator(tree); NUnit.Framework.Assert.IsFalse(i.HasNext()); }
public virtual void TestEmptyTreeCorruption() { ObjectId bId = ObjectId.FromString("abbbfafe3129f85747aba7bfac992af77134c607"); RevTree tree_root; RevTree tree_A; RevTree tree_AB; RevCommit b; { Tree root = new Tree(db); Tree A = root.AddTree("A"); FileTreeEntry B = root.AddFile("B"); B.SetId(bId); Tree A_A = A.AddTree("A"); Tree A_B = A.AddTree("B"); ObjectInserter inserter = db.NewObjectInserter(); try { A_A.SetId(inserter.Insert(Constants.OBJ_TREE, A_A.Format())); A_B.SetId(inserter.Insert(Constants.OBJ_TREE, A_B.Format())); A.SetId(inserter.Insert(Constants.OBJ_TREE, A.Format())); root.SetId(inserter.Insert(Constants.OBJ_TREE, root.Format())); inserter.Flush(); } finally { inserter.Release(); } tree_root = rw.ParseTree(root.GetId()); tree_A = rw.ParseTree(A.GetId()); tree_AB = rw.ParseTree(A_A.GetId()); NUnit.Framework.Assert.AreSame(tree_AB, rw.ParseTree(A_B.GetId())); b = Commit(rw.ParseTree(root.GetId())); } MarkStart(b); AssertCommit(b, objw.Next()); NUnit.Framework.Assert.IsNull(objw.Next()); NUnit.Framework.Assert.AreSame(tree_root, objw.NextObject()); NUnit.Framework.Assert.AreSame(tree_A, objw.NextObject()); NUnit.Framework.Assert.AreSame(tree_AB, objw.NextObject()); NUnit.Framework.Assert.AreSame(rw.LookupBlob(bId), objw.NextObject()); NUnit.Framework.Assert.IsNull(objw.NextObject()); }
public virtual void TestMissingSubtree_DetectFileAdded_FileModified() { ObjectInserter inserter = db.NewObjectInserter(); ObjectId aFileId = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("a")); ObjectId bFileId = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("b")); ObjectId cFileId1 = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("c-1")); ObjectId cFileId2 = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("c-2")); // Create sub-a/empty, sub-c/empty = hello. ObjectId oldTree; { Tree root = new Tree(db); { Tree subA = root.AddTree("sub-a"); subA.AddFile("empty").SetId(aFileId); subA.SetId(inserter.Insert(Constants.OBJ_TREE, subA.Format())); } { Tree subC = root.AddTree("sub-c"); subC.AddFile("empty").SetId(cFileId1); subC.SetId(inserter.Insert(Constants.OBJ_TREE, subC.Format())); } oldTree = inserter.Insert(Constants.OBJ_TREE, root.Format()); } // Create sub-a/empty, sub-b/empty, sub-c/empty. ObjectId newTree; { Tree root = new Tree(db); { Tree subA = root.AddTree("sub-a"); subA.AddFile("empty").SetId(aFileId); subA.SetId(inserter.Insert(Constants.OBJ_TREE, subA.Format())); } { Tree subB = root.AddTree("sub-b"); subB.AddFile("empty").SetId(bFileId); subB.SetId(inserter.Insert(Constants.OBJ_TREE, subB.Format())); } { Tree subC = root.AddTree("sub-c"); subC.AddFile("empty").SetId(cFileId2); subC.SetId(inserter.Insert(Constants.OBJ_TREE, subC.Format())); } newTree = inserter.Insert(Constants.OBJ_TREE, root.Format()); } inserter.Flush(); inserter.Release(); TreeWalk tw = new TreeWalk(db); tw.Reset(oldTree, newTree); tw.Recursive = true; tw.Filter = TreeFilter.ANY_DIFF; NUnit.Framework.Assert.IsTrue(tw.Next()); NUnit.Framework.Assert.AreEqual("sub-b/empty", tw.PathString); NUnit.Framework.Assert.AreEqual(FileMode.MISSING, tw.GetFileMode(0)); NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(1)); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, tw.GetObjectId(0)); NUnit.Framework.Assert.AreEqual(bFileId, tw.GetObjectId(1)); NUnit.Framework.Assert.IsTrue(tw.Next()); NUnit.Framework.Assert.AreEqual("sub-c/empty", tw.PathString); NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(0)); NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(1)); NUnit.Framework.Assert.AreEqual(cFileId1, tw.GetObjectId(0)); NUnit.Framework.Assert.AreEqual(cFileId2, tw.GetObjectId(1)); NUnit.Framework.Assert.IsFalse(tw.Next()); }
public virtual void TestSimpleT() { Tree tree = new Tree(db); tree.AddTree("a"); TreeIterator i = MakeIterator(tree); NUnit.Framework.Assert.IsTrue(i.HasNext()); NUnit.Framework.Assert.AreEqual("a", i.Next().GetFullName()); NUnit.Framework.Assert.IsTrue(i.HasNext()); NUnit.Framework.Assert.AreEqual(string.Empty, i.Next().GetFullName()); NUnit.Framework.Assert.IsFalse(i.HasNext()); }