aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKetan Padegaonkar2012-03-31 12:46:22 (EDT)
committerChris Aniszczyk2012-11-18 19:36:13 (EST)
commit360be05fd4347b044adef575029c43897b24ceff (patch)
treeec46edb71702886ccd03fff0a3e8488d3978508f
parent20c3b6b8a0ba4f3d9f5666dd48b132839ab7e5bf (diff)
downloadjgit-360be05fd4347b044adef575029c43897b24ceff.zip
jgit-360be05fd4347b044adef575029c43897b24ceff.tar.gz
jgit-360be05fd4347b044adef575029c43897b24ceff.tar.bz2
Have git-ls tree to accept path args like git-ls-treerefs/changes/34/1334/4
Usage is: jgit ls-tree [-r|--recursive] <tree-ish> [-- paths...] Change-Id: I2e1c9c3cc8cddfa12ca4bfb9afc4df0492a9fce1 Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com> Signed-off-by: Chris Aniszczyk <zx@twitter.com>
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java
index 16480d9..4fb560b 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java
@@ -45,12 +45,17 @@
package org.eclipse.jgit.pgm;
-import org.kohsuke.args4j.Argument;
-import org.kohsuke.args4j.Option;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
+import org.kohsuke.args4j.spi.StopOptionHandler;
class LsTree extends TextBuiltin {
@Option(name = "--recursive", usage = "usage_recurseIntoSubtrees", aliases = { "-r" })
@@ -59,9 +64,16 @@ class LsTree extends TextBuiltin {
@Argument(index = 0, required = true, metaVar = "metaVar_treeish")
private AbstractTreeIterator tree;
+ @Argument(index = 1)
+ @Option(name = "--", metaVar = "metaVar_paths", multiValued = true, handler = StopOptionHandler.class)
+ private List<String> paths = new ArrayList<String>();
+
@Override
protected void run() throws Exception {
final TreeWalk walk = new TreeWalk(db);
+ walk.reset(); // drop the first empty tree, which we do not need here
+ if (paths.size() > 0)
+ walk.setFilter(PathFilterGroup.createFromStrings(paths));
walk.setRecursive(recursive);
walk.addTree(tree);