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; }
/** * Enter into the current subtree. * * <p>If the current entry is a subtree this method arranges for its children to be returned * before the next sibling following the subtree is returned. * * @throws MissingObjectException a subtree was found, but the subtree object does not exist in * this repository. The repository may be missing objects. * @throws IncorrectObjectTypeException a subtree was found, and the subtree id does not denote a * tree, but instead names some other non-tree type of object. The repository may have data * corruption. * @throws CorruptObjectException the contents of a tree 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 enterSubtree() throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { final AbstractTreeIterator ch = currentHead; final AbstractTreeIterator[] tmp = new AbstractTreeIterator[trees.length]; for (int i = 0; i < trees.length; i++) { final AbstractTreeIterator t = trees[i]; final AbstractTreeIterator n; if (t.matches == ch && !t.eof() && FileMode.TREE.equals(t.mode)) n = t.createSubtreeIterator(db, idBuffer, curs); else n = t.createEmptyTreeIterator(); tmp[i] = n; } depth++; advance = false; System.arraycopy(tmp, 0, trees, 0, trees.length); }
/** * Advance this walker to the next relevant entry. * * @return true if there is an entry available; false if all entries have been walked and the walk * of this set of tree iterators is over. * @throws MissingObjectException {@link #isRecursive()} was enabled, a subtree was found, but the * subtree object does not exist in this repository. The repository may be missing objects. * @throws IncorrectObjectTypeException {@link #isRecursive()} was enabled, a subtree was found, * and the subtree id does not denote a tree, but instead names some other non-tree type of * object. The repository may have data corruption. * @throws CorruptObjectException the contents of a tree 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 boolean next() throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { try { if (advance) { advance = false; postChildren = false; popEntriesEqual(); } for (; ; ) { final AbstractTreeIterator t = min(); if (t.eof()) { if (depth > 0) { exitSubtree(); if (postOrderTraversal) { advance = true; postChildren = true; return true; } popEntriesEqual(); continue; } return false; } currentHead = t; if (!filter.include(this)) { skipEntriesEqual(); continue; } if (recursive && FileMode.TREE.equals(t.mode)) { enterSubtree(); continue; } advance = true; return true; } } catch (StopWalkException stop) { for (final AbstractTreeIterator t : trees) t.stopWalk(); return false; } }