options = [make_option('-r', '--range',
metavar = 'rev1[..[rev2]]', dest = 'revs',
help = 'show the diff between revisions'),
- 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')]
-
+ action = 'store_true')
+ ] + make_diff_opts_option()
def func(parser, options, args):
"""Show the tree diff
rev1 = 'HEAD'
rev2 = None
- if options.diff_opts:
- diff_flags = options.diff_opts.split()
- else:
- diff_flags = []
-
if options.stat:
out.stdout_raw(git.diffstat(args, git_id(crt_series, rev1),
git_id(crt_series, rev2)) + '\n')
else:
diff_str = git.diff(args, git_id(crt_series, rev1),
- git_id(crt_series, rev2), diff_flags = diff_flags )
+ git_id(crt_series, rev2),
+ diff_flags = options.diff_flags)
if diff_str:
pager(diff_str)
options = [make_option('-d', '--diff',
help = 'edit the patch diff',
action = 'store_true'),
- make_option('-O', '--diff-opts',
- help = 'options to pass to git-diff'),
make_option('--undo',
help = 'revert the commit generated by the last edit',
action = 'store_true'),
help = 'replace the committer name with COMMNAME'),
make_option('--commemail',
help = 'replace the committer e-mail with COMMEMAIL')
- ] + make_sign_options() + make_message_options()
+ ] + (make_sign_options() + make_message_options()
+ + make_diff_opts_option())
def __update_patch(pname, text, options):
"""Update the current patch from the given text.
"""
patch = crt_series.get_patch(pname)
- if options.diff_opts:
- if not options.diff:
- raise CmdException, '--diff-opts only available with --diff'
- diff_flags = options.diff_opts.split()
- else:
- diff_flags = []
-
# generate the file to be edited
descr = patch.get_description().strip()
authdate = patch.get_authdate()
tmpl_dict['diffstat'] = git.diffstat(rev1 = bottom, rev2 = top)
tmpl_dict['diff'] = git.diff(rev1 = bottom, rev2 = top,
- diff_flags = diff_flags)
+ diff_flags = options.diff_flags)
for key in tmpl_dict:
# make empty strings if key is not available
help = 'Use FILE as a template'),
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('-s', '--stdout',
help = 'dump the patches to the standard output',
- action = 'store_true')]
+ action = 'store_true')
+ ] + make_diff_opts_option()
def func(parser, options, args):
os.makedirs(dirname)
series = file(os.path.join(dirname, 'series'), 'w+')
- if options.diff_opts:
- diff_flags = options.diff_opts.split()
- else:
- diff_flags = []
-
applied = crt_series.get_applied()
if len(args) != 0:
patches = parse_patches(args, applied)
f.write(descr)
f.write(git.diff(rev1 = patch.get_bottom(),
rev2 = patch.get_top(),
- diff_flags = diff_flags))
+ diff_flags = options.diff_flags))
if not options.stdout:
f.close()
patch_no += 1
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')]
+ action = 'store_true')
+ ] + make_diff_opts_option()
def func(parser, options, args):
elif options.bare:
out.stdout_raw(git.barefiles(rev1, rev2) + '\n')
else:
- 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')
+ out.stdout_raw(git.files(rev1, rev2, diff_flags = options.diff_flags)
+ + '\n')
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('-m', '--mbox',
help = 'generate an mbox file instead of sending',
- action = 'store_true')]
+ action = 'store_true')
+ ] + make_diff_opts_option()
def __get_sender():
prefix_str = confprefix + ' '
else:
prefix_str = ''
-
- if options.diff_opts:
- diff_flags = options.diff_opts.split()
- else:
- diff_flags = []
total_nr_str = str(total_nr)
patch_nr_str = str(patch_nr).zfill(len(total_nr_str))
'diff': git.diff(
rev1 = git_id(crt_series, '%s//bottom' % patch),
rev2 = git_id(crt_series, '%s//top' % patch),
- diff_flags = diff_flags),
+ diff_flags = options.diff_flags),
'diffstat': git.diffstat(
rev1 = git_id(crt_series, '%s//bottom'%patch),
rev2 = git_id(crt_series, '%s//top' % patch)),
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')]
+ action = 'store_true')
+ ] + make_diff_opts_option()
def status(files, modified, new, deleted, conflict, unknown, noexclude,
resolved_all()
git.reset()
else:
- if options.diff_opts:
- diff_flags = options.diff_opts.split()
- else:
- diff_flags = []
-
status(args, options.modified, options.new, options.deleted,
options.conflict, options.unknown, options.noexclude,
- diff_flags = diff_flags)
+ options.diff_flags)
metavar = 'FILE', dest = 'save_template', type = 'string',
help = 'save the message template to FILE and exit')]
+def make_diff_opts_option():
+ def diff_opts_callback(option, opt_str, value, parser):
+ if value:
+ parser.values.diff_flags.extend(value.split())
+ else:
+ parser.values.diff_flags = []
+ return [optparse.make_option(
+ '-O', '--diff-opts', dest = 'diff_flags', default = [],
+ action = 'callback', callback = diff_opts_callback,
+ type = 'string', metavar = 'OPTIONS',
+ help = 'extra options to pass to "git diff"')]
+
# Exit codes.
STGIT_SUCCESS = 0 # everything's OK
STGIT_GENERAL_ERROR = 1 # seems to be non-command-specific error