From 313d2db22c1b50bb7b0954d81257ead45b52df44 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 10 Aug 2008 01:46:21 -0700 Subject: [PATCH] Add getTree to TreeWalk for locating the current iterator instance 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 Signed-off-by: Robin Rosenberg --- .../src/org/spearce/jgit/treewalk/TreeWalk.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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 7ea16b51..9a9564a1 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 -- 2.11.4.GIT