[PATCH 1 of 3] diff: add --stat for diffstat output
Brodie Rao
dackze at gmail.com
Tue Sep 22 08:05:31 CDT 2009
# HG changeset patch
# User Brodie Rao <me+hg at dackz.net>
# Date 1253624269 14400
# Node ID bd0a07c03d2a9c83e5a8803928aa29790352cff3
# Parent a15813fae0a8f414228f9da768c235f9d017ebfa
diff: add --stat for diffstat output
diff --stat invokes patch.diffstat() on the diff output.
When in interactive mode, the output's maximum width is determined by the
terminal's width.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1088,6 +1088,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')
@@ -1098,10 +1099,19 @@ 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:
+ statopts = {}
+ if ui.interactive():
+ statopts['width'] = util.termwidth()
+ ui.write(patch.diffstat(util.iterlines(it), **statopts))
+ else:
+ for chunk in it:
+ ui.write(chunk)
def export(ui, repo, *changesets, **opts):
"""dump the header and diffs for one or more changesets
@@ -3161,7 +3171,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')),
+ ('s', 'stat', None, _('output diffstat-style summary of changes')),
]
similarityopts = [
diff --git a/tests/test-diffstat b/tests/test-diffstat
new file mode 100755
--- /dev/null
+++ b/tests/test-diffstat
@@ -0,0 +1,23 @@
+#!/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 -s
+
+hg ci -m adda
+
+cat >> a <<EOF
+a
+a
+a
+EOF
+
+echo '% narrow 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,9 @@
+% 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(-)
More information about the Mercurial-devel
mailing list