chiark / gitweb /
Add new --diff-opts/-O flag to diff- and status-related commands.
authorYann Dirson <ydirson@altern.org>
Thu, 31 May 2007 22:34:38 +0000 (00:34 +0200)
committerCatalin Marinas <catalin.marinas@gmail.com>
Sat, 2 Jun 2007 22:43:52 +0000 (23:43 +0100)
This new flag allows to pass arbitrary flags to the git-diff calls
underlying several StGIT commands.  It can be used to pass flags
affecting both diff- and status-generating commands (eg. -M or -C), or
flags only affecting diff-generating ones (eg. --color, --binary).

It supercedes --binary for commands where it was allowed,
'-O --binary' is now available for the same functionality.

Signed-off-by: Yann Dirson <ydirson@altern.org>
stgit/commands/diff.py
stgit/commands/export.py
stgit/commands/files.py
stgit/commands/mail.py
stgit/commands/show.py
stgit/commands/status.py
stgit/git.py

index b66c75bb9c7a53a691cf336055d7be057163bede..f8b19f8868fa33df995364638086d7a0db29f4bc 100644 (file)
@@ -44,9 +44,8 @@ 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('-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')]
@@ -79,8 +78,8 @@ def func(parser, options, args):
         rev1 = 'HEAD'
         rev2 = None
 
-    if options.binary:
-        diff_flags = [ '--binary' ]
+    if options.diff_opts:
+        diff_flags = options.diff_opts.split()
     else:
         diff_flags = []
 
index d6b36a959b09c87c7db3db763347b450d2d3d44e..35851bc54f06356b95fd54377f4a0e536854da53 100644 (file)
@@ -62,9 +62,8 @@ 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('-O', '--diff-opts',
+                       help = 'options to pass to git-diff'),
            make_option('-s', '--stdout',
                        help = 'dump the patches to the standard output',
                        action = 'store_true')]
@@ -87,8 +86,8 @@ def func(parser, options, args):
             os.makedirs(dirname)
         series = file(os.path.join(dirname, 'series'), 'w+')
 
-    if options.binary:
-        diff_flags = [ '--binary' ]
+    if options.diff_opts:
+        diff_flags = options.diff_opts.split()
     else:
         diff_flags = []
 
index 59893d842414ee097ada715e84aa3687aae8fc69..659a82b57c73aba9a62a036dfed9201f17dbc145 100644 (file)
@@ -38,6 +38,8 @@ options = [make_option('-s', '--stat',
                        action = 'store_true'),
            make_option('-b', '--branch',
                        help = 'use BRANCH instead of the default one'),
+           make_option('-O', '--diff-opts',
+                       help = 'options to pass to git-diff'),
            make_option('--bare',
                        help = 'bare file names (useful for scripting)',
                        action = 'store_true')]
@@ -61,4 +63,9 @@ def func(parser, options, args):
     elif options.bare:
         out.stdout_raw(git.barefiles(rev1, rev2) + '\n')
     else:
-        out.stdout_raw(git.files(rev1, rev2) + '\n')
+        if options.diff_opts:
+            diff_flags = options.diff_opts.split()
+        else:
+            diff_flags = []
+
+        out.stdout_raw(git.files(rev1, rev2, diff_flags = diff_flags) + '\n')
index 7113cff796cd3a8f9328040253ac89a4813436b2..cec1828bce44bc3ecfdb803bedbda4b77b0a6b8c 100644 (file)
@@ -120,9 +120,8 @@ 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('-O', '--diff-opts',
+                       help = 'options to pass to git-diff'),
            make_option('-m', '--mbox',
                        help = 'generate an mbox file instead of sending',
                        action = 'store_true')]
@@ -377,8 +376,8 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options):
     else:
         prefix_str = ''
         
-    if options.binary:
-        diff_flags = [ '--binary' ]
+    if options.diff_opts:
+        diff_flags = options.diff_opts.split()
     else:
         diff_flags = []
 
index a270efd8bd99f48d6b0744226ce7a33b11182439..ea4c874d0646649c4bacf4b8cfef7d66c9d26795 100644 (file)
@@ -35,7 +35,9 @@ options = [make_option('-a', '--applied',
                        action = 'store_true'),
            make_option('-u', '--unapplied',
                        help = 'show the unapplied patches',
-                       action = 'store_true')]
+                       action = 'store_true'),
+           make_option('-O', '--diff-opts',
+                       help = 'options to pass to git-diff')]
 
 
 def func(parser, options, args):
