Allow 'show' to display many patches
[stgit] / stgit / commands / show.py
index 50eb376..5c297c0 100644 (file)
@@ -17,29 +17,47 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 import sys, os
 from optparse import OptionParser, make_option
+from pydoc import pager
 
 from stgit.commands.common import *
 from stgit import git
 
 
 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
     """
-    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:
-        parser.error('incorrect number of arguments')
-
-    commit_id = git_id(patch)
-    sys.stdout.write(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)