git.pretty_commit() re-implemented with "git show" (bug #10018)
[stgit] / stgit / commands / diff.py
index 8678a0a..1425518 100644 (file)
@@ -22,11 +22,12 @@ from pydoc import pager
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
 help = 'show the tree diff'
-usage = """%prog [options] [<files...>]
+usage = """%prog [options] [<files or dirs>]
 
 Show the diff (default) or diffstat between the current working copy
 or a tree-ish object and another tree-ish object. File names can also
@@ -41,9 +42,12 @@ rev = '([patch][//[bottom | top]]) | <tree-ish> | base'
 If neither bottom nor top are given but a '//' is present, the command
 shows the specified patch (defaulting to the current one)."""
 
+directory = DirectoryHasRepository()
 options = [make_option('-r', '--range',
                        metavar = 'rev1[..[rev2]]', dest = 'revs',
                        help = 'show the diff between revisions'),
+           make_option('-O', '--diff-opts',
+                       help = 'options to pass to git-diff'),
            make_option('-s', '--stat',
                        help = 'show the stat instead of the diff',
                        action = 'store_true')]
@@ -52,6 +56,9 @@ options = [make_option('-r', '--range',
 def func(parser, options, args):
     """Show the tree diff
     """
+    args = git.ls_files(args)
+    directory.cd_to_topdir()
+
     if options.revs:
         rev_list = options.revs.split('..')
         rev_list_len = len(rev_list)
@@ -76,9 +83,16 @@ def func(parser, options, args):
         rev1 = 'HEAD'
         rev2 = None
 
+    if options.diff_opts:
+        diff_flags = options.diff_opts.split()
+    else:
+        diff_flags = []
+
     if options.stat:
-        print git.diffstat(args, git_id(rev1), git_id(rev2))
+        out.stdout_raw(git.diffstat(args, git_id(crt_series, rev1),
+                                    git_id(crt_series, rev2)) + '\n')
     else:
-        diff_str = git.diff(args, git_id(rev1), git_id(rev2))
+        diff_str = git.diff(args, git_id(crt_series, rev1),
+                            git_id(crt_series, rev2), diff_flags = diff_flags )
         if diff_str:
             pager(diff_str)