git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/4] Make diff flags handling more modular.

From
Yann Dirson <ydirson@altern.org>
Date
May 31, 2007, 22:34 UTC
Message-ID
<20070531223433.6005.27608.stgit@gandelf.nowhere.earth>
In-Reply-To
<20070531222920.6005.74481.stgit@gandelf.nowhere.earth>
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
 stgit/commands/diff.py   |    7 ++++++-
 stgit/commands/export.py |    8 +++++++-
 stgit/commands/mail.py   |    7 ++++++-
 stgit/git.py             |   12 ++++--------
 4 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/stgit/commands/diff.py b/stgit/commands/diff.py
index f56cbeb..b66c75b 100644
--- a/stgit/commands/diff.py
+++ b/stgit/commands/diff.py
@@ -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)
diff --git a/stgit/commands/export.py b/stgit/commands/export.py
index cafcbe3..d6b36a9 100644
--- a/stgit/commands/export.py
+++ b/stgit/commands/export.py
@@ -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
diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index b95014c..7113cff 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -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
diff --git a/stgit/git.py b/stgit/git.py
index 5cdc8cd..7358fae 100644
--- a/stgit/git.py
+++ b/stgit/git.py
@@ -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 = ''
 
Previous: Yann DirsonNext: Yann Dirson
Message 7 of 10 in “Rename detection, take 2”
  1. 0/4 Rename detection, take 2Yann Dirson, May 31, 2007
  2. 1/4 Add 2 new contrib scripts.Yann Dirson, May 31, 2007
  3. David KågedalJun 1, 2007
  4. Karl HasselströmJun 3, 2007
  5. Yann DirsonJun 3, 2007
  6. 2/4 Call external commands without a shell where possible.Yann Dirson, May 31, 2007
  7. 3/4 Make diff flags handling more modular.Yann Dirson, May 31, 2007
  8. 4/4 Add new --diff-opts/-O flag to diff- and status-related commands.Yann Dirson, May 31, 2007
  9. Catalin MarinasJun 4, 2007
  10. Yann DirsonJun 5, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.