chiark / gitweb /
Make diff flags handling more modular.
authorYann Dirson <ydirson@altern.org>
Thu, 31 May 2007 22:34:33 +0000 (00:34 +0200)
committerCatalin Marinas <catalin.marinas@gmail.com>
Sat, 2 Jun 2007 22:43:03 +0000 (23:43 +0100)
Signed-off-by: Yann Dirson <ydirson@altern.org>
stgit/commands/diff.py
stgit/commands/export.py
stgit/commands/mail.py
stgit/git.py

index f56cbebac8c32a03de8421f9a1e1180c5f06fb45..b66c75bb9c7a53a691cf336055d7be057163bede 100644 (file)
@@ -79,10 +79,15 @@ def func(parser, options, args):
         rev1 = 'HEAD'
         rev2 = None
 
+    if options.binary:
+        diff_flags = [ '--binary' ]
+    else:
+        diff_flags = []
+
     if options.stat:
         out.stdout_raw(git.diffstat(args, git_id(rev1), git_id(rev2)) + '\n')
     else:
         diff_str = git.diff(args, git_id(rev1), git_id(rev2),
-                            binary = options.binary)
+                            diff_flags = diff_flags )
         if diff_str:
             pager(diff_str)
index cafcbe3076d2947ca0d1499945980c09d0d301db..d6b36a959b09c87c7db3db763347b450d2d3d44e 100644 (file)
@@ -87,6 +87,11 @@ def func(parser, options, args):
             os.makedirs(dirname)
         series = file(os.path.join(dirname, 'series'), 'w+')
 
+    if options.binary:
+        diff_flags = [ '--binary' ]
+    else:
+        diff_flags = []
+
     applied = crt_series.get_applied()
     if len(args) != 0:
         patches = parse_patches(args, applied)
@@ -175,7 +180,8 @@ def func(parser, options, args):
         # write the diff
         git.diff(rev1 = patch.get_bottom(),
                  rev2 = patch.get_top(),
-                 out_fd = f, binary = options.binary)
+                 out_fd = f,
+                 diff_flags = diff_flags )
         if not options.stdout:
             f.close()
         patch_no += 1
index b95014c16ae48b796cd00268876335e23a91992d..7113cff796cd3a8f9328040253ac89a4813436b2 100644 (file)
@@ -377,6 +377,11 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options):
     else:
         prefix_str = ''
         
+    if options.binary:
+        diff_flags = [ '--binary' ]
+    else:
+        diff_flags = []
+
     total_nr_str = str(total_nr)
     patch_nr_str = str(patch_nr).zfill(len(total_nr_str))
     if total_nr > 1:
@@ -394,7 +399,7 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options):
                  'endofheaders': '',
                  'diff':         git.diff(rev1 = git_id('%s//bottom' % patch),
                                           rev2 = git_id('%s//top' % patch),
-                                          binary = options.binary),
+                                          diff_flags = diff_flags ),
                  'diffstat':     git.diffstat(rev1 = git_id('%s//bottom'%patch),
                                               rev2 = git_id('%s//top' % patch)),
                  # for backward template compatibility
index 5cdc8cdf0aa6d1ab2664776a09c86269f8f8af69..7358fae6ef31d11f3f5f912e142b0488b988f21c 100644 (file)
@@ -770,27 +770,23 @@ def status(files = None, modified = False, new = False, deleted = False,
             out.stdout('%s' % fs[1])
 
 def diff(files = None, rev1 = 'HEAD', rev2 = None, out_fd = None,
-         binary = False):
+         diff_flags = []):
     """Show the diff between rev1 and rev2
     """
     if not files:
         files = []
 
-    args = []
-    if binary:
-        args.append('--binary')
-
     if rev1 and rev2:
-        diff_str = _output(['git-diff-tree', '-p'] + args
+        diff_str = _output(['git-diff-tree', '-p'] + diff_flags
                            + [rev1, rev2, '--'] + files)
     elif rev1 or rev2:
         refresh_index()
         if rev2:
             diff_str = _output(['git-diff-index', '-p', '-R']
-                               + args + [rev2, '--'] + files)
+                               + diff_flags + [rev2, '--'] + files)
         else:
             diff_str = _output(['git-diff-index', '-p']
-                               + args + [rev1, '--'] + files)
+                               + diff_flags + [rev1, '--'] + files)
     else:
         diff_str = ''