/// <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(); } }
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()); } }
/** * 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; }
/** * 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; }
/** * 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) { }
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); }
private void AssertCorrectId(DirCache treeT, GitSharp.TreeWalk.TreeWalk tw) { Assert.Equals(treeT.getEntry(tw.getPathString()).getObjectId(), tw.getObjectId(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]; }
/** * 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>(); }
public InCoreMerger(Repository local) : base(local) { _tw = new NameConflictTreeWalk(Db); _cache = DirCache.newInCore(); }
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++; } }
/// <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>(); }