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

[JGIT PATCH 3/4] Added a method to get the non-relative name from the tree walker

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Jun 24, 2008, 21:20 UTC
Message-ID
<1214342427-2077-3-git-send-email-robin.rosenberg@dewire.com>
In-Reply-To
<1214342427-2077-2-git-send-email-robin.rosenberg@dewire.com>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/treewalk/TreeWalk.java    |   21 ++++++++++++++++++++
 1 files changed, 21 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 42f8b25..a5eb4d9 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java
@@ -499,6 +499,17 @@ public class TreeWalk {
 	}
 
 	/**
+	 * Get the current entry's name.
+	 * <p>
+	 *
+	 * @return name of the current entry only.
+	 * @see #getPathString()
+	 */
+	public String getName() {
+		return nameOf(currentHead);
+	}
+
+	/**
 	 * Test if the supplied path matches the current entry's path.
 	 * <p>
 	 * This method tests that the supplied path is exactly equal to the current
@@ -659,4 +670,14 @@ public class TreeWalk {
 					+ Constants.CHARACTER_ENCODING, uee);
 		}
 	}
+
+	private static String nameOf(final AbstractTreeIterator t) {
+		try {
+			return new String(t.path, t.pathOffset, t.pathLen - t.pathOffset,
+					Constants.CHARACTER_ENCODING);
+		} catch (UnsupportedEncodingException uee) {
+			throw new RuntimeException("JVM doesn't support "
+					+ Constants.CHARACTER_ENCODING, uee);
+		}
+	}
 }
-- 
1.5.5.1.178.g1f811
Previous: Robin RosenbergNext: Robin Rosenberg
Message 3 of 10 in “LsTree: Do not use the default first empty tree in the walker”
  1. 1/4 LsTree: Do not use the default first empty tree in the walkerRobin Rosenberg, Jun 24, 2008
  2. 2/4 Create a fnmatch-style pattern TreeFilterRobin Rosenberg, Jun 24, 2008
  3. 3/4 Added a method to get the non-relative name from the tree walkerRobin Rosenberg, Jun 24, 2008
  4. 4/4 LsTree: Enable pattern matching in LsTreeRobin Rosenberg, Jun 24, 2008
  5. oops, resendRobin Rosenberg, Jun 24, 2008
  6. 1/4 LsTree: Do not use the default first empty tree in the walkerRobin Rosenberg, Jun 24, 2008
  7. 2/4 Create a fnmatch-style pattern TreeFilterRobin Rosenberg, Jun 24, 2008
  8. 3/4 Added a method to get the non-relative name from the tree walkerRobin Rosenberg, Jun 24, 2008
  9. 4/4 LsTree: Enable pattern matching in LsTreeRobin Rosenberg, Jun 24, 2008
  10. Shawn O. PearceJun 25, 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.