@@ -58,8 +60,13 @@ def func(parser, options, args):
         else:
             patches = parse_patches(args, applied + unapplied, len(applied))
 
+    if options.diff_opts:
+        diff_flags = options.diff_opts.split()
+    else:
+        diff_flags = []
+
     commit_ids = [git_id(patch) for patch in patches]
-    commit_str = '\n'.join([git.pretty_commit(commit_id)
+    commit_str = '\n'.join([git.pretty_commit(commit_id, diff_flags=diff_flags)
                             for commit_id in commit_ids])
     if commit_str:
         pager(commit_str)
index b8f062330d868e9bb78941a30cfdada87bb3d975..156552b7802f6dda167e925f77809b8f5d279e6e 100644 (file)
@@ -58,6 +58,8 @@ options = [make_option('-m', '--modified',
            make_option('-x', '--noexclude',
                        help = 'do not exclude any files from listing',
                        action = 'store_true'),
+           make_option('-O', '--diff-opts',
+                       help = 'options to pass to git-diff'),
            make_option('--reset',
                        help = 'reset the current tree changes',
                        action = 'store_true')]
@@ -75,5 +77,11 @@ def func(parser, options, args):
             resolved_all()
             git.reset()
     else:
+        if options.diff_opts:
+            diff_flags = options.diff_opts.split()
+        else:
+            diff_flags = []
+
         git.status(args, options.modified, options.new, options.deleted,
-                   options.conflict, options.unknown, options.noexclude)
+                   options.conflict, options.unknown, options.noexclude,
+                   diff_flags = diff_flags)
index 7358fae6ef31d11f3f5f912e142b0488b988f21c..4bc41aac6b19fbfc48dad36aa83d02ee16b121fd 100644 (file)
@@ -217,7 +217,7 @@ def __run(cmd, args=None):
     return 0
 
 def __tree_status(files = None, tree_id = 'HEAD', unknown = False,
-                  noexclude = True, verbose = False):
+                  noexclude = True, verbose = False, diff_flags = []):
     """Returns a list of pairs - [status, filename]
     """
     if verbose:
@@ -254,7 +254,8 @@ def __tree_status(files = None, tree_id = 'HEAD', unknown = False,
     cache_files += [('C', filename) for filename in conflicts]
 
     # the rest
-    for line in _output_lines(['git-diff-index', tree_id, '--'] + files):
+    for line in _output_lines(['git-diff-index'] + diff_flags +
+                              [ tree_id, '--'] + files):
         fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
         if fs[1] not in conflicts:
             cache_files.append(fs)
@@ -737,13 +738,15 @@ def merge(base, head1, head2, recursive = False):
         raise GitException, 'GIT index merging failed (possible conflicts)'
 
 def status(files = None, modified = False, new = False, deleted = False,
-           conflict = False, unknown = False, noexclude = False):
+           conflict = False, unknown = False, noexclude = False,
+           diff_flags = []):
     """Show the tree status
     """
     if not files:
         files = []
 
-    cache_files = __tree_status(files, unknown = True, noexclude = noexclude)
+    cache_files = __tree_status(files, unknown = True, noexclude = noexclude,
+                                diff_flags = diff_flags)
     all = not (modified or new or deleted or conflict or unknown)
 
     if not all:
@@ -809,12 +812,12 @@ def diffstat(files = None, rev1 = 'HEAD', rev2 = None):
         raise GitException, 'git.diffstat failed'
     return diff_str
 
-def files(rev1, rev2):
+def files(rev1, rev2, diff_flags = []):
     """Return the files modified between rev1 and rev2
     """
 
     result = ''
-    for line in _output_lines(['git-diff-tree''-r', rev1, rev2]):
+    for line in _output_lines(['git-diff-tree'] + diff_flags + ['-r', rev1, rev2]):
         result += '%s %s\n' % tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
 
     return result.rstrip()
@@ -829,11 +832,11 @@ def barefiles(rev1, rev2):
 
     return result.rstrip()
 
-def pretty_commit(commit_id = 'HEAD'):
+def pretty_commit(commit_id = 'HEAD', diff_flags = []):
     """Return a given commit (log + diff)
     """
-    return _output(['git-diff-tree', '--cc', '--always', '--pretty', '-r',
-                    commit_id])
+    return _output(['git-diff-tree'] + diff_flags +
+                   ['--cc', '--always', '--pretty', '-r', commit_id])
 
 def checkout(files = None, tree_id = None, force = False):
     """Check out the given or all files