public void testEmptyTree_NoTreeWalk() { DirCache dc = DirCache.read(db); Assert.AreEqual(0, dc.getEntryCount()); var i = new DirCacheIterator(dc); Assert.IsTrue(i.eof()); }
public void testNoSubtree_NoTreeWalk() { DirCache dc = DirCache.read(db); string[] paths = { "a.", "a0b" }; var ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); } DirCacheBuilder b = dc.builder(); for (int i = 0; i < ents.Length; i++) { b.add(ents[i]); } b.finish(); var iter = new DirCacheIterator(dc); int pathIdx = 0; for (; !iter.eof(); iter.next(1)) { Assert.AreEqual(pathIdx, iter.Pointer); Assert.AreSame(ents[pathIdx], iter.getDirCacheEntry()); pathIdx++; } Assert.AreEqual(paths.Length, pathIdx); }
public void testSingleSubtree_Recursive() { DirCache dc = DirCache.read(db); FileMode mode = FileMode.RegularFile; string[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" }; var ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].setFileMode(mode); } DirCacheBuilder b = dc.builder(); for (int i = 0; i < ents.Length; i++) { b.add(ents[i]); } b.finish(); var iter = new DirCacheIterator(dc); var tw = new GitSharp.TreeWalk.TreeWalk(db); tw.reset(); tw.addTree(iter); tw.Recursive = true; int pathIdx = 0; while (tw.next()) { var c = tw.getTree<DirCacheIterator>(0, typeof(DirCacheIterator)); Assert.IsNotNull(c); Assert.AreEqual(pathIdx, c.Pointer); Assert.AreSame(ents[pathIdx], c.getDirCacheEntry()); Assert.AreEqual(paths[pathIdx], tw.getPathString()); Assert.AreEqual(mode.Bits, tw.getRawMode(0)); Assert.AreSame(mode, tw.getFileMode(0)); pathIdx++; } Assert.AreEqual(paths.Length, pathIdx); }
public void testSingleSubtree_NoRecursion() { DirCache dc = DirCache.read(db); string[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" }; var ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].setFileMode(FileMode.RegularFile); } DirCacheBuilder b = dc.builder(); for (int i = 0; i < ents.Length; i++) { b.add(ents[i]); } b.finish(); string[] expPaths = { "a.", "a", "a0b" }; FileMode[] expModes = { FileMode.RegularFile, FileMode.Tree, FileMode.RegularFile }; var expPos = new[] { 0, -1, 4 }; var iter = new DirCacheIterator(dc); var tw = new GitSharp.TreeWalk.TreeWalk(db); tw.reset(); tw.addTree(iter); tw.Recursive = false; int pathIdx = 0; while (tw.next()) { Assert.AreSame(iter, tw.getTree<DirCacheIterator>(0, typeof(DirCacheIterator))); Assert.AreEqual(expModes[pathIdx].Bits, tw.getRawMode(0)); Assert.AreSame(expModes[pathIdx], tw.getFileMode(0)); Assert.AreEqual(expPaths[pathIdx], tw.getPathString()); if (expPos[pathIdx] >= 0) { Assert.AreEqual(expPos[pathIdx], iter.Pointer); Assert.AreSame(ents[expPos[pathIdx]], iter.getDirCacheEntry()); } else { Assert.AreSame(FileMode.Tree, tw.getFileMode(0)); } pathIdx++; } Assert.AreEqual(expPaths.Length, pathIdx); }
public void testNoSubtree_WithTreeWalk() { DirCache dc = DirCache.read(db); string[] paths = { "a.", "a0b" }; FileMode[] modes = { FileMode.ExecutableFile, FileMode.GitLink }; var ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].setFileMode(modes[i]); } DirCacheBuilder b = dc.builder(); for (int i = 0; i < ents.Length; i++) { b.add(ents[i]); } b.finish(); var iter = new DirCacheIterator(dc); var tw = new GitSharp.TreeWalk.TreeWalk(db); tw.reset(); tw.addTree(iter); int pathIdx = 0; while (tw.next()) { Assert.AreSame(iter, tw.getTree<DirCacheIterator>(0, typeof(DirCacheIterator))); Assert.AreEqual(pathIdx, iter.Pointer); Assert.AreSame(ents[pathIdx], iter.getDirCacheEntry()); Assert.AreEqual(paths[pathIdx], tw.getPathString()); Assert.AreEqual(modes[pathIdx].Bits, tw.getRawMode(0)); Assert.AreSame(modes[pathIdx], tw.getFileMode(0)); pathIdx++; } Assert.AreEqual(paths.Length, pathIdx); }
public DirCacheIterator(DirCacheIterator parentIterator, DirCacheTree cacheTree) : base(parentIterator, parentIterator.Path, parentIterator.PathLen + 1) { Cache = parentIterator.Cache; Tree = cacheTree; TreeStart = parentIterator._pointer; TreeEnd = TreeStart + Tree.getEntrySpan(); SubtreeId = parentIterator.SubtreeId; _pointer = parentIterator._pointer; ParseEntry(); }