/// <summary> /// Recursively add an entire tree into this builder. /// <para /> /// If pathPrefix is "a/b" and the tree contains file "c" then the resulting /// DirCacheEntry will have the path "a/b/c". /// <para /> /// All entries are inserted at stage 0, therefore assuming that the /// application will not insert any other paths with the same pathPrefix. /// </summary> /// <param name="pathPrefix"> /// UTF-8 encoded prefix to mount the tree's entries at. If the /// path does not end with '/' one will be automatically inserted /// as necessary. /// </param> /// <param name="stage">Stage of the entries when adding them.</param> /// <param name="db"> /// Repository the tree(s) will be read from during recursive /// traversal. This must be the same repository that the resulting /// <see cref="DirCache"/> would be written out to (or used in) otherwise /// the caller is simply asking for deferred MissingObjectExceptions. /// </param> /// <param name="tree"> /// The tree to recursively add. This tree's contents will appear /// under <paramref name="pathPrefix"/>. The ObjectId must be that of a /// tree; the caller is responsible for dereferencing a tag or /// commit (if necessary). /// </param> /// <exception cref="IOException"> /// A tree cannot be read to iterate through its entries. /// </exception> public void addTree(byte[] pathPrefix, int stage, Repository db, AnyObjectId tree) { var tw = new TreeWalk.TreeWalk(db); tw.reset(); var curs = new WindowCursor(); try { tw.addTree(new CanonicalTreeParser(pathPrefix, db, tree.ToObjectId(), curs)); } finally { curs.Release(); } tw.Recursive = true; if (!tw.next()) { return; } DirCacheEntry newEntry = ToEntry(stage, tw); BeforeAdd(newEntry); FastAdd(newEntry); while (tw.next()) { FastAdd(ToEntry(stage, tw)); } }
/// <summary> /// Open an iterator over a tree. /// </summary> /// <param name="treeId"> /// the tree to scan; must be a tree (not a <see cref="Treeish"/>). /// </param> /// <returns>An iterator for the tree.</returns> /// <exception cref="IncorrectObjectTypeException"> /// the input object is not a tree. /// </exception> /// <exception cref="IOException"> /// the tree object is not found or cannot be read. /// </exception> protected AbstractTreeIterator OpenTree(AnyObjectId treeId) { var windowCursor = new WindowCursor(); try { return(new CanonicalTreeParser(null, _db, treeId, windowCursor)); } finally { windowCursor.Release(); } }
public override AbstractTreeIterator createSubtreeIterator(Repository repo) { var curs = new WindowCursor(); try { return(createSubtreeIterator(repo, new MutableObjectId(), curs)); } finally { curs.Release(); } }
/// <summary> /// Recursively add an entire tree into this builder. /// <para /> /// If pathPrefix is "a/b" and the tree contains file "c" then the resulting /// DirCacheEntry will have the path "a/b/c". /// <para /> /// All entries are inserted at stage 0, therefore assuming that the /// application will not insert any other paths with the same pathPrefix. /// </summary> /// <param name="pathPrefix"> /// UTF-8 encoded prefix to mount the tree's entries at. If the /// path does not end with '/' one will be automatically inserted /// as necessary. /// </param> /// <param name="stage">Stage of the entries when adding them.</param> /// <param name="db"> /// Repository the tree(s) will be read from during recursive /// traversal. This must be the same repository that the resulting /// <see cref="DirCache"/> would be written out to (or used in) otherwise /// the caller is simply asking for deferred MissingObjectExceptions. /// </param> /// <param name="tree"> /// The tree to recursively add. This tree's contents will appear /// under <paramref name="pathPrefix"/>. The ObjectId must be that of a /// tree; the caller is responsible for dereferencing a tag or /// commit (if necessary). /// </param> /// <exception cref="IOException"> /// A tree cannot be read to iterate through its entries. /// </exception> public void addTree(byte[] pathPrefix, int stage, Repository db, AnyObjectId tree) { var tw = new TreeWalk.TreeWalk(db); tw.reset(); var curs = new WindowCursor(); try { tw.addTree(new CanonicalTreeParser(pathPrefix, db, tree.ToObjectId(), curs)); } finally { curs.Release(); } tw.Recursive = true; if (!tw.next()) return; DirCacheEntry newEntry = ToEntry(stage, tw); BeforeAdd(newEntry); FastAdd(newEntry); while (tw.next()) { FastAdd(ToEntry(stage, tw)); } }
/// <summary> /// Open an iterator over a tree. /// </summary> /// <param name="treeId"> /// the tree to scan; must be a tree (not a <see cref="Treeish"/>). /// </param> /// <returns>An iterator for the tree.</returns> /// <exception cref="IncorrectObjectTypeException"> /// the input object is not a tree. /// </exception> /// <exception cref="IOException"> /// the tree object is not found or cannot be read. /// </exception> protected AbstractTreeIterator OpenTree(AnyObjectId treeId) { var windowCursor = new WindowCursor(); try { return new CanonicalTreeParser(null, _db, treeId, windowCursor); } finally { windowCursor.Release(); } }
public override AbstractTreeIterator createSubtreeIterator(Repository repo) { var curs = new WindowCursor(); try { return createSubtreeIterator(repo, new MutableObjectId(), curs); } finally { curs.Release(); } }
/// <summary> /// Consume data from the input stream until the packfile is indexed. /// </summary> /// <param name="progress">progress feedback</param> public void index(ProgressMonitor progress) { progress.Start(2 /* tasks */); try { try { ReadPackHeader(); _entries = new PackedObjectInfo[(int)_objectCount]; _baseById = new ObjectIdSubclassMap <DeltaChain>(); _baseByPos = new LongMap <UnresolvedDelta>(); progress.BeginTask(PROGRESS_DOWNLOAD, (int)_objectCount); for (int done = 0; done < _objectCount; done++) { IndexOneObject(); progress.Update(1); if (progress.IsCancelled) { throw new IOException("Download cancelled"); } } ReadPackFooter(); EndInput(); progress.EndTask(); if (_deltaCount > 0) { if (_packOut == null) { throw new IOException("need packOut"); } ResolveDeltas(progress); if (_needBaseObjectIds) { _baseIds = new HashSet <ObjectId>(); foreach (var c in _baseById) { _baseIds.Add(c); } } if (_entryCount < _objectCount) { if (!_fixThin) { throw new IOException("pack has " + (_objectCount - _entryCount) + " unresolved deltas"); } FixThinPack(progress); } } if (_packOut != null && (_keepEmpty || _entryCount > 0)) { _packOut.Flush(); } _packDigest = null; _baseById = null; _baseByPos = null; if (_dstIdx != null && (_keepEmpty || _entryCount > 0)) { WriteIdx(); } } finally { try { InflaterCache.Instance.release(_inflater); } finally { _inflater = null; _objectDatabase.close(); } _windowCursor = WindowCursor.Release(_windowCursor); progress.EndTask(); if (_packOut != null) { _packOut.Dispose(); } } if (_keepEmpty || _entryCount > 0) { if (_dstPack != null) { _dstPack.IsReadOnly = true; } if (_dstIdx != null) { _dstIdx.IsReadOnly = true; } } } catch (IOException) { if (_dstPack != null) { _dstPack.DeleteFile(); } if (_dstIdx != null) { _dstIdx.DeleteFile(); } throw; } }