From 360be05fd4347b044adef575029c43897b24ceff Mon Sep 17 00:00:00 2001 From: Ketan Padegaonkar Date: Sat, 31 Mar 2012 18:46:22 +0200 Subject: [PATCH] Have git-ls tree to accept path args like git-ls-tree Usage is: jgit ls-tree [-r|--recursive] [-- paths...] Change-Id: I2e1c9c3cc8cddfa12ca4bfb9afc4df0492a9fce1 Signed-off-by: Robin Rosenberg Signed-off-by: Chris Aniszczyk --- .../src/org/eclipse/jgit/pgm/LsTree.java | 16 ++++++++++++++-- 1 file 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 16480d9dbf..4fb560b198 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 paths = new ArrayList(); + @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); -- 2.39.5