chiark / gitweb /
Add --binary flag to commands that generate diffs
authorKarl Hasselström <kha@treskal.com>
Mon, 21 May 2007 20:58:38 +0000 (21:58 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Mon, 21 May 2007 20:59:29 +0000 (21:59 +0100)
This just passes the --binary option to git-diff-*, which causes the
generated diffs to contain an applyable diff even when binary files
differ. It's necessary to do this if you want to mail patches to
binary files.

Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/diff.py
stgit/commands/export.py
stgit/commands/mail.py
stgit/git.py

index 8678a0a236f3cc5488a1acf928888f9947901c3a..d3e119084759110da6aa06586567cd9cba84975a 100644 (file)
@@ -44,6 +44,9 @@ shows the specified patch (defaulting to the current one)."""
 options = [make_option('-r', '--range',
                        metavar = 'rev1[..[rev2]]', dest = 'revs',
                        help = 'show the diff between revisions'),
+           make_option('--binary',
+                       help = 'output a diff even for binary files',
+                       action = 'store_true'),
            make_option('-s', '--stat',
                        help = 'show the stat instead of the diff',
                        action = 'store_true')]
@@ -79,6 +82,7 @@ def func(parser, options, args):
     if options.stat:
         print git.diffstat(args, git_id(rev1), git_id(rev2))
     else:
-        diff_str = git.diff(args, git_id(rev1), git_id(rev2))
+        diff_str = git.diff(args, git_id(rev1), git_id(rev2),
+                            binary = options.binary)
         if diff_str:
             pager(diff_str)
index 79b8630dd6cdcb83fa2ad068a79257c230e494b1..20d8f67a6be453f9656ff0da9a2ea4c21944227b 100644 (file)
@@ -62,6 +62,9 @@ options = [make_option('-d', '--dir',
                        help = 'Use FILE as a template'),
            make_option('-b', '--branch',
                        help = 'use BRANCH instead of the default one'),
+           make_option('--binary',
+                       help = 'output a diff even for binary files',
+                       action = 'store_true'),
            make_option('-s', '--stdout',
                        help = 'dump the patches to the standard output',
                        action = 'store_true')]
@@ -172,7 +175,7 @@ def func(parser, options, args):
         # write the diff
         git.diff(rev1 = patch.get_bottom(),
                  rev2 = patch.get_top(),
-                 out_fd = f)
+                 out_fd = f, binary = options.binary)
         if not options.stdout:
             f.close()
         patch_no += 1
index 151a40804c67cc9aa1620d18e037f265819c491e..2fcaa5f629429f1c1c669682eafbd9056a7ecc12 100644 (file)
@@ -120,6 +120,9 @@ options = [make_option('-a', '--all',
                        help = 'username for SMTP authentication'),
            make_option('-b', '--branch',
                        help = 'use BRANCH instead of the default one'),
+           make_option('--binary',
+                       help = 'output a diff even for binary files',
+                       action = 'store_true'),
            make_option('-m', '--mbox',
                        help = 'generate an mbox file instead of sending',
                        action = 'store_true')]
@@ -390,7 +393,8 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options):
                  # for backward template compatibility
                  'endofheaders': '',
                  'diff':         git.diff(rev1 = git_id('%s//bottom' % patch),
-                                          rev2 = git_id('%s//top' % patch)),
+                                          rev2 = git_id('%s//top' % patch),
+                                          binary = options.binary),
                  'diffstat':     git.diffstat(rev1 = git_id('%s//bottom'%patch),
                                               rev2 = git_id('%s//top' % patch)),
                  # for backward template compatibility
index 837f927eedfe28ecef0dd679d6f88acdd9ea5adb..86630ce3900af65d130116aaa1532638de5d4cd7 100644 (file)
@@ -771,20 +771,28 @@ def status(files = None, modified = False, new = False, deleted = False,
         else:
             print '%s' % fs[1]
 
-def diff(files = None, rev1 = 'HEAD', rev2 = None, out_fd = None):
+def diff(files = None, rev1 = 'HEAD', rev2 = None, out_fd = None,
+         binary = False):
     """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', rev1, rev2, '--'] + files)
+        diff_str = _output(['git-diff-tree', '-p'] + args
+                           + [rev1, rev2, '--'] + files)
     elif rev1 or rev2:
         refresh_index()
         if rev2:
-            diff_str = _output(['git-diff-index', '-p', '-R', rev2, '--'] + files)
+            diff_str = _output(['git-diff-index', '-p', '-R']
+                               + args + [rev2, '--'] + files)
         else:
-            diff_str = _output(['git-diff-index', '-p', rev1, '--'] + files)
+            diff_str = _output(['git-diff-index', '-p']
+                               + args + [rev1, '--'] + files)
     else:
         diff_str = ''