]> source.dussan.org Git - jgit.git/commitdiff
RevWalkTextBuiltin: Add -n to limit number of commits returned 98/25998/2
authorDave Borowitz <dborowitz@google.com>
Mon, 5 May 2014 19:42:23 +0000 (12:42 -0700)
committerDave Borowitz <dborowitz@google.com>
Mon, 5 May 2014 22:58:33 +0000 (15:58 -0700)
Implementing the -<#> flag from C git is less trivial.

Change-Id: Idb55a303304a6d4055aaf37d0b4dcf92c684e25f

org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java

index e23fb356af4d8857beb0cc1ec443d5a1d50de2da..94156aa7e489b683ff7dfc56f0479f9b81b7dda8 100644 (file)
@@ -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) {