public void testReadIndex_DirCacheTree()
        {
            Dictionary<string, CGitIndexRecord> cList = ReadLsFiles();
            Dictionary<string, 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.Values)
            {
                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());
            }
        }
Example #2
0
        /**
         * Create a new in-core index representation, lock it, and read from disk.
         * <p>
         * The new index will be locked and then read before it is returned to the
         * caller. Read failures are reported as exceptions and therefore prevent
         * the method from returning a partially populated index.  On read failure,
         * the lock is released.
         *
         * @param indexLocation
         *            location of the index file on disk.
         * @return a cache representing the contents of the specified index file (if
         *         it exists) or an empty cache if the file does not exist.
         * @
         *             the index file is present but could not be read, or the lock
         *             could not be obtained.
         * @throws CorruptObjectException
         *             the index file is using a format or extension that this
         *             library does not support.
         */
        public static DirCache Lock(FileInfo indexLocation)
        {
            DirCache c = new DirCache(indexLocation);
            if (!c.Lock())
                throw new IOException("Cannot lock " + indexLocation);

            try
            {
                c.read();
            }
            catch (Exception e)
            {
                c.unlock();
                throw e;
            }
            return c;
        }
Example #3
0
 /**
  * Create a new in-core index representation and read an index from disk.
  * <p>
  * The new index will be read before it is returned to the caller. Read
  * failures are reported as exceptions and therefore prevent the method from
  * returning a partially populated index.
  *
  * @param indexLocation
  *            location of the index file on disk.
  * @return a cache representing the contents of the specified index file (if
  *         it exists) or an empty cache if the file does not exist.
  * @
  *             the index file is present but could not be read.
  * @throws CorruptObjectException
  *             the index file is using a format or extension that this
  *             library does not support.
  */
 public static DirCache read(FileInfo indexLocation)
 {
     DirCache c = new DirCache(indexLocation);
     c.read();
     return c;
 }
        public void testTreeWalk_LsFiles()
        {
            Dictionary<string, CGitIndexRecord> ls = ReadLsFiles();
            var dc = new DirCache(_index);
            Assert.AreEqual(0, dc.getEntryCount());
            dc.read();
            Assert.AreEqual(ls.Count, dc.getEntryCount());

            var rItr = ls.Values.GetEnumerator();
            var tw = new GitSharp.TreeWalk.TreeWalk(db);
            tw.reset();
            tw.Recursive = true;
            tw.addTree(new DirCacheIterator(dc));
            while (rItr.MoveNext())
            {
                Assert.IsTrue(tw.next());
                var dcItr = tw.getTree<DirCacheIterator>(0, typeof(DirCacheIterator));
                Assert.IsNotNull(dcItr);
                AssertAreEqual(rItr.Current, dcItr.getDirCacheEntry());
            }
        }
        public void testReadIndex_LsFiles()
        {
            Dictionary<string, CGitIndexRecord> ls = ReadLsFiles();
            var dc = new DirCache(_index);
            Assert.AreEqual(0, dc.getEntryCount());
            dc.read();
            Assert.AreEqual(ls.Count, dc.getEntryCount());

            int i = 0;
            foreach (var val in ls.Values)
            {
                Assert.IsTrue(CGitIndexRecord.Equals(val, dc.getEntry(i)), "Invalid index: " + i);
                i++;
            }
        }