Iterate a DirCache as part of a TreeWalk. This is an iterator to adapt a loaded DirCache instance (such as Read from an existing .git/index file) to the tree structure used by a TreeWalk, making it possible for applications to walk over any combination of tree objects already in the object database, index files, or working directories.
Inheritance: GitSharp.Core.TreeWalk.AbstractTreeIterator
        public void testEmptyTree_NoTreeWalk()
        {
            DirCache dc = DirCache.read(db);
            Assert.AreEqual(0, dc.getEntryCount());

            var i = new DirCacheIterator(dc);
            Assert.IsTrue(i.eof());
        }
Example #2
0
 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();
 }
 public DirCacheIterator(DirCacheIterator parentIterator, DirCacheTree cacheTree)
     : base(parentIterator, parentIterator.Path, parentIterator.PathLen + 1)
 {
     if (parentIterator == null)
     {
         throw new System.ArgumentNullException("parentIterator");
     }
     Cache     = parentIterator.Cache;
     Tree      = cacheTree;
     TreeStart = parentIterator._pointer;
     TreeEnd   = TreeStart + Tree.getEntrySpan();
     SubtreeId = parentIterator.SubtreeId;
     _pointer  = parentIterator._pointer;
     ParseEntry();
 }
        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.Core.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.Core.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.Core.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)
 {
     if ( parentIterator == null)
     {
         throw new System.ArgumentNullException("parentIterator");
     }
     Cache = parentIterator.Cache;
     Tree = cacheTree;
     TreeStart = parentIterator._pointer;
     TreeEnd = TreeStart + Tree.getEntrySpan();
     SubtreeId = parentIterator.SubtreeId;
     _pointer = parentIterator._pointer;
     ParseEntry();
 }
Example #9
0
 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();
 }