/** * Reset this walker to run over a set of existing trees. * * @param ids the trees we need to parse. The walker will execute over this many parallel trees if * the reset is successful. * @throws MissingObjectException the given tree object does not exist in this repository. * @throws IncorrectObjectTypeException the given object id does not denote a tree, but instead * names some other non-tree type of object. Note that commits are not trees, even if they are * sometimes called a "tree-ish". * @throws CorruptObjectException the object claimed to be a tree, but its contents did not appear * to be a tree. The repository may have data corruption. * @throws IOException a loose object or pack file could not be read. */ public void reset(final AnyObjectId[] ids) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { final int oldLen = trees.length; final int newLen = ids.length; final AbstractTreeIterator[] r = newLen == oldLen ? trees : new AbstractTreeIterator[newLen]; for (int i = 0; i < newLen; i++) { AbstractTreeIterator o; if (i < oldLen) { o = trees[i]; while (o.parent != null) o = o.parent; if (o instanceof CanonicalTreeParser && o.pathOffset == 0) { o.matches = null; o.matchShift = 0; ((CanonicalTreeParser) o).reset(db, ids[i], curs); r[i] = o; continue; } } o = parserFor(ids[i]); r[i] = o; } trees = r; advance = false; depth = 0; }
void skipEntriesEqual() throws CorruptObjectException { final AbstractTreeIterator ch = currentHead; for (int i = 0; i < trees.length; i++) { final AbstractTreeIterator t = trees[i]; if (t.matches == ch) { t.skip(); t.matches = null; } } }
AbstractTreeIterator min() throws CorruptObjectException { int i = 0; AbstractTreeIterator minRef = trees[i]; while (minRef.eof() && ++i < trees.length) minRef = trees[i]; if (minRef.eof()) return minRef; minRef.matches = minRef; while (++i < trees.length) { final AbstractTreeIterator t = trees[i]; if (t.eof()) continue; final int cmp = t.pathCompare(minRef); if (cmp < 0) { t.matches = t; minRef = t; } else if (cmp == 0) { t.matches = minRef; } } return minRef; }
/** * Add an already created tree iterator for walking. * * <p>The position of this tree is returned to the caller, in case the caller has lost track of * the order they added the trees into the walker. * * <p>The tree which the iterator operates on must have the same root as existing trees in the * walk. * * @param p an iterator to walk over. The iterator should be new, with no parent, and should still * be positioned before the first entry. The tree which the iterator operates on must have the * same root as other trees in the walk. * @return position of this tree within the walker. * @throws CorruptObjectException the iterator was unable to obtain its first entry, due to * possible data corruption within the backing data store. */ public int addTree(final AbstractTreeIterator p) throws CorruptObjectException { final int n = trees.length; final AbstractTreeIterator[] newTrees = new AbstractTreeIterator[n + 1]; System.arraycopy(trees, 0, newTrees, 0, n); newTrees[n] = p; p.matches = null; p.matchShift = 0; trees = newTrees; return n; }
/** * Reset this walker to run over a single existing tree. * * @param id the tree we need to parse. The walker will execute over this single tree if the reset * is successful. * @throws MissingObjectException the given tree object does not exist in this repository. * @throws IncorrectObjectTypeException the given object id does not denote a tree, but instead * names some other non-tree type of object. Note that commits are not trees, even if they are * sometimes called a "tree-ish". * @throws CorruptObjectException the object claimed to be a tree, but its contents did not appear * to be a tree. The repository may have data corruption. * @throws IOException a loose object or pack file could not be read. */ public void reset(final AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { if (trees.length == 1) { AbstractTreeIterator o = trees[0]; while (o.parent != null) o = o.parent; if (o instanceof CanonicalTreeParser) { o.matches = null; o.matchShift = 0; ((CanonicalTreeParser) o).reset(db, id, curs); trees[0] = o; } else { trees[0] = parserFor(id); } } else { trees = new AbstractTreeIterator[] {parserFor(id)}; } advance = false; depth = 0; }