From: Yann Dirson Date: Thu, 31 May 2007 22:34:33 +0000 (+0200) Subject: Make diff flags handling more modular. X-Git-Tag: v0.14.3~229 X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/commitdiff_plain/0d219030bbc792da477f721578e0acc1256fc6d0 Make diff flags handling more modular. Signed-off-by: Yann Dirson --- 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 = ''