git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[EGIT PATCH 06/11] Add getTree to TreeWalk for locating the current iterator instance

From
Shawn O. Pearce <spearce@spearce.org>
Date
Aug 10, 2008, 08:46 UTC
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 <spearce@spearce.org>
---
 .../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.
+	 * <p>
+	 * 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 <T>
+	 *            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 extends AbstractTreeIterator> T getTree(final int nth,
+			final Class<T> clazz) {
+		final AbstractTreeIterator t = trees[nth];
+		return t.matches == currentHead ? (T) t : null;
+	}
+
+	/**
 	 * Obtain the raw {@link FileMode} bits for the current entry.
 	 * <p>
 	 * Every added tree supplies mode bits, even if the tree does not contain
-- 
1.6.0.rc2.219.g1250ab
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 7 of 15 in “Misc. cleanups and improvements”
  1. 00/11 Misc. cleanups and improvementsShawn O. Pearce, Aug 10, 2008
  2. 01/11 Fix RawParseUtils.endOfParagraph to work on all corner casesShawn O. Pearce, Aug 10, 2008
  3. 02/11 Add test case for the RevCommit parsing codeShawn O. Pearce, Aug 10, 2008
  4. 03/11 Notify AbstractTreeIterator implementations of skipped tree entriesShawn O. Pearce, Aug 10, 2008
  5. 04/11 Allow AbstractTreeIterator subclasses to supply their own path arrayShawn O. Pearce, Aug 10, 2008
  6. 05/11 Allow WorkingTreeIterators to define their prefix path when createdShawn O. Pearce, Aug 10, 2008
  7. 06/11 Add getTree to TreeWalk for locating the current iterator instanceShawn O. Pearce, Aug 10, 2008
  8. 07/11 Allow WorkingTreeIterator to track last modified time for entriesShawn O. Pearce, Aug 10, 2008
  9. 08/11 Expose the current entry's length, last modified in WorkingTreeIteratorShawn O. Pearce, Aug 10, 2008
  10. 09/11 Expose idBuffer,idOffset in AbstractTreeIterator to applicationsShawn O. Pearce, Aug 10, 2008
  11. 10/11 Add a TreeWalk iterator implementation for IContainerShawn O. Pearce, Aug 10, 2008
  12. 11/11 Teach NB how to encode/decode an unsigned 16 bit integerShawn O. Pearce, Aug 10, 2008
  13. Robin RosenbergAug 13, 2008
  14. Shawn O. PearceAug 14, 2008
  15. Robin RosenbergAug 14, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.