예제 #1
0
        public 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;
            Assert.AreSame(e1, ents[0]);
            Assert.AreSame(e0, ents[1]);
            Assert.AreSame(e3, ents[2]);
            Assert.AreSame(e4, ents[3]);
            Assert.AreSame(e2, ents[4]);
        }
예제 #2
0
        public void test006_addDeepTree()
        {
            Tree t = new Tree(db);

            Tree e = t.AddTree("e");
            Assert.IsNotNull(e);
            Assert.IsTrue(e.Parent == t);
            Tree f = t.AddTree("f");
            Assert.IsNotNull(f);
            Assert.IsTrue(f.Parent == t);
            Tree g = f.AddTree("g");
            Assert.IsNotNull(g);
            Assert.IsTrue(g.Parent == f);
            Tree h = g.AddTree("h");
            Assert.IsNotNull(h);
            Assert.IsTrue(h.Parent == g);

            h.Id = (SOME_FAKE_ID);
            Assert.IsTrue(!h.IsModified);
            g.Id = (SOME_FAKE_ID);
            Assert.IsTrue(!g.IsModified);
            f.Id = (SOME_FAKE_ID);
            Assert.IsTrue(!f.IsModified);
            e.Id = (SOME_FAKE_ID);
            Assert.IsTrue(!e.IsModified);
            t.Id = SOME_FAKE_ID;
            Assert.IsTrue(!t.IsModified);

            Assert.AreEqual("f/g/h", h.FullName);
            Assert.IsTrue(t.findTreeMember(h.FullName) == h);
            Assert.IsTrue(t.FindBlobMember("f/z") == null);
            Assert.IsTrue(t.FindBlobMember("y/z") == null);

            FileTreeEntry i = h.AddFile("i");
            Assert.IsNotNull(i);
            Assert.AreEqual("f/g/h/i", i.FullName);
            Assert.IsTrue(t.FindBlobMember(i.FullName) == i);
            Assert.IsTrue(h.IsModified);
            Assert.IsTrue(g.IsModified);
            Assert.IsTrue(f.IsModified);
            Assert.IsTrue(!e.IsModified);
            Assert.IsTrue(t.IsModified);

            Assert.IsTrue(h.Id == null);
            Assert.IsTrue(g.Id == null);
            Assert.IsTrue(f.Id == null);
            Assert.IsTrue(e.Id != null);
            Assert.IsTrue(t.Id == null);
        }
예제 #3
0
        public void test004_addTree()
        {
            Tree t = new Tree(db);
            t.Id = SOME_FAKE_ID;
            Assert.IsTrue(t.Id != null);
            Assert.IsFalse(t.IsModified);

            String n = "bob";
            Tree f = t.AddTree(n);
            Assert.IsNotNull(f);
            Assert.AreEqual(n, f.Name);
            Assert.AreEqual(f.Name, Encoding.UTF8.GetString(f.NameUTF8));
            Assert.AreEqual(n, f.FullName);
            Assert.IsTrue(f.Id == null);
            Assert.IsTrue(f.Parent == t);
            Assert.IsTrue(f.Repository == db);
            Assert.IsTrue(f.IsLoaded);
            Assert.IsFalse(f.Members.Length > 0);
            Assert.IsFalse(f.IsRoot);
            Assert.IsTrue(f.TreeEntry == f);
            Assert.IsTrue(t.IsModified);
            Assert.IsTrue(t.Id == null);
            Assert.IsTrue(t.findTreeMember(f.Name) == f);

            TreeEntry[] i = t.Members;
            Assert.IsTrue(i.Length > 0);
            Assert.IsTrue(i[0] == f);
            Assert.IsTrue(i.Length == 1);
        }
예제 #4
0
 public void test005_addRecursiveTree()
 {
     Tree t = new Tree(db);
     Tree f = t.AddTree("a/b/c");
     Assert.IsNotNull(f);
     Assert.AreEqual(f.Name, "c");
     Assert.AreEqual(f.Parent.Name, "b");
     Assert.AreEqual(f.Parent.Parent.Name, "a");
     Assert.IsTrue(t == f.Parent.Parent.Parent, "t is great-grandparent");
 }
예제 #5
0
파일: Tree.cs 프로젝트: rzeng/GitSharp
        public 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, (byte)'/', offset, slash);
            if (p >= 0 && slash < s.Length && _contents[p] is Tree)
                return ((Tree)_contents[p]).AddTree(s, slash + 1);

            byte[] newName = SubString(s, offset, slash);
            if (p >= 0)
                throw new EntryExistsException(Constants.CHARSET.GetString(newName));

            Tree t = new Tree(this, newName);
            InsertEntry(p, t);
            return slash == s.Length ? t : t.AddTree(s, slash + 1);
        }