コード例 #1
0
        /// <summary>
        /// Create a new iterator for an already loaded DirCache instance.
        /// <para/>
        /// 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.
        /// </summary>
        /// <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();
            }
        }
コード例 #2
0
        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());
            }
        }
コード例 #3
0
ファイル: DirCache.cs プロジェクト: gilran/GitSharp
        /**
         * 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;
        }
コード例 #4
0
ファイル: DirCache.cs プロジェクト: gilran/GitSharp
 /**
  * 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;
 }
コード例 #5
0
ファイル: DirCacheBuilder.cs プロジェクト: gilran/GitSharp
 /**
  * Construct a new builder.
  *
  * @param dc
  *            the cache this builder will eventually update.
  * @param ecnt
  *            estimated number of entries the builder will have upon
  *            completion. This sizes the initial entry table.
  */
 public DirCacheBuilder(DirCache dc, int ecnt)
     : base(dc, ecnt)
 {
 }
コード例 #6
0
ファイル: CherryPickTest.cs プロジェクト: gilran/GitSharp
	    private ObjectId Commit(ObjectWriter ow, DirCache treeB, ObjectId[] parentIds)
        {
		    Commit c = new Commit(db);
		    c.TreeId = treeB.writeTree(ow);
		    c.Author = new PersonIdent("A U Thor", "a.u.thor", 1L, 0);
		    c.Committer = c.Author;
		    c.ParentIds = parentIds;
		    c.Message = "Tree " + c.TreeId.Name;
		    return ow.WriteCommit(c);
	    }
コード例 #7
0
ファイル: CherryPickTest.cs プロジェクト: gilran/GitSharp
        private void AssertCorrectId(DirCache treeT, GitSharp.TreeWalk.TreeWalk tw) 
        {
		    Assert.Equals(treeT.getEntry(tw.getPathString()).getObjectId(), tw.getObjectId(0));
	    }
コード例 #8
0
 /**
  * Construct a new editor.
  *
  * @param dc
  *            the cache this editor will eventually update.
  * @param ecnt
  *            estimated number of entries the editor will have upon
  *            completion. This sizes the initial entry table.
  */
 protected BaseDirCacheEditor(DirCache dc, int ecnt)
 {
     cache = dc;
     entries = new DirCacheEntry[ecnt];
 }
コード例 #9
0
 /**
  * Construct a new editor.
  *
  * @param dc
  *            the cache this editor will eventually update.
  * @param ecnt
  *            estimated number of entries the editor will have upon
  *            completion. This sizes the initial entry table.
  */
 public DirCacheEditor(DirCache dc, int ecnt)
     : base(dc, ecnt)
 {
     edits = new List<PathEdit>();
 }
コード例 #10
0
		    public InCoreMerger(Repository local) : base(local)
            {
			    _tw = new NameConflictTreeWalk(Db);
			    _cache = DirCache.newInCore();
		    }
コード例 #11
0
        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());
            }
        }
コード例 #12
0
        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++;
            }
        }
コード例 #13
0
 /// <summary>
 /// Construct a new editor.
 /// </summary>
 /// <param name="dirCache">
 /// The cache this editor will eventually update.
 /// </param>
 /// <param name="entryCount">
 /// Estimated number of entries the editor will have upon
 /// completion. This sizes the initial entry table.
 /// </param>
 public DirCacheEditor(DirCache dirCache, int entryCount)
     : base(dirCache, entryCount)
 {
     _edits = new List<PathEdit>();
 }