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

[JGIT PATCH 4/4] LsTree: Enable pattern matching in LsTree

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Jun 24, 2008, 21:20 UTC
Message-ID
<1214342427-2077-4-git-send-email-robin.rosenberg@dewire.com>
In-Reply-To
<1214342427-2077-3-git-send-email-robin.rosenberg@dewire.com>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/pgm/LsTree.java           |   14 +++++++++++++-
 .../jgit/treewalk/filter/WildCardTreeFilter.java   |    2 +-
 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java b/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java
index 05ec8c3..87a003d 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java
@@ -43,8 +43,11 @@ import org.spearce.jgit.lib.Constants;
 import org.spearce.jgit.lib.FileMode;
 import org.spearce.jgit.treewalk.FileTreeIterator;
 import org.spearce.jgit.treewalk.TreeWalk;
+import org.spearce.jgit.treewalk.filter.TreeFilter;
+import org.spearce.jgit.treewalk.filter.WildCardTreeFilter;
 
 class LsTree extends TextBuiltin {
+
 	@Override
 	void execute(final String[] args) throws Exception {
 		final TreeWalk walk = new TreeWalk(db);
@@ -66,12 +69,21 @@ class LsTree extends TextBuiltin {
 			throw die("too many arguments");
 
 		walk.reset(); // drop the first empty tree, which we do not need here
-		final String n = args[argi];
+		final String n = args[argi++];
 		if (is_WorkDir(n))
 			walk.addTree(new FileTreeIterator(new File(n)));
 		else
 			walk.addTree(resolve(n));
 
+		if (argi == args.length - 1) {
+			TreeFilter filter = WildCardTreeFilter.create(args[argi++]);
+			walk.setFilter(filter);
+		}
+		if (argi + 1 == args.length)
+			throw die("usage: [-r] treename [pattern]");
+		else if (argi + 1 < args.length)
+			throw die("too many arguments");
+
 		while (walk.next()) {
 			final FileMode mode = walk.getFileMode(0);
 			if (mode == FileMode.TREE)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java
index dc3faf9..645d52d 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java
@@ -74,7 +74,7 @@ public class WildCardTreeFilter extends TreeFilter {
 	public boolean include(TreeWalk walker) throws MissingObjectException,
 			IncorrectObjectTypeException, IOException {
 		matcher.reset();
-		matcher.append(walker.getPathString());
+		matcher.append(walker.getName());
 		if (matcher.isMatch())
 			return true;
 		return false;
-- 
1.5.5.1.178.g1f811
Previous: Robin RosenbergNext: Robin Rosenberg
Message 4 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.