From 614a477b079412d05762808b7ab0d014cf05e80f Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Mon, 5 May 2014 12:42:23 -0700 Subject: [PATCH] RevWalkTextBuiltin: Add -n to limit number of commits returned Implementing the -<#> flag from C git is less trivial. Change-Id: Idb55a303304a6d4055aaf37d0b4dcf92c684e25f --- .../src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java index e23fb356a..94156aa7e 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java @@ -146,6 +146,9 @@ abstract class RevWalkTextBuiltin extends TextBuiltin { revLimiter.add(MessageRevFilter.create(msg)); } + @Option(name = "--max-count", aliases = "-n", metaVar = "metaVar_n") + private int maxCount = -1; + @Override protected void run() throws Exception { walk = createWalk(); @@ -218,7 +221,8 @@ abstract class RevWalkTextBuiltin extends TextBuiltin { protected int walkLoop() throws Exception { int n = 0; for (final RevCommit c : walk) { - n++; + if (++n > maxCount && maxCount >= 0) + break; show(c); } if (walk instanceof ObjectWalk) {