public void testEmptyCache_Clear_NoCacheTree() { DirCache dc = DirCache.read(db); DirCacheTree tree = dc.getCacheTree(true); Assert.IsNotNull(tree); dc.clear(); Assert.IsNull(dc.getCacheTree(false)); Assert.AreNotSame(tree, dc.getCacheTree(true)); }
public void testTwoLevelSubtree() { DirCache dc = DirCache.read(db); string[] paths = { "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].setFileMode(FileMode.RegularFile); } int aFirst = 1; int aLast = 4; int acFirst = 2; int acLast = 3; DirCacheBuilder b = dc.builder(); for (int i = 0; i < ents.Length; i++) { b.add(ents[i]); } b.finish(); Assert.IsNull(dc.getCacheTree(false)); DirCacheTree root = dc.getCacheTree(true); Assert.IsNotNull(root); Assert.AreSame(root, dc.getCacheTree(true)); Assert.AreEqual(string.Empty, root.getNameString()); Assert.AreEqual(string.Empty, root.getPathString()); Assert.AreEqual(1, root.getChildCount()); Assert.AreEqual(dc.getEntryCount(), root.getEntrySpan()); Assert.IsFalse(root.isValid()); DirCacheTree aTree = root.getChild(0); Assert.IsNotNull(aTree); Assert.AreSame(aTree, root.getChild(0)); Assert.AreEqual("a", aTree.getNameString()); Assert.AreEqual("a/", aTree.getPathString()); Assert.AreEqual(1, aTree.getChildCount()); Assert.AreEqual(aLast - aFirst + 1, aTree.getEntrySpan()); Assert.IsFalse(aTree.isValid()); DirCacheTree acTree = aTree.getChild(0); Assert.IsNotNull(acTree); Assert.AreSame(acTree, aTree.getChild(0)); Assert.AreEqual("c", acTree.getNameString()); Assert.AreEqual("a/c/", acTree.getPathString()); Assert.AreEqual(0, acTree.getChildCount()); Assert.AreEqual(acLast - acFirst + 1, acTree.getEntrySpan()); Assert.IsFalse(acTree.isValid()); }
public void testEmptyCache_CreateEmptyCacheTree() { DirCache dc = DirCache.read(db); DirCacheTree tree = dc.getCacheTree(true); Assert.IsNotNull(tree); Assert.AreSame(tree, dc.getCacheTree(false)); Assert.AreSame(tree, dc.getCacheTree(true)); Assert.AreEqual(string.Empty, tree.getNameString()); Assert.AreEqual(string.Empty, tree.getPathString()); Assert.AreEqual(0, tree.getChildCount()); Assert.AreEqual(0, tree.getEntrySpan()); Assert.IsFalse(tree.isValid()); }
public void testReadIndex_DirCacheTree() { List <CGitIndexRecord> cList = ReadLsFiles(); List <CGitLsTreeRecord> cTree = ReadLsTree(); var dc = new DirCache(_index); Assert.AreEqual(0, dc.getEntryCount()); dc.read(); Assert.AreEqual(cList.Count, dc.getEntryCount()); DirCacheTree jTree = dc.getCacheTree(false); Assert.IsNotNull(jTree); Assert.AreEqual(string.Empty, jTree.getNameString()); Assert.AreEqual(string.Empty, jTree.getPathString()); Assert.IsTrue(jTree.isValid()); Assert.AreEqual(ObjectId .FromString("698dd0b8d0c299f080559a1cffc7fe029479a408"), jTree .getObjectId()); Assert.AreEqual(cList.Count, jTree.getEntrySpan()); var subtrees = new List <CGitLsTreeRecord>(); foreach (CGitLsTreeRecord r in cTree) { if (FileMode.Tree.Equals(r.Mode)) { subtrees.Add(r); } } Assert.AreEqual(subtrees.Count, jTree.getChildCount()); for (int i = 0; i < jTree.getChildCount(); i++) { DirCacheTree sj = jTree.getChild(i); CGitLsTreeRecord sc = subtrees[i]; Assert.AreEqual(sc.Path, sj.getNameString()); Assert.AreEqual(sc.Path + "/", sj.getPathString()); Assert.IsTrue(sj.isValid()); Assert.AreEqual(sc.Id, sj.getObjectId()); } }
internal DirCacheBuildIterator(NGit.Dircache.DirCacheBuildIterator p, DirCacheTree dct) : base(p, dct) { builder = p.builder; }
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; }
internal DirCacheIterator(NGit.Dircache.DirCacheIterator p, DirCacheTree dct) : base (p, p.path, p.pathLen + 1) { cache = p.cache; tree = dct; treeStart = p.ptr; treeEnd = treeStart + tree.GetEntrySpan(); subtreeId = p.subtreeId; ptr = p.ptr; ParseEntry(); }
/// <summary>Create a new iterator for an already loaded DirCache instance.</summary> /// <remarks> /// Create a new iterator for an already loaded DirCache instance. /// <p> /// The iterator implementation may copy part of the cache's data during /// construction, so the cache must be read in prior to creating the /// iterator. /// </remarks> /// <param name="dc">the cache to walk. It must be already loaded into memory.</param> public DirCacheIterator(DirCache dc) { cache = dc; tree = dc.GetCacheTree(true); treeStart = 0; treeEnd = tree.GetEntrySpan(); subtreeId = new byte[Constants.OBJECT_ID_LENGTH]; if (!Eof) { ParseEntry(); } }