{"thread":{"id":"14129","subject":"[JGIT PATCH 2/4] Create a fnmatch-style pattern TreeFilter","startedAt":"2008-06-24T21:20:24Z","lastAt":"2008-06-25T04:09:31Z","messageCount":10,"participants":["Robin Rosenberg","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"80988","messageId":"1214342427-2077-1-git-send-email-robin.rosenberg@dewire.com","threadId":"14129","inReplyTo":"20080622233525.GJ11793@spearce.org","subject":"[JGIT PATCH 1/4] LsTree: Do not use the default first empty tree in the walker","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-24T21:20:24Z","receivedAt":"2008-06-24T21:20:24Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"In f0ef5e1ef09d346432fead17bc82d78b7cfbd621 an empty tree\nwas added to all TreeWalkers.\n\nSigned-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n .../src/org/spearce/jgit/pgm/LsTree.java           |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java b/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java\nindex 1bc7bbd..05ec8c3 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java\n@@ -65,6 +65,7 @@ class LsTree extends TextBuiltin {\n \t\telse if (argi + 1 < args.length)\n \t\t\tthrow die(\"too many arguments\");\n \n+\t\twalk.reset(); // drop the first empty tree, which we do not need here\n \t\tfinal String n = args[argi];\n \t\tif (is_WorkDir(n))\n \t\t\twalk.addTree(new FileTreeIterator(new File(n)));\n-- \n1.5.5.1.178.g1f811\n"},{"id":"80986","messageId":"1214342427-2077-2-git-send-email-robin.rosenberg@dewire.com","threadId":"14129","inReplyTo":"1214342427-2077-1-git-send-email-robin.rosenberg@dewire.com","subject":"[JGIT PATCH 2/4] Create a fnmatch-style pattern TreeFilter","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-24T21:20:25Z","receivedAt":"2008-06-24T21:20:25Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"This uses Florian's pattern matcher to perform the matching.\n\nSigned-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n .../jgit/treewalk/filter/WildCardTreeFilter.java   |  101 ++++++++++++++++++++\n 1 files changed, 101 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java\n\ndiff --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\nnew file mode 100644\nindex 0000000..dc3faf9\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java\n@@ -0,0 +1,101 @@\n+/*\n+ * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.treewalk.filter;\n+\n+import java.io.IOException;\n+\n+import org.spearce.jgit.errors.IncorrectObjectTypeException;\n+import org.spearce.jgit.errors.InvalidPatternException;\n+import org.spearce.jgit.errors.MissingObjectException;\n+import org.spearce.jgit.fnmatch.FileNameMatcher;\n+import org.spearce.jgit.treewalk.TreeWalk;\n+import org.spearce.jgit.treewalk.filter.TreeFilter;\n+\n+/**\n+ * This class implements a TreeeFilter that uses the wildcard style pattern\n+ * matching like of Posix fnmatch function.\n+ */\n+public class WildCardTreeFilter extends TreeFilter {\n+\n+\tprivate final FileNameMatcher matcher;\n+\n+\tprivate final String pattern;\n+\n+\tprotected WildCardTreeFilter(final String pattern) {\n+\t\ttry {\n+\t\t\tthis.pattern = pattern;\n+\t\t\tmatcher = new FileNameMatcher(pattern, null);\n+\t\t} catch (InvalidPatternException e) {\n+\t\t\tthrow new IllegalArgumentException(e);\n+\t\t}\n+\t}\n+\n+\t@Override\n+\tpublic TreeFilter clone() {\n+\t\treturn new WildCardTreeFilter(pattern);\n+\t}\n+\n+\t@Override\n+\tpublic boolean include(TreeWalk walker) throws MissingObjectException,\n+\t\t\tIncorrectObjectTypeException, IOException {\n+\t\tmatcher.reset();\n+\t\tmatcher.append(walker.getPathString());\n+\t\tif (matcher.isMatch())\n+\t\t\treturn true;\n+\t\treturn false;\n+\t}\n+\n+\t@Override\n+\tpublic boolean shouldBeRecursive() {\n+\t\treturn true;\n+\t}\n+\n+\t/**\n+\t * Construct a WildCardmatcher like POSIX fnmatch.\n+\t *\n+\t * @param pattern\n+\t *            A POSIX wildcard pattern\n+\t * @return a {@link TreeFilter} that matches pattern\n+\t * @throws IllegalArgumentException\n+\t *             if the pattern is malformed\n+\t */\n+\tpublic static TreeFilter create(final String pattern) {\n+\t\treturn new WildCardTreeFilter(pattern);\n+\t}\n+\n+}\n-- \n1.5.5.1.178.g1f811\n"},{"id":"80987","messageId":"1214342427-2077-3-git-send-email-robin.rosenberg@dewire.com","threadId":"14129","inReplyTo":"1214342427-2077-2-git-send-email-robin.rosenberg@dewire.com","subject":"[JGIT PATCH 3/4] Added a method to get the non-relative name from the tree walker","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-24T21:20:26Z","receivedAt":"2008-06-24T21:20:26Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n .../src/org/spearce/jgit/treewalk/TreeWalk.java    |   21 ++++++++++++++++++++\n 1 files changed, 21 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\nindex 42f8b25..a5eb4d9 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\n@@ -499,6 +499,17 @@ public class TreeWalk {\n \t}\n \n \t/**\n+\t * Get the current entry's name.\n+\t * <p>\n+\t *\n+\t * @return name of the current entry only.\n+\t * @see #getPathString()\n+\t */\n+\tpublic String getName() {\n+\t\treturn nameOf(currentHead);\n+\t}\n+\n+\t/**\n \t * Test if the supplied path matches the current entry's path.\n \t * <p>\n \t * This method tests that the supplied path is exactly equal to the current\n@@ -659,4 +670,14 @@ public class TreeWalk {\n \t\t\t\t\t+ Constants.CHARACTER_ENCODING, uee);\n \t\t}\n \t}\n+\n+\tprivate static String nameOf(final AbstractTreeIterator t) {\n+\t\ttry {\n+\t\t\treturn new String(t.path, t.pathOffset, t.pathLen - t.pathOffset,\n+\t\t\t\t\tConstants.CHARACTER_ENCODING);\n+\t\t} catch (UnsupportedEncodingException uee) {\n+\t\t\tthrow new RuntimeException(\"JVM doesn't support \"\n+\t\t\t\t\t+ Constants.CHARACTER_ENCODING, uee);\n+\t\t}\n+\t}\n }\n-- \n1.5.5.1.178.g1f811\n"},{"id":"80989","messageId":"1214342427-2077-4-git-send-email-robin.rosenberg@dewire.com","threadId":"14129","inReplyTo":"1214342427-2077-3-git-send-email-robin.rosenberg@dewire.com","subject":"[JGIT PATCH 4/4] LsTree: Enable pattern matching in LsTree","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-24T21:20:27Z","receivedAt":"2008-06-24T21:20:27Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n .../src/org/spearce/jgit/pgm/LsTree.java           |   14 +++++++++++++-\n .../jgit/treewalk/filter/WildCardTreeFilter.java   |    2 +-\n 2 files changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java b/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java\nindex 05ec8c3..87a003d 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java\n@@ -43,8 +43,11 @@ import org.spearce.jgit.lib.Constants;\n import org.spearce.jgit.lib.FileMode;\n import org.spearce.jgit.treewalk.FileTreeIterator;\n import org.spearce.jgit.treewalk.TreeWalk;\n+import org.spearce.jgit.treewalk.filter.TreeFilter;\n+import org.spearce.jgit.treewalk.filter.WildCardTreeFilter;\n \n class LsTree extends TextBuiltin {\n+\n \t@Override\n \tvoid execute(final String[] args) throws Exception {\n \t\tfinal TreeWalk walk = new TreeWalk(db);\n@@ -66,12 +69,21 @@ class LsTree extends TextBuiltin {\n \t\t\tthrow die(\"too many arguments\");\n \n \t\twalk.reset(); // drop the first empty tree, which we do not need here\n-\t\tfinal String n = args[argi];\n+\t\tfinal String n = args[argi++];\n \t\tif (is_WorkDir(n))\n \t\t\twalk.addTree(new FileTreeIterator(new File(n)));\n \t\telse\n \t\t\twalk.addTree(resolve(n));\n \n+\t\tif (argi == args.length - 1) {\n+\t\t\tTreeFilter filter = WildCardTreeFilter.create(args[argi++]);\n+\t\t\twalk.setFilter(filter);\n+\t\t}\n+\t\tif (argi + 1 == args.length)\n+\t\t\tthrow die(\"usage: [-r] treename [pattern]\");\n+\t\telse if (argi + 1 < args.length)\n+\t\t\tthrow die(\"too many arguments\");\n+\n \t\twhile (walk.next()) {\n \t\t\tfinal FileMode mode = walk.getFileMode(0);\n \t\t\tif (mode == FileMode.TREE)\ndiff --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\nindex dc3faf9..645d52d 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java\n@@ -74,7 +74,7 @@ public class WildCardTreeFilter extends TreeFilter {\n \tpublic boolean include(TreeWalk walker) throws MissingObjectException,\n \t\t\tIncorrectObjectTypeException, IOException {\n \t\tmatcher.reset();\n-\t\tmatcher.append(walker.getPathString());\n+\t\tmatcher.append(walker.getName());\n \t\tif (matcher.isMatch())\n \t\t\treturn true;\n \t\treturn false;\n-- \n1.5.5.1.178.g1f811\n"},{"id":"81007","messageId":"1214343392-5341-1-git-send-email-robin.rosenberg@dewire.com","threadId":"14129","inReplyTo":"20080622233525.GJ11793@spearce.org","subject":"oops, resend","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-24T21:36:28Z","receivedAt":"2008-06-24T21:36:28Z","isPatch":false,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"I f*d the first series. 1 2 3 testing.. :(\n\n-- robin\n"},{"id":"81006","messageId":"1214343392-5341-2-git-send-email-robin.rosenberg@dewire.com","threadId":"14129","inReplyTo":"1214343392-5341-1-git-send-email-robin.rosenberg@dewire.com","subject":"[JGIT PATCH 1/4] LsTree: Do not use the default first empty tree in the walker","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-24T21:36:29Z","receivedAt":"2008-06-24T21:36:29Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"In f0ef5e1ef09d346432fead17bc82d78b7cfbd621 an empty tree\nwas added to all TreeWalkers.\n\nSigned-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n .../src/org/spearce/jgit/pgm/LsTree.java           |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java b/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java\nindex 1bc7bbd..05ec8c3 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java\n@@ -65,6 +65,7 @@ class LsTree extends TextBuiltin {\n \t\telse if (argi + 1 < args.length)\n \t\t\tthrow die(\"too many arguments\");\n \n+\t\twalk.reset(); // drop the first empty tree, which we do not need here\n \t\tfinal String n = args[argi];\n \t\tif (is_WorkDir(n))\n \t\t\twalk.addTree(new FileTreeIterator(new File(n)));\n-- \n1.5.5.1.178.g1f811\n"},{"id":"81008","messageId":"1214343392-5341-3-git-send-email-robin.rosenberg@dewire.com","threadId":"14129","inReplyTo":"1214343392-5341-2-git-send-email-robin.rosenberg@dewire.com","subject":"[JGIT PATCH 2/4] Create a fnmatch-style pattern TreeFilter","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-24T21:36:30Z","receivedAt":"2008-06-24T21:36:30Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"This uses Florian's pattern matcher to perform the matching.\n\nSigned-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n .../jgit/treewalk/filter/WildCardTreeFilter.java   |  103 ++++++++++++++++++++\n 1 files changed, 103 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java\n\ndiff --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\nnew file mode 100644\nindex 0000000..ce6da5e\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java\n@@ -0,0 +1,103 @@\n+/*\n+ * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.treewalk.filter;\n+\n+import java.io.IOException;\n+\n+import org.spearce.jgit.errors.IncorrectObjectTypeException;\n+import org.spearce.jgit.errors.InvalidPatternException;\n+import org.spearce.jgit.errors.MissingObjectException;\n+import org.spearce.jgit.fnmatch.FileNameMatcher;\n+import org.spearce.jgit.treewalk.TreeWalk;\n+import org.spearce.jgit.treewalk.filter.TreeFilter;\n+\n+/**\n+ * This class implements a TreeeFilter that uses the wildcard style pattern\n+ * matching like of Posix fnmatch function.\n+ */\n+public class WildCardTreeFilter extends TreeFilter {\n+\n+\tprivate final FileNameMatcher matcher;\n+\n+\tprivate final String pattern;\n+\n+\tprotected WildCardTreeFilter(final String pattern) {\n+\t\ttry {\n+\t\t\tthis.pattern = pattern;\n+\t\t\tmatcher = new FileNameMatcher(pattern, null);\n+\t\t} catch (InvalidPatternException e) {\n+\t\t\tthrow new IllegalArgumentException(e);\n+\t\t}\n+\t}\n+\n+\t@Override\n+\tpublic TreeFilter clone() {\n+\t\treturn new WildCardTreeFilter(pattern);\n+\t}\n+\n+\t@Override\n+\tpublic boolean include(TreeWalk walker) throws MissingObjectException,\n+\t\t\tIncorrectObjectTypeException, IOException {\n+\t\tif (walker.isRecursive() && walker.isSubtree())\n+\t\t\treturn true;\n+\t\tmatcher.reset();\n+\t\tmatcher.append(walker.getPathString());\n+\t\tif (matcher.isMatch())\n+\t\t\treturn true;\n+\t\treturn false;\n+\t}\n+\n+\t@Override\n+\tpublic boolean shouldBeRecursive() {\n+\t\treturn true;\n+\t}\n+\n+\t/**\n+\t * Construct a WildCardmatcher like POSIX fnmatch.\n+\t *\n+\t * @param pattern\n+\t *            A POSIX wildcard pattern\n+\t * @return a {@link TreeFilter} that matches pattern\n+\t * @throws IllegalArgumentException\n+\t *             if the pattern is malformed\n+\t */\n+\tpublic static TreeFilter create(final String pattern) {\n+\t\treturn new WildCardTreeFilter(pattern);\n+\t}\n+\n+}\n-- \n1.5.5.1.178.g1f811\n"},{"id":"81009","messageId":"1214343392-5341-4-git-send-email-robin.rosenberg@dewire.com","threadId":"14129","inReplyTo":"1214343392-5341-3-git-send-email-robin.rosenberg@dewire.com","subject":"[JGIT PATCH 3/4] Added a method to get the non-relative name from the tree walker","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-24T21:36:31Z","receivedAt":"2008-06-24T21:36:31Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n .../src/org/spearce/jgit/treewalk/TreeWalk.java    |   21 ++++++++++++++++++++\n 1 files changed, 21 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\nindex 42f8b25..a5eb4d9 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\n@@ -499,6 +499,17 @@ public class TreeWalk {\n \t}\n \n \t/**\n+\t * Get the current entry's name.\n+\t * <p>\n+\t *\n+\t * @return name of the current entry only.\n+\t * @see #getPathString()\n+\t */\n+\tpublic String getName() {\n+\t\treturn nameOf(currentHead);\n+\t}\n+\n+\t/**\n \t * Test if the supplied path matches the current entry's path.\n \t * <p>\n \t * This method tests that the supplied path is exactly equal to the current\n@@ -659,4 +670,14 @@ public class TreeWalk {\n \t\t\t\t\t+ Constants.CHARACTER_ENCODING, uee);\n \t\t}\n \t}\n+\n+\tprivate static String nameOf(final AbstractTreeIterator t) {\n+\t\ttry {\n+\t\t\treturn new String(t.path, t.pathOffset, t.pathLen - t.pathOffset,\n+\t\t\t\t\tConstants.CHARACTER_ENCODING);\n+\t\t} catch (UnsupportedEncodingException uee) {\n+\t\t\tthrow new RuntimeException(\"JVM doesn't support \"\n+\t\t\t\t\t+ Constants.CHARACTER_ENCODING, uee);\n+\t\t}\n+\t}\n }\n-- \n1.5.5.1.178.g1f811\n"},{"id":"81010","messageId":"1214343392-5341-5-git-send-email-robin.rosenberg@dewire.com","threadId":"14129","inReplyTo":"1214343392-5341-4-git-send-email-robin.rosenberg@dewire.com","subject":"[JGIT PATCH 4/4] LsTree: Enable pattern matching in LsTree","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-06-24T21:36:32Z","receivedAt":"2008-06-24T21:36:32Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n .../src/org/spearce/jgit/pgm/LsTree.java           |   19 +++++++++++++------\n .../jgit/treewalk/filter/WildCardTreeFilter.java   |    2 +-\n 2 files changed, 14 insertions(+), 7 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java b/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java\nindex 05ec8c3..6bb4192 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/pgm/LsTree.java\n@@ -43,8 +43,11 @@ import org.spearce.jgit.lib.Constants;\n import org.spearce.jgit.lib.FileMode;\n import org.spearce.jgit.treewalk.FileTreeIterator;\n import org.spearce.jgit.treewalk.TreeWalk;\n+import org.spearce.jgit.treewalk.filter.TreeFilter;\n+import org.spearce.jgit.treewalk.filter.WildCardTreeFilter;\n \n class LsTree extends TextBuiltin {\n+\n \t@Override\n \tvoid execute(final String[] args) throws Exception {\n \t\tfinal TreeWalk walk = new TreeWalk(db);\n@@ -60,18 +63,22 @@ class LsTree extends TextBuiltin {\n \t\t\t\tbreak;\n \t\t}\n \n-\t\tif (argi == args.length)\n-\t\t\tthrow die(\"usage: [-r] treename\");\n-\t\telse if (argi + 1 < args.length)\n-\t\t\tthrow die(\"too many arguments\");\n-\n \t\twalk.reset(); // drop the first empty tree, which we do not need here\n-\t\tfinal String n = args[argi];\n+\t\tfinal String n = args[argi++];\n \t\tif (is_WorkDir(n))\n \t\t\twalk.addTree(new FileTreeIterator(new File(n)));\n \t\telse\n \t\t\twalk.addTree(resolve(n));\n \n+\t\tif (argi == args.length - 1) {\n+\t\t\tTreeFilter filter = WildCardTreeFilter.create(args[argi++]);\n+\t\t\twalk.setFilter(filter);\n+\t\t}\n+\t\tif (argi + 1 == args.length)\n+\t\t\tthrow die(\"usage: [-r] treename [pattern]\");\n+\t\telse if (argi + 1 < args.length)\n+\t\t\tthrow die(\"too many arguments\");\n+\n \t\twhile (walk.next()) {\n \t\t\tfinal FileMode mode = walk.getFileMode(0);\n \t\t\tif (mode == FileMode.TREE)\ndiff --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\nindex ce6da5e..8b22e25 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java\n@@ -76,7 +76,7 @@ public class WildCardTreeFilter extends TreeFilter {\n \t\tif (walker.isRecursive() && walker.isSubtree())\n \t\t\treturn true;\n \t\tmatcher.reset();\n-\t\tmatcher.append(walker.getPathString());\n+\t\tmatcher.append(walker.getName());\n \t\tif (matcher.isMatch())\n \t\t\treturn true;\n \t\treturn false;\n-- \n1.5.5.1.178.g1f811\n"},{"id":"81053","messageId":"20080625040931.GA11793@spearce.org","threadId":"14129","inReplyTo":"1214343392-5341-5-git-send-email-robin.rosenberg@dewire.com","subject":"Re: [JGIT PATCH 4/4] LsTree: Enable pattern matching in LsTree","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-06-25T04:09:31Z","receivedAt":"2008-06-25T04:09:31Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Robin Rosenberg <robin.rosenberg@dewire.com> wrote:\n> 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\n> index ce6da5e..8b22e25 100644\n> --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java\n> +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/filter/WildCardTreeFilter.java\n> @@ -76,7 +76,7 @@ public class WildCardTreeFilter extends TreeFilter {\n>  \t\tif (walker.isRecursive() && walker.isSubtree())\n>  \t\t\treturn true;\n>  \t\tmatcher.reset();\n> -\t\tmatcher.append(walker.getPathString());\n> +\t\tmatcher.append(walker.getName());\n>  \t\tif (matcher.isMatch())\n>  \t\t\treturn true;\n>  \t\treturn false;\n\nAre we only supporting `jgit ls-tree . '*.c'` ?\nOr do we want to allow `jgit ls-tree . 'src/*.c'`?\n\nls-tree is only a little sample program that is not likely to have\na lot of real-world users calling it; but is a good demonstration\nof how to use TreeWalk.  So I really don't care either way.\n\nThe WildCardTreeFilter on the other hand could be applied to a\nRevWalk, such as to grab history for not just 'foo.c' but anything\nthat matches 'f*.c'.  But then you have to ask, why is the filter\nlimited to testing only the last component of the path?  Why can't\nit test 'src/f*.c'?\n\nOtherwise everything in your series up until here makes sense and\nlooks good to me.  Be nice if the tree filter wasn't so abusive in\nneeding to look at every path in the project, as that would really\nhurt if it was applied to a RevWalk.  But its not required to be\nfast, if you ask for fnmatch paths, you get what you asked for...\n\n-- \nShawn.\n"}]}