git.pretty_commit() re-implemented with "git show" (bug #10018)
[stgit] / stgit / commands / show.py
index 2b22744..e6814d3 100644 (file)
@@ -30,6 +30,7 @@ Show the commit log and the diff corresponding to the given
 patches. The output is similar to that generated by the 'git show'
 command."""
 
 patches. The output is similar to that generated by the 'git show'
 command."""
 
+directory = DirectoryHasRepository()
 options = [make_option('-b', '--branch',
                        help = 'use BRANCH instead of the default one'),
            make_option('-a', '--applied',
 options = [make_option('-b', '--branch',
                        help = 'use BRANCH instead of the default one'),
            make_option('-a', '--applied',
@@ -38,8 +39,8 @@ options = [make_option('-b', '--branch',
            make_option('-u', '--unapplied',
                        help = 'show the unapplied patches',
                        action = 'store_true'),
            make_option('-u', '--unapplied',
                        help = 'show the unapplied patches',
                        action = 'store_true'),
-           make_option('-O', '--diff-opts',
-                       help = 'options to pass to git-diff')]
+           make_option('-O', '--show-opts',
+                       help = 'options to pass to "git show"')]
 
 
 def func(parser, options, args):
 
 
 def func(parser, options, args):
@@ -55,16 +56,21 @@ def func(parser, options, args):
     elif len(args) == 0:
         patches = ['HEAD']
     else:
     elif len(args) == 0:
         patches = ['HEAD']
     else:
-        patches = parse_patches(args, applied + unapplied +\
+        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, applied + unapplied +\
                                 crt_series.get_hidden(), len(applied))
 
                                 crt_series.get_hidden(), len(applied))
 
-    if options.diff_opts:
-        diff_flags = options.diff_opts.split()
+    if options.show_opts:
+        show_flags = options.show_opts.split()
     else:
     else:
-        diff_flags = []
+        show_flags = []
 
 
-    commit_ids = [git_id(patch) for patch in patches]
-    commit_str = '\n'.join([git.pretty_commit(commit_id, diff_flags=diff_flags)
+    commit_ids = [git_id(crt_series, patch) for patch in patches]
+    commit_str = '\n'.join([git.pretty_commit(commit_id, flags = show_flags)
                             for commit_id in commit_ids])
     if commit_str:
         pager(commit_str)
                             for commit_id in commit_ids])
     if commit_str:
         pager(commit_str)