X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/78e5af69d99659769b052e4c00fe5b23a8356231..f73aeed63821f211efe8f09ee7285122efee2886:/stgit/commands/diff.py diff --git a/stgit/commands/diff.py b/stgit/commands/diff.py index fd6be34..631e42d 100644 --- a/stgit/commands/diff.py +++ b/stgit/commands/diff.py @@ -17,39 +17,35 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import sys, os -from optparse import OptionParser, make_option from pydoc import pager - +from stgit.argparse import opt from stgit.commands.common import * from stgit.utils import * from stgit.out import * -from stgit import stack, git - - -help = 'show the tree diff' -usage = """%prog [options] [] +from stgit import argparse, stack, git +from stgit.lib import git as gitlib +help = 'Show the tree diff' +kind = 'wc' +usage = ['[options] []'] +description = """ Show the diff (default) or diffstat between the current working copy -or a tree-ish object and another tree-ish object. File names can also -be given to restrict the diff output. The tree-ish object can be a -standard git commit, tag or tree. In addition to these, the command -also supports 'base', representing the bottom of the current stack, -and '[patch][//[bottom | top]]' for the patch boundaries (defaulting to -the current one): +or a tree-ish object and another tree-ish object (defaulting to HEAD). +File names can also be given to restrict the diff output. The +tree-ish object has the format accepted by the linkstg:id[] command.""" -rev = '([patch][//[bottom | top]]) | | base' +args = [argparse.known_files, argparse.dirty_files] +options = [ + opt('-r', '--range', metavar = 'rev1[..[rev2]]', dest = 'revs', + args = [argparse.patch_range(argparse.applied_patches, + argparse.unapplied_patches, + argparse.hidden_patches)], + short = 'Show the diff between revisions'), + opt('-s', '--stat', action = 'store_true', + short = 'Show the stat instead of the diff'), + ] + argparse.diff_opts_option() -If neither bottom nor top are given but a '//' is present, the command -shows the specified patch (defaulting to the current one).""" - -directory = DirectoryHasRepository() -options = [make_option('-r', '--range', - metavar = 'rev1[..[rev2]]', dest = 'revs', - help = 'show the diff between revisions'), - make_option('-s', '--stat', - help = 'show the stat instead of the diff', - action = 'store_true') - ] + make_diff_opts_option() +directory = DirectoryHasRepository(log = False) def func(parser, options, args): """Show the tree diff @@ -61,17 +57,8 @@ def func(parser, options, args): rev_list = options.revs.split('..') rev_list_len = len(rev_list) if rev_list_len == 1: - rev = rev_list[0] - if rev.endswith('/'): - # the whole patch - rev = strip_suffix('/', rev) - if rev.endswith('/'): - rev = strip_suffix('/', rev) - rev1 = rev + '//bottom' - rev2 = rev + '//top' - else: - rev1 = rev_list[0] - rev2 = None + rev1 = rev_list[0] + rev2 = None elif rev_list_len == 2: rev1 = rev_list[0] rev2 = rev_list[1] @@ -81,11 +68,13 @@ def func(parser, options, args): rev1 = 'HEAD' rev2 = None - diff_str = git.diff(args, git_id(crt_series, rev1), - git_id(crt_series, rev2), + if not options.stat: + options.diff_flags.extend(color_diff_flags()) + diff_str = git.diff(args, rev1 and git_id(crt_series, rev1), + rev2 and git_id(crt_series, rev2), diff_flags = options.diff_flags) if options.stat: - out.stdout_raw(git.diffstat(diff_str) + '\n') + out.stdout_raw(gitlib.diffstat(diff_str) + '\n') else: if diff_str: pager(diff_str)