private CanonicalTreeParser(CanonicalTreeParser p) : base(p) { }
// [henon] createSubtreeIterator0 <--- not a typo! /** * Back door to quickly create a subtree iterator for any subtree. * <p> * Don't use this unless you are ObjectWalk. The method is meant to be * called only once the current entry has been identified as a tree and its * identity has been converted into an ObjectId. * * @param repo * repository to load the tree data from. * @param id * ObjectId of the tree to open. * @param curs * window cursor to use during repository access. * @return a new parser that walks over the current subtree. * @throws IOException * a loose object or pack file could not be read. */ public CanonicalTreeParser createSubtreeIterator0(Repository repo, AnyObjectId id, WindowCursor curs) { CanonicalTreeParser p = new CanonicalTreeParser(this); p.reset(repo, id, curs); return p; }
/// <summary> /// Create a new revision and object walker for a given repository. /// </summary> /// <param name="repo"> /// The repository the walker will obtain data from. /// </param> public ObjectWalk(Repository repo) : base(repo) { _pendingObjects = new BlockObjQueue(); _treeWalk = new CanonicalTreeParser(); }
private void MarkTreeUninteresting(RevObject tree) { if ((tree.Flags & UNINTERESTING) != 0) return; tree.Flags |= UNINTERESTING; _treeWalk = _treeWalk.resetRoot(Repository, tree, WindowCursor); while (!_treeWalk.eof()) { FileMode mode = _treeWalk.EntryFileMode; var sType = (int)mode.ObjectType; switch (sType) { case Constants.OBJ_BLOB: _treeWalk.getEntryObjectId(IdBuffer); lookupBlob(IdBuffer).Flags |= UNINTERESTING; break; case Constants.OBJ_TREE: _treeWalk.getEntryObjectId(IdBuffer); RevTree t = lookupTree(IdBuffer); if ((t.Flags & UNINTERESTING) == 0) { t.Flags |= UNINTERESTING; _treeWalk = _treeWalk.createSubtreeIterator0(Repository, t, WindowCursor); continue; } break; default: if (FileMode.GitLink == FileMode.FromBits(mode.Bits)) break; _treeWalk.getEntryObjectId(IdBuffer); throw new CorruptObjectException("Invalid mode " + mode + " for " + IdBuffer + " " + _treeWalk.EntryPathString + " in " + tree + "."); } _treeWalk = _treeWalk.next(); } }
/// <summary> /// Pop the next most recent object. /// </summary> /// <returns>next most recent object; null if traversal is over.</returns> /// <exception cref="MissingObjectException"> /// One or or more of the next objects are not available from the /// object database, but were thought to be candidates for /// traversal. This usually indicates a broken link. /// </exception> /// <exception cref="IncorrectObjectTypeException"> /// One or or more of the objects in a tree do not match the type indicated. /// </exception> /// <exception cref="Exception"> /// A pack file or loose object could not be Read. /// </exception> public RevObject nextObject() { _fromTreeWalk = false; if (_nextSubtree != null) { _treeWalk = _treeWalk.createSubtreeIterator0(Repository, _nextSubtree, WindowCursor); _nextSubtree = null; } while (!_treeWalk.eof()) { FileMode mode = _treeWalk.EntryFileMode; var sType = (int)mode.ObjectType; switch (sType) { case Constants.OBJ_BLOB: _treeWalk.getEntryObjectId(IdBuffer); RevBlob blob = lookupBlob(IdBuffer); if ((blob.Flags & SEEN) != 0) break; blob.Flags |= SEEN; if (ShouldSkipObject(blob)) break; _fromTreeWalk = true; return blob; case Constants.OBJ_TREE: _treeWalk.getEntryObjectId(IdBuffer); RevTree tree = lookupTree(IdBuffer); if ((tree.Flags & SEEN) != 0) break; tree.Flags |= SEEN; if (ShouldSkipObject(tree)) break; _nextSubtree = tree; _fromTreeWalk = true; return tree; default: if (FileMode.GitLink.Equals(mode.Bits)) break; _treeWalk.getEntryObjectId(IdBuffer); throw new CorruptObjectException("Invalid mode " + mode + " for " + IdBuffer + " " + _treeWalk.EntryPathString + " in " + _currentTree + "."); } _treeWalk = _treeWalk.next(); } while (true) { RevObject obj = _pendingObjects.next(); if (obj == null) return null; if ((obj.Flags & SEEN) != 0) continue; obj.Flags |= SEEN; if (ShouldSkipObject(obj)) continue; if (obj is RevTree) { _currentTree = (RevTree)obj; _treeWalk = _treeWalk.resetRoot(Repository, _currentTree, WindowCursor); } return obj; } }
private void markTreeUninteresting(RevTree tree) { if ((tree.flags & UNINTERESTING) != 0) return; tree.flags |= UNINTERESTING; treeWalk = treeWalk.resetRoot(db, tree, curs); while (!treeWalk.eof()) { FileMode mode = treeWalk.getEntryFileMode(); int sType = (int)mode.ObjectType; switch (sType) { case Constants.OBJ_BLOB: { treeWalk.getEntryObjectId(idBuffer); lookupBlob(idBuffer).flags |= UNINTERESTING; break; } case Constants.OBJ_TREE: { treeWalk.getEntryObjectId(idBuffer); RevTree t = lookupTree(idBuffer); if ((t.flags & UNINTERESTING) == 0) { t.flags |= UNINTERESTING; treeWalk = treeWalk.createSubtreeIterator0(db, t, curs); continue; } break; } default: if (FileMode.GitLink.Equals(mode.Bits)) break; treeWalk.getEntryObjectId(idBuffer); throw new CorruptObjectException("Invalid mode " + mode + " for " + idBuffer.ToString() + " " + treeWalk.getEntryPathString() + " in " + tree + "."); } treeWalk = treeWalk.next(); } }
/** * Pop the next most recent object. * * @return next most recent object; null if traversal is over. * @throws MissingObjectException * one or or more of the next objects are not available from the * object database, but were thought to be candidates for * traversal. This usually indicates a broken link. * @throws IncorrectObjectTypeException * one or or more of the objects in a tree do not match the type * indicated. * @ * a pack file or loose object could not be read. */ public RevObject nextObject() { fromTreeWalk = false; if (nextSubtree != null) { treeWalk = treeWalk.createSubtreeIterator0(db, nextSubtree, curs); nextSubtree = null; } while (!treeWalk.eof()) { FileMode mode = treeWalk.getEntryFileMode(); int sType = (int)mode.ObjectType; switch (sType) { case Constants.OBJ_BLOB: { treeWalk.getEntryObjectId(idBuffer); RevBlob o = lookupBlob(idBuffer); if ((o.flags & SEEN) != 0) break; o.flags |= SEEN; if (shouldSkipObject(o)) break; fromTreeWalk = true; return o; } case Constants.OBJ_TREE: { treeWalk.getEntryObjectId(idBuffer); RevTree o = lookupTree(idBuffer); if ((o.flags & SEEN) != 0) break; o.flags |= SEEN; if (shouldSkipObject(o)) break; nextSubtree = o; fromTreeWalk = true; return o; } default: if (FileMode.GitLink.Equals(mode.Bits)) break; treeWalk.getEntryObjectId(idBuffer); throw new CorruptObjectException("Invalid mode " + mode + " for " + idBuffer.ToString() + " " + treeWalk.getEntryPathString() + " in " + currentTree + "."); } treeWalk = treeWalk.next(); } for (; ; ) { RevObject o = pendingObjects.next(); if (o == null) return null; if ((o.flags & SEEN) != 0) continue; o.flags |= SEEN; if (shouldSkipObject(o)) continue; if (o is RevTree) { currentTree = (RevTree)o; treeWalk = treeWalk.resetRoot(db, currentTree, curs); } return o; } }