git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGIT PATCH 5/5] Add --binary flag to commands that generate diffs
Date: Sat, 19 May 2007 02:10:12 +0200	[thread overview]
Message-ID: <20070519001012.4906.86287.stgit@yoghurt> (raw)
In-Reply-To: <20070519000451.4906.87089.stgit@yoghurt>

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   |    6 +++++-
 stgit/commands/export.py |    5 ++++-
 stgit/commands/mail.py   |    6 +++++-
 stgit/git.py             |   16 ++++++++++++----
 4 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/stgit/commands/diff.py b/stgit/commands/diff.py
index 8678a0a..d3e1190 100644
--- a/stgit/commands/diff.py
+++ b/stgit/commands/diff.py
@@ -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)
diff --git a/stgit/commands/export.py b/stgit/commands/export.py
index 79b8630..20d8f67 100644
--- a/stgit/commands/export.py
+++ b/stgit/commands/export.py
@@ -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
diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index 151a408..2fcaa5f 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -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
diff --git a/stgit/git.py b/stgit/git.py
index 837f927..86630ce 100644
--- a/stgit/git.py
+++ b/stgit/git.py
@@ -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 = ''
 

  parent reply	other threads:[~2007-05-19  0:10 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-06 15:13 [StGIT PATCH] Don't use patches/<branch>/current Karl Hasselström
2007-05-15 15:56 ` Catalin Marinas
2007-05-15 16:21   ` Peter Oberndorfer
2007-05-15 16:50     ` Catalin Marinas
2007-05-15 18:25   ` Karl Hasselström
2007-05-15 19:38     ` [StGIT PATCH] Remove obsolete files when deleting a branch Karl Hasselström
2007-05-15 20:01     ` [StGIT PATCH] Don't use patches/<branch>/current Catalin Marinas
2007-05-16  7:11       ` Karl Hasselström
2007-05-16 12:07         ` Catalin Marinas
2007-05-16 19:40           ` Karl Hasselström
2007-05-16 20:40             ` Karl Hasselström
2007-05-17 12:43               ` Catalin Marinas
2007-05-17 14:57                 ` Karl Hasselström
2007-05-17 20:51                   ` Catalin Marinas
2007-05-18  6:30                     ` Karl Hasselström
2007-06-10  9:54                       ` [StGIT PATCH 0/6] New and improved DAG appliedness series Karl Hasselström
2007-06-10  9:54                         ` [StGIT PATCH 1/6] Verify patch status during the test Karl Hasselström
2007-06-10  9:55                         ` [StGIT PATCH 2/6] Make use of the get_patch() utility function Karl Hasselström
2007-06-10  9:55                         ` [StGIT PATCH 3/6] Compute patch appliedness from commit DAG Karl Hasselström
2007-06-10  9:55                         ` [StGIT PATCH 4/6] Test the new DAG appliedness machinery Karl Hasselström
2007-06-10  9:55                         ` [StGIT PATCH 5/6] Fix bash completion after the DAG appliedness patch Karl Hasselström
2007-06-10  9:55                         ` [StGIT PATCH 6/6] Speed up the appliedness test Karl Hasselström
2007-06-30 19:54                         ` [StGIT PATCH 0/6] New and improved DAG appliedness series Yann Dirson
2007-07-01 14:35                           ` Karl Hasselström
2007-05-15 21:08   ` [StGIT PATCH] Don't use patches/<branch>/current Yann Dirson
2007-05-15 21:36     ` Catalin Marinas
2007-05-15 21:49       ` Yann Dirson
2007-05-16  6:27         ` Karl Hasselström
2007-05-19  0:09           ` [StGIT PATCH 0/5] Metadata format versioning Karl Hasselström
2007-05-19  0:09             ` [StGIT PATCH 1/5] Fix config caching so that get, set, get works Karl Hasselström
2007-05-19  0:09             ` [StGIT PATCH 2/5] Have only a single command in each test_expect_failure Karl Hasselström
2007-05-19  0:10             ` [StGIT PATCH 3/5] Upgrade old StGIT branches to new-format metadata Karl Hasselström
2007-05-19  0:10             ` [StGIT PATCH 4/5] Test the format version upgrade code Karl Hasselström
2007-05-19  0:10             ` Karl Hasselström [this message]
2007-05-22 12:15               ` [StGIT PATCH 5/5] Add --binary flag to commands that generate diffs Catalin Marinas
2007-05-22 13:31                 ` Karl Hasselström
2007-05-20 20:03 ` [StGit PATCH 0/2] Bash prompt updates Robin Rosenberg
2007-05-20 20:04   ` [StGit PATCH 1/2] Update the bash prompt from 'applied' instead of the obsolete 'current' Robin Rosenberg
2007-05-20 20:46     ` Yann Dirson
2007-05-20 21:22       ` [PATCH " Robin Rosenberg
2007-05-21  7:48         ` Karl Hasselström
2007-05-21  9:31           ` Catalin Marinas
2007-05-21 10:15             ` Karl Hasselström
2007-05-21 11:39               ` Karl Hasselström
2007-05-21 15:17                 ` Catalin Marinas
2007-05-21 15:39                   ` Karl Hasselström
2007-05-22 12:11                     ` Catalin Marinas
2007-05-22 13:29                       ` Karl Hasselström
2007-05-21 18:57             ` Yann Dirson
2007-05-20 21:24       ` [PATCH 2/2] Don't use / as separatar since it is common i branch names Robin Rosenberg
2007-05-20 20:04   ` [StGit PATCH " Robin Rosenberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070519001012.4906.86287.stgit@yoghurt \
    --to=kha@treskal.com \
    --cc=catalin.marinas@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).