]> source.dussan.org Git - jgit.git/commitdiff
Have git-ls tree to accept path args like git-ls-tree 34/1334/4
authorKetan Padegaonkar <KetanPadegaonkar@gmail.com>
Sat, 31 Mar 2012 16:46:22 +0000 (18:46 +0200)
committerChris Aniszczyk <zx@twitter.com>
Mon, 19 Nov 2012 00:36:13 +0000 (18:36 -0600)
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>
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java

index 16480d9dbfceeee8a3b80dd148b6ef8c1ec61871..4fb560b198d3d53158f3a4bb7e8d488bcc0952dd 100644 (file)
 
 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);