diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -420,11 +420,19 @@ class queue(object): def printdiff(self, repo, node1, node2=None, files=None, fp=None, changes=None, opts={}): + stat = opts.get('stat') + if stat: + opts['unified'] = '0' + m = cmdutil.match(repo, files, opts) chunks = patch.diff(repo, node1, node2, m, changes, self.diffopts()) write = fp is None and repo.ui.write or fp.write - for chunk in chunks: - write(chunk) + if stat: + width = self.ui.interactive() and util.termwidth() or 80 + write(patch.diffstat(util.iterlines(chunks), width=width)) + else: + for chunk in chunks: + write(chunk) def mergeone(self, repo, mergeq, head, patch, rev): # first try just applying the patch diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1085,6 +1085,7 @@ def diff(ui, repo, *pats, **opts): revs = opts.get('rev') change = opts.get('change') + stat = opts.get('stat') if revs and change: msg = _('cannot specify --rev and --change at the same time') @@ -1095,10 +1096,17 @@ def diff(ui, repo, *pats, **opts): else: node1, node2 = cmdutil.revpair(repo, revs) + if stat: + opts['unified'] = '0' + m = cmdutil.match(repo, pats, opts) it = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts)) - for chunk in it: - ui.write(chunk) + if stat: + width = ui.interactive() and util.termwidth() or 80 + ui.write(patch.diffstat(util.iterlines(it), width=width)) + else: + for chunk in it: + ui.write(chunk) def export(ui, repo, *changesets, **opts): """dump the header and diffs for one or more changesets @@ -3260,7 +3268,8 @@ diffopts2 = [ _('ignore changes in the amount of white space')), ('B', 'ignore-blank-lines', None, _('ignore changes whose lines are all blank')), - ('U', 'unified', '', _('number of lines of context to show')) + ('U', 'unified', '', _('number of lines of context to show')), + ('', 'stat', None, _('output diffstat-style summary of changes')), ] similarityopts = [ diff --git a/tests/test-debugcomplete.out b/tests/test-debugcomplete.out --- a/tests/test-debugcomplete.out +++ b/tests/test-debugcomplete.out @@ -167,7 +167,7 @@ add: include, exclude, dry-run annotate: rev, follow, text, user, date, number, changeset, line-number, include, exclude clone: noupdate, rev, pull, uncompressed, ssh, remotecmd commit: addremove, close-branch, include, exclude, message, logfile, date, user -diff: rev, change, text, git, nodates, show-function, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, include, exclude +diff: rev, change, text, git, nodates, show-function, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude export: output, switch-parent, text, git, nodates forget: include, exclude init: ssh, remotecmd diff --git a/tests/test-diffstat b/tests/test-diffstat new file mode 100755 --- /dev/null +++ b/tests/test-diffstat @@ -0,0 +1,31 @@ +#!/bin/sh + +hg init repo +cd repo +i=0; while (( $i < 213 )); do echo a >> a; i=$(($i + 1)); done +hg add a + +echo '% wide diffstat' +hg diff --stat + +echo '% diffstat width' +COLUMNS=24 hg diff --config ui.interactive=true --stat + +hg ci -m adda + +cat >> a < b +hg add b + +echo '% binary diffstat' +hg diff --stat diff --git a/tests/test-diffstat.out b/tests/test-diffstat.out new file mode 100644 --- /dev/null +++ b/tests/test-diffstat.out @@ -0,0 +1,12 @@ +% wide diffstat + a | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 files changed, 213 insertions(+), 0 deletions(-) +% diffstat width + a | 213 ++++++++++++++ + 1 files changed, 213 insertions(+), 0 deletions(-) +% narrow diffstat + a | 3 +++ + 1 files changed, 3 insertions(+), 0 deletions(-) +% binary diffstat + b | 0 + 1 files changed, 0 insertions(+), 0 deletions(-) diff --git a/tests/test-help.out b/tests/test-help.out --- a/tests/test-help.out +++ b/tests/test-help.out @@ -241,6 +241,7 @@ options: -b --ignore-space-change ignore changes in the amount of white space -B --ignore-blank-lines ignore changes whose lines are all blank -U --unified number of lines of context to show + --stat output diffstat-style summary of changes -I --include include names matching the given patterns -X --exclude exclude names matching the given patterns