Allow 'show' to display many patches
authorCatalin Marinas <catalin.marinas@gmail.com>
Wed, 22 Nov 2006 20:14:57 +0000 (20:14 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Wed, 22 Nov 2006 20:14:57 +0000 (20:14 +0000)
The show command should be allowed to display more than one patch.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/commands/show.py

index a3169b9..5c297c0 100644 (file)
@@ -24,25 +24,40 @@ from stgit import git
 
 
 help = 'show the commit corresponding to a patch (or the current patch)'
 
 
 help = 'show the commit corresponding to a patch (or the current patch)'
-usage = """%prog [options] [<patch>]
+usage = """%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>]
 
 
-Show the commit log and the diff corresponding to a given patch. The
-output is similar to that generated by the 'git show' command."""
+Show the commit log and the diff corresponding to the given
+patches. The output is similar to that generated by the 'git show'
+command."""
 
 
-options = []
+options = [make_option('-a', '--applied',
+                       help = 'show the applied patches',
+                       action = 'store_true'),
+           make_option('-u', '--unapplied',
+                       help = 'show the unapplied patches',
+                       action = 'store_true')]
 
 
 def func(parser, options, args):
     """Show commit log and diff
     """
 
 
 def func(parser, options, args):
     """Show commit log and diff
     """
-    if len(args) == 0:
-        patch = 'HEAD'
-    elif len(args) == 1:
-        patch = args[0]
+    if options.applied:
+        patches = crt_series.get_applied()
+    elif options.unapplied:
+        patches = crt_series.get_unapplied()
+    elif len(args) == 0:
+        patches = ['HEAD']
     else:
     else:
-        parser.error('incorrect number of arguments')
-
-    commit_id = git_id(patch)
-    commit_str = git.pretty_commit(commit_id)
+        if len(args) == 1 and args[0].find('..') == -1 \
+               and not crt_series.patch_exists(args[0]):
+            # it might be just a commit id
+            patches = args
+        else:
+            patches = parse_patches(args, crt_series.get_applied()
+                                    + crt_series.get_unapplied())
+
+    commit_ids = [git_id(patch) for patch in patches]
+    commit_str = '\n'.join([git.pretty_commit(commit_id)
+                            for commit_id in commit_ids])
     if commit_str:
         pager(commit_str)
     if commit_str:
         pager(commit_str)