Add a new option to "stg applied" and "stg unapplied" that provides a count
authorChuck Lever <chuck.lever@oracle.com>
Wed, 8 Nov 2006 22:30:03 +0000 (22:30 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Wed, 8 Nov 2006 22:30:03 +0000 (22:30 +0000)
of patches rather than a list.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
stgit/commands/applied.py
stgit/commands/series.py
stgit/commands/unapplied.py

index d568cd6..f131d62 100644 (file)
@@ -32,7 +32,10 @@ stack.  They are listed in the order in which they were pushed, the
 last one being the current (topmost) patch."""
 
 options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one')]
+                       help = 'use BRANCH instead of the default one'),
+           make_option('-c', '--count',
+                       help = 'print the number of applied patches',
+                       action = 'store_true')]
 
 
 def func(parser, options, args):
@@ -41,5 +44,10 @@ def func(parser, options, args):
     if len(args) != 0:
         parser.error('incorrect number of arguments')
 
-    for p in crt_series.get_applied():
-        print p
+    applied = crt_series.get_applied()
+
+    if options.count:
+        print len(applied)
+    else:
+        for p in applied:
+            print p
index e66f1bd..105eeb9 100644 (file)
@@ -33,6 +33,9 @@ prefixed with a '>'. Empty patches are prefixed with a '0'."""
 
 options = [make_option('-b', '--branch',
                        help = 'use BRANCH instead of the default one'),
+           make_option('-c', '--count',
+                       help = 'print the number of patches in the series',
+                       action = 'store_true'),
            make_option('-d', '--description',
                        help = 'show a short description for each patch',
                        action = 'store_true'),
@@ -73,6 +76,10 @@ def func(parser, options, args):
     applied = crt_series.get_applied()
     unapplied = crt_series.get_unapplied()
 
+    if options.count:
+        print len(applied) + len(unapplied)
+        return
+
     if options.short:
         if len(applied) > 5:
             applied = applied[-6:]
index 4a14456..cbac052 100644 (file)
@@ -31,7 +31,10 @@ List the patches from the series which are not pushed onto the stack.
 They are listed in the reverse order in which they were popped."""
 
 options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one')]
+                       help = 'use BRANCH instead of the default one'),
+           make_option('-c', '--count',
+                       help = 'print the number of unapplied patches',
+                       action = 'store_true')]
 
 
 def func(parser, options, args):
@@ -40,5 +43,10 @@ def func(parser, options, args):
     if len(args) != 0:
         parser.error('incorrect number of arguments')
 
-    for p in crt_series.get_unapplied():
-        print p
+    unapplied = crt_series.get_unapplied()
+
+    if options.count:
+        print len(unapplied)
+    else:
+        for p in unapplied:
+            print p