From: Shawn O. Pearce Date: Sun, 10 Aug 2008 08:46:21 GMT Subject: [EGIT PATCH 06/11] Add getTree to TreeWalk for locating the current iterator instance Message-ID: <1218357986-19671-7-git-send-email-spearce@spearce.org> In-Reply-To: <1218357986-19671-6-git-send-email-spearce@spearce.org> Since TreeWalk creates new child iterators as it dives into a subtree (and pops them when it comes out of the subtree) we must allow callers to locate their current iterator if they need additional APIs from it. Signed-off-by: Shawn O. Pearce --- .../src/org/spearce/jgit/treewalk/TreeWalk.java | 23 ++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java index 7ea16b5..9f373e6 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java @@ -413,6 +413,29 @@ public class TreeWalk { } /** + * Obtain the tree iterator for the current entry. + *

+ * Entering into (or exiting out of) a subtree causes the current tree + * iterator instance to be changed for the nth tree. This allows the tree + * iterators to manage only one list of items, with the diving handled by + * recursive trees. + * + * @param + * type of the tree iterator expected by the caller. + * @param nth + * tree to obtain the current iterator of. + * @param clazz + * type of the tree iterator expected by the caller. + * @return r the current iterator of the requested type; null if the tree + * has no entry to match the current path. + */ + public T getTree(final int nth, + final Class clazz) { + final AbstractTreeIterator t = trees[nth]; + return t.matches == currentHead ? (T) t : null; + } + + /** * Obtain the raw {@link FileMode} bits for the current entry. *

* Every added tree supplies mode bits, even if the tree does not contain -- 1.6.0.rc2.219.g1250ab