git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [JGIT PATCH 1/4] LsTree: Do not use the default first empty tree in the walker
       [not found] <20080622233525.GJ11793@spearce.org>
@ 2008-06-24 21:20 ` Robin Rosenberg
  2008-06-24 21:20   ` [JGIT PATCH 2/4] Create a fnmatch-style pattern TreeFilter Robin Rosenberg
  2008-06-24 21:36 ` oops, resend Robin Rosenberg
  1 sibling, 1 reply; 10+ messages in thread
From: Robin Rosenberg @ 2008-06-24 21:20 UTC (permalink / raw)
  To: git; +Cc: Shawn O. Pearce, Marek Zawirski, Florian Koeberle,
	Robin Rosenberg

In f0ef5e1ef09d346432fead17bc82d78b7cfbd621 an empty tree
was added to all TreeWalkers.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/pgm/LsTree.java           |    1 +
 1 files changed, 1 insertions(+), 0 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 1bc7bbd..05ec8c3 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java
@@ -65,6 +65,7 @@ class LsTree extends TextBuiltin {
 		else if (argi + 1 < args.length)
 			throw die("too many arguments");
 
+		walk.reset(); // drop the first empty tree, which we do not need here
 		final String n = args[argi];
 		if (is_WorkDir(n))
 			walk.addTree(new FileTreeIterator(new File(n)));
-- 
1.5.5.1.178.g1f811

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [JGIT PATCH 2/4] Create a fnmatch-style pattern TreeFilter
  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   ` 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
  0 siblings, 1 reply; 10+ messages in thread
From: Robin Rosenberg @ 2008-06-24 21:20 UTC (permalink / raw)
  To: git; +Cc: Shawn O. Pearce, Marek Zawirski, Florian Koeberle,
	Robin Rosenberg

This uses Florian's pattern matcher to perform the matching.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../jgit/treewalk/filter/WildCardTreeFilter.java   |  101 ++++++++++++++++++++
 1 files changed, 101 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java

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
new file mode 100644
index 0000000..dc3faf9
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the following
+ *   disclaimer in the documentation and/or other materials provided
+ *   with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ *   names of its contributors may be used to endorse or promote
+ *   products derived from this software without specific prior
+ *   written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.treewalk.filter;
+
+import java.io.IOException;
+
+import org.spearce.jgit.errors.IncorrectObjectTypeException;
+import org.spearce.jgit.errors.InvalidPatternException;
+import org.spearce.jgit.errors.MissingObjectException;
+import org.spearce.jgit.fnmatch.FileNameMatcher;
+import org.spearce.jgit.treewalk.TreeWalk;
+import org.spearce.jgit.treewalk.filter.TreeFilter;
+
+/**
+ * This class implements a TreeeFilter that uses the wildcard style pattern
+ * matching like of Posix fnmatch function.
+ */
+public class WildCardTreeFilter extends TreeFilter {
+
+	private final FileNameMatcher matcher;
+
+	private final String pattern;
+
+	protected WildCardTreeFilter(final String pattern) {
+		try {
+			this.pattern = pattern;
+			matcher = new FileNameMatcher(pattern, null);
+		} catch (InvalidPatternException e) {
+			throw new IllegalArgumentException(e);
+		}
+	}
+
+	@Override
+	public TreeFilter clone() {
+		return new WildCardTreeFilter(pattern);
+	}
+
+	@Override
+	public boolean include(TreeWalk walker) throws MissingObjectException,
+			IncorrectObjectTypeException, IOException {
+		matcher.reset();
+		matcher.append(walker.getPathString());
+		if (matcher.isMatch())
+			return true;
+		return false;
+	}
+
+	@Override
+	public boolean shouldBeRecursive() {
+		return true;
+	}
+
+	/**
+	 * Construct a WildCardmatcher like POSIX fnmatch.
+	 *
+	 * @param pattern
+	 *            A POSIX wildcard pattern
+	 * @return a {@link TreeFilter} that matches pattern
+	 * @throws IllegalArgumentException
+	 *             if the pattern is malformed
+	 */
+	public static TreeFilter create(final String pattern) {
+		return new WildCardTreeFilter(pattern);
+	}
+
+}
-- 
1.5.5.1.178.g1f811

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [JGIT PATCH 3/4] Added a method to get the non-relative name from the tree walker
  2008-06-24 21:20   ` [JGIT PATCH 2/4] Create a fnmatch-style pattern TreeFilter Robin Rosenberg
@ 2008-06-24 21:20     ` Robin Rosenberg
  2008-06-24 21:20       ` [JGIT PATCH 4/4] LsTree: Enable pattern matching in LsTree Robin Rosenberg
  0 siblings, 1 reply; 10+ messages in thread
From: Robin Rosenberg @ 2008-06-24 21:20 UTC (permalink / raw)
  To: git; +Cc: Shawn O. Pearce, Marek Zawirski, Florian Koeberle,
	Robin Rosenberg

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [JGIT PATCH 4/4] LsTree: Enable pattern matching in LsTree
  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
  0 siblings, 0 replies; 10+ messages in thread
From: Robin Rosenberg @ 2008-06-24 21:20 UTC (permalink / raw)
  To: git; +Cc: Shawn O. Pearce, Marek Zawirski, Florian Koeberle,
	Robin Rosenberg

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* oops, resend
       [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:36 ` 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
  1 sibling, 1 reply; 10+ messages in thread
From: Robin Rosenberg @ 2008-06-24 21:36 UTC (permalink / raw)
  To: git; +Cc: Shawn O. Pearce, Marek Zawirski, Florian Koeberle

I f*d the first series. 1 2 3 testing.. :(

-- robin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [JGIT PATCH 1/4] LsTree: Do not use the default first empty tree in the walker
  2008-06-24 21:36 ` oops, resend Robin Rosenberg
@ 2008-06-24 21:36   ` Robin Rosenberg
  2008-06-24 21:36     ` [JGIT PATCH 2/4] Create a fnmatch-style pattern TreeFilter Robin Rosenberg
  0 siblings, 1 reply; 10+ messages in thread
From: Robin Rosenberg @ 2008-06-24 21:36 UTC (permalink / raw)
  To: git; +Cc: Shawn O. Pearce, Marek Zawirski, Florian Koeberle,
	Robin Rosenberg

In f0ef5e1ef09d346432fead17bc82d78b7cfbd621 an empty tree
was added to all TreeWalkers.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/pgm/LsTree.java           |    1 +
 1 files changed, 1 insertions(+), 0 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 1bc7bbd..05ec8c3 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java
@@ -65,6 +65,7 @@ class LsTree extends TextBuiltin {
 		else if (argi + 1 < args.length)
 			throw die("too many arguments");
 
+		walk.reset(); // drop the first empty tree, which we do not need here
 		final String n = args[argi];
 		if (is_WorkDir(n))
 			walk.addTree(new FileTreeIterator(new File(n)));
-- 
1.5.5.1.178.g1f811

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [JGIT PATCH 2/4] Create a fnmatch-style pattern TreeFilter
  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     ` 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
  0 siblings, 1 reply; 10+ messages in thread
From: Robin Rosenberg @ 2008-06-24 21:36 UTC (permalink / raw)
  To: git; +Cc: Shawn O. Pearce, Marek Zawirski, Florian Koeberle,
	Robin Rosenberg

This uses Florian's pattern matcher to perform the matching.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../jgit/treewalk/filter/WildCardTreeFilter.java   |  103 ++++++++++++++++++++
 1 files changed, 103 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java

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
new file mode 100644
index 0000000..ce6da5e
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the following
+ *   disclaimer in the documentation and/or other materials provided
+ *   with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ *   names of its contributors may be used to endorse or promote
+ *   products derived from this software without specific prior
+ *   written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.treewalk.filter;
+
+import java.io.IOException;
+
+import org.spearce.jgit.errors.IncorrectObjectTypeException;
+import org.spearce.jgit.errors.InvalidPatternException;
+import org.spearce.jgit.errors.MissingObjectException;
+import org.spearce.jgit.fnmatch.FileNameMatcher;
+import org.spearce.jgit.treewalk.TreeWalk;
+import org.spearce.jgit.treewalk.filter.TreeFilter;
+
+/**
+ * This class implements a TreeeFilter that uses the wildcard style pattern
+ * matching like of Posix fnmatch function.
+ */
+public class WildCardTreeFilter extends TreeFilter {
+
+	private final FileNameMatcher matcher;
+
+	private final String pattern;
+
+	protected WildCardTreeFilter(final String pattern) {
+		try {
+			this.pattern = pattern;
+			matcher = new FileNameMatcher(pattern, null);
+		} catch (InvalidPatternException e) {
+			throw new IllegalArgumentException(e);
+		}
+	}
+
+	@Override
+	public TreeFilter clone() {
+		return new WildCardTreeFilter(pattern);
+	}
+
+	@Override
+	public boolean include(TreeWalk walker) throws MissingObjectException,
+			IncorrectObjectTypeException, IOException {
+		if (walker.isRecursive() && walker.isSubtree())
+			return true;
+		matcher.reset();
+		matcher.append(walker.getPathString());
+		if (matcher.isMatch())
+			return true;
+		return false;
+	}
+
+	@Override
+	public boolean shouldBeRecursive() {
+		return true;
+	}
+
+	/**
+	 * Construct a WildCardmatcher like POSIX fnmatch.
+	 *
+	 * @param pattern
+	 *            A POSIX wildcard pattern
+	 * @return a {@link TreeFilter} that matches pattern
+	 * @throws IllegalArgumentException
+	 *             if the pattern is malformed
+	 */
+	public static TreeFilter create(final String pattern) {
+		return new WildCardTreeFilter(pattern);
+	}
+
+}
-- 
1.5.5.1.178.g1f811

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [JGIT PATCH 3/4] Added a method to get the non-relative name from the tree walker
  2008-06-24 21:36     ` [JGIT PATCH 2/4] Create a fnmatch-style pattern TreeFilter Robin Rosenberg
@ 2008-06-24 21:36       ` Robin Rosenberg
  2008-06-24 21:36         ` [JGIT PATCH 4/4] LsTree: Enable pattern matching in LsTree Robin Rosenberg
  0 siblings, 1 reply; 10+ messages in thread
From: Robin Rosenberg @ 2008-06-24 21:36 UTC (permalink / raw)
  To: git; +Cc: Shawn O. Pearce, Marek Zawirski, Florian Koeberle,
	Robin Rosenberg

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [JGIT PATCH 4/4] LsTree: Enable pattern matching in LsTree
  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         ` Robin Rosenberg
  2008-06-25  4:09           ` Shawn O. Pearce
  0 siblings, 1 reply; 10+ messages in thread
From: Robin Rosenberg @ 2008-06-24 21:36 UTC (permalink / raw)
  To: git; +Cc: Shawn O. Pearce, Marek Zawirski, Florian Koeberle,
	Robin Rosenberg

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/pgm/LsTree.java           |   19 +++++++++++++------
 .../jgit/treewalk/filter/WildCardTreeFilter.java   |    2 +-
 2 files changed, 14 insertions(+), 7 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..6bb4192 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);
@@ -60,18 +63,22 @@ class LsTree extends TextBuiltin {
 				break;
 		}
 
-		if (argi == args.length)
-			throw die("usage: [-r] treename");
-		else if (argi + 1 < args.length)
-			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 ce6da5e..8b22e25 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
@@ -76,7 +76,7 @@ public class WildCardTreeFilter extends TreeFilter {
 		if (walker.isRecursive() && walker.isSubtree())
 			return true;
 		matcher.reset();
-		matcher.append(walker.getPathString());
+		matcher.append(walker.getName());
 		if (matcher.isMatch())
 			return true;
 		return false;
-- 
1.5.5.1.178.g1f811

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [JGIT PATCH 4/4] LsTree: Enable pattern matching in LsTree
  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
  0 siblings, 0 replies; 10+ messages in thread
From: Shawn O. Pearce @ 2008-06-25  4:09 UTC (permalink / raw)
  To: Robin Rosenberg; +Cc: git, Marek Zawirski, Florian Koeberle

Robin Rosenberg <robin.rosenberg@dewire.com> wrote:
> 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 ce6da5e..8b22e25 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
> @@ -76,7 +76,7 @@ public class WildCardTreeFilter extends TreeFilter {
>  		if (walker.isRecursive() && walker.isSubtree())
>  			return true;
>  		matcher.reset();
> -		matcher.append(walker.getPathString());
> +		matcher.append(walker.getName());
>  		if (matcher.isMatch())
>  			return true;
>  		return false;

Are we only supporting `jgit ls-tree . '*.c'` ?
Or do we want to allow `jgit ls-tree . 'src/*.c'`?

ls-tree is only a little sample program that is not likely to have
a lot of real-world users calling it; but is a good demonstration
of how to use TreeWalk.  So I really don't care either way.

The WildCardTreeFilter on the other hand could be applied to a
RevWalk, such as to grab history for not just 'foo.c' but anything
that matches 'f*.c'.  But then you have to ask, why is the filter
limited to testing only the last component of the path?  Why can't
it test 'src/f*.c'?

Otherwise everything in your series up until here makes sense and
looks good to me.  Be nice if the tree filter wasn't so abusive in
needing to look at every path in the project, as that would really
hurt if it was applied to a RevWalk.  But its not required to be
fast, if you ask for fnmatch paths, you get what you asked for...

-- 
Shawn.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-06-25  4:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [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       ` [JGIT PATCH 4/4] LsTree: Enable pattern matching in LsTree Robin Rosenberg
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

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).