From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: git@vger.kernel.org
Cc: "Shawn O. Pearce" <spearce@spearce.org>,
Marek Zawirski <marek.zawirski@gmail.com>,
Florian Koeberle <florianskarten@web.de>,
Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [JGIT PATCH 4/4] LsTree: Enable pattern matching in LsTree
Date: Tue, 24 Jun 2008 23:20:27 +0200 [thread overview]
Message-ID: <1214342427-2077-4-git-send-email-robin.rosenberg@dewire.com> (raw)
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
next prev parent reply other threads:[~2008-06-24 21:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20080622233525.GJ11793@spearce.org>
2008-06-24 21:20 ` [JGIT PATCH 1/4] LsTree: Do not use the default first empty tree in the walker Robin Rosenberg
2008-06-24 21:20 ` [JGIT PATCH 2/4] Create a fnmatch-style pattern TreeFilter Robin Rosenberg
2008-06-24 21:20 ` [JGIT PATCH 3/4] Added a method to get the non-relative name from the tree walker Robin Rosenberg
2008-06-24 21:20 ` Robin Rosenberg [this message]
2008-06-24 21:36 ` oops, resend Robin Rosenberg
2008-06-24 21:36 ` [JGIT PATCH 1/4] LsTree: Do not use the default first empty tree in the walker Robin Rosenberg
2008-06-24 21:36 ` [JGIT PATCH 2/4] Create a fnmatch-style pattern TreeFilter Robin Rosenberg
2008-06-24 21:36 ` [JGIT PATCH 3/4] Added a method to get the non-relative name from the tree walker Robin Rosenberg
2008-06-24 21:36 ` [JGIT PATCH 4/4] LsTree: Enable pattern matching in LsTree Robin Rosenberg
2008-06-25 4:09 ` Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1214342427-2077-4-git-send-email-robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=florianskarten@web.de \
--cc=git@vger.kernel.org \
--cc=marek.zawirski@gmail.com \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).