コード例 #1
0
 public override void Next(int delta)
 {
     while (--delta >= 0)
     {
         if (currentSubtree != null)
         {
             ptr += currentSubtree.GetEntrySpan();
         }
         else
         {
             ptr++;
         }
         if (Eof)
         {
             break;
         }
         ParseEntry();
     }
 }
コード例 #2
0
 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();
 }
コード例 #3
0
 /// <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();
     }
 }
コード例 #4
0
        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());
        }
コード例 #5
0
        public virtual void TestEmptyCache_CreateEmptyCacheTree()
        {
            DirCache     dc   = db.ReadDirCache();
            DirCacheTree tree = dc.GetCacheTree(true);

            NUnit.Framework.Assert.IsNotNull(tree);
            NUnit.Framework.Assert.AreSame(tree, dc.GetCacheTree(false));
            NUnit.Framework.Assert.AreSame(tree, dc.GetCacheTree(true));
            NUnit.Framework.Assert.AreEqual(string.Empty, tree.GetNameString());
            NUnit.Framework.Assert.AreEqual(string.Empty, tree.GetPathString());
            NUnit.Framework.Assert.AreEqual(0, tree.GetChildCount());
            NUnit.Framework.Assert.AreEqual(0, tree.GetEntrySpan());
            NUnit.Framework.Assert.IsFalse(tree.IsValid());
        }
コード例 #6
0
        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());
            }
        }