Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx> --- .../src/org/spearce/jgit/pgm/LsTree.java | 42 ++++++-------------- 1 files changed, 12 insertions(+), 30 deletions(-) diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsTree.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsTree.java index a0a7216..8d4937f 100644 --- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsTree.java +++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsTree.java @@ -37,40 +37,26 @@ package org.spearce.jgit.pgm; -import java.io.File; - +import org.kohsuke.args4j.Argument; +import org.kohsuke.args4j.Option; import org.spearce.jgit.lib.Constants; import org.spearce.jgit.lib.FileMode; -import org.spearce.jgit.treewalk.FileTreeIterator; +import org.spearce.jgit.treewalk.AbstractTreeIterator; import org.spearce.jgit.treewalk.TreeWalk; class LsTree extends TextBuiltin { - @Override - public void execute(final String[] args) throws Exception { - final TreeWalk walk = new TreeWalk(db); - int argi = 0; - for (; argi < args.length; argi++) { - final String a = args[argi]; - if ("--".equals(a)) { - argi++; - break; - } else if ("-r".equals(a)) - walk.setRecursive(true); - else - break; - } + @Option(name = "--recursive", usage = "recurse into subtrees", aliases = { "-r" }) + private boolean recursive; - if (argi == args.length) - throw die("usage: [-r] treename"); - else if (argi + 1 < args.length) - throw die("too many arguments"); + @Argument(index = 0, required = true, metaVar = "tree-ish") + private AbstractTreeIterator tree; + @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 - final String n = args[argi]; - if (is_WorkDir(n)) - walk.addTree(new FileTreeIterator(new File(n))); - else - walk.addTree(resolve(n)); + walk.setRecursive(recursive); + walk.addTree(tree); while (walk.next()) { final FileMode mode = walk.getFileMode(0); @@ -88,8 +74,4 @@ class LsTree extends TextBuiltin { out.println(); } } - - private boolean is_WorkDir(final String name) { - return new File(name).isDirectory(); - } } -- 1.5.6.3.569.ga9185 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html