public virtual void TestTwoLevelSubtree() { DirCache dc = db.ReadDirCache(); string[] paths = new string[] { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = FileMode.REGULAR_FILE; } int aFirst = 1; int aLast = 4; int acFirst = 2; int acLast = 3; DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); NUnit.Framework.Assert.IsNull(dc.GetCacheTree(false)); DirCacheTree root = dc.GetCacheTree(true); NUnit.Framework.Assert.IsNotNull(root); NUnit.Framework.Assert.AreSame(root, dc.GetCacheTree(true)); NUnit.Framework.Assert.AreEqual(string.Empty, root.GetNameString()); NUnit.Framework.Assert.AreEqual(string.Empty, root.GetPathString()); NUnit.Framework.Assert.AreEqual(1, root.GetChildCount()); NUnit.Framework.Assert.AreEqual(dc.GetEntryCount(), root.GetEntrySpan()); NUnit.Framework.Assert.IsFalse(root.IsValid()); DirCacheTree aTree = root.GetChild(0); NUnit.Framework.Assert.IsNotNull(aTree); NUnit.Framework.Assert.AreSame(aTree, root.GetChild(0)); NUnit.Framework.Assert.AreEqual("a", aTree.GetNameString()); NUnit.Framework.Assert.AreEqual("a/", aTree.GetPathString()); NUnit.Framework.Assert.AreEqual(1, aTree.GetChildCount()); NUnit.Framework.Assert.AreEqual(aLast - aFirst + 1, aTree.GetEntrySpan()); NUnit.Framework.Assert.IsFalse(aTree.IsValid()); DirCacheTree acTree = aTree.GetChild(0); NUnit.Framework.Assert.IsNotNull(acTree); NUnit.Framework.Assert.AreSame(acTree, aTree.GetChild(0)); NUnit.Framework.Assert.AreEqual("c", acTree.GetNameString()); NUnit.Framework.Assert.AreEqual("a/c/", acTree.GetPathString()); NUnit.Framework.Assert.AreEqual(0, acTree.GetChildCount()); NUnit.Framework.Assert.AreEqual(acLast - acFirst + 1, acTree.GetEntrySpan()); NUnit.Framework.Assert.IsFalse(acTree.IsValid()); }
private void ParseEntry() { currentEntry = cache.GetEntry(ptr); byte[] cep = currentEntry.path; if (nextSubtreePos != tree.GetChildCount()) { DirCacheTree s = tree.GetChild(nextSubtreePos); if (s.Contains(cep, pathOffset, cep.Length)) { // The current position is the first file of this subtree. // Use the subtree instead as the current position. // currentSubtree = s; nextSubtreePos++; if (s.IsValid()) { s.GetObjectId().CopyRawTo(subtreeId, 0); } mode = FileMode.TREE.GetBits(); path = cep; pathLen = pathOffset + s.NameLength(); return; } } // The current position is a file/symlink/gitlink so we // do not have a subtree located here. // mode = currentEntry.RawMode; path = cep; pathLen = cep.Length; currentSubtree = null; }
public virtual void TestReadIndex_DirCacheTree() { IDictionary <string, DirCacheCGitCompatabilityTest.CGitIndexRecord> cList = ReadLsFiles (); IDictionary <string, DirCacheCGitCompatabilityTest.CGitLsTreeRecord> cTree = ReadLsTree (); DirCache dc = new DirCache(index, FS.DETECTED); NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount()); dc.Read(); NUnit.Framework.Assert.AreEqual(cList.Count, dc.GetEntryCount()); DirCacheTree jTree = dc.GetCacheTree(false); NUnit.Framework.Assert.IsNotNull(jTree); NUnit.Framework.Assert.AreEqual(string.Empty, jTree.GetNameString()); NUnit.Framework.Assert.AreEqual(string.Empty, jTree.GetPathString()); NUnit.Framework.Assert.IsTrue(jTree.IsValid()); NUnit.Framework.Assert.AreEqual(ObjectId.FromString("698dd0b8d0c299f080559a1cffc7fe029479a408" ), jTree.GetObjectId()); NUnit.Framework.Assert.AreEqual(cList.Count, jTree.GetEntrySpan()); AList <DirCacheCGitCompatabilityTest.CGitLsTreeRecord> subtrees = new AList <DirCacheCGitCompatabilityTest.CGitLsTreeRecord >(); foreach (DirCacheCGitCompatabilityTest.CGitLsTreeRecord r in cTree.Values) { if (FileMode.TREE.Equals(r.mode)) { subtrees.AddItem(r); } } NUnit.Framework.Assert.AreEqual(subtrees.Count, jTree.GetChildCount()); for (int i = 0; i < jTree.GetChildCount(); i++) { DirCacheTree sj = jTree.GetChild(i); DirCacheCGitCompatabilityTest.CGitLsTreeRecord sc = subtrees[i]; NUnit.Framework.Assert.AreEqual(sc.path, sj.GetNameString()); NUnit.Framework.Assert.AreEqual(sc.path + "/", sj.GetPathString()); NUnit.Framework.Assert.IsTrue(sj.IsValid()); NUnit.Framework.Assert.AreEqual(sc.id, sj.GetObjectId()); } }