[PATCH] patch: restore the previous output of 'diff --stat'
Steven Brown
stevengbrown at gmail.com
Thu May 26 09:53:28 CDT 2011
# HG changeset patch
# User Steven Brown <StevenGBrown at gmail.com>
# Date 1306421462 -28800
# Node ID 9d58fbe994b4125998c49cf25d5ef6cf79a0f385
# Parent a6b543e053058c39b52e2b7c1e9a4b7c14c66a56
patch: restore the previous output of 'diff --stat'
Restore the previous diffstat behaviour of scaling by the maximum number of
changes to a single file. Changeset f03f08240c32 modified the diffstat to be
scaled by the total number of changes. This seems to have been unintentional.
diff -r a6b543e05305 -r 9d58fbe994b4 mercurial/patch.py
--- a/mercurial/patch.py Wed May 25 10:06:17 2011 +0200
+++ b/mercurial/patch.py Thu May 26 22:51:02 2011 +0800
@@ -1672,14 +1672,15 @@
yield text
def diffstatsum(stats):
- maxfile, addtotal, removetotal, binary = 0, 0, 0, False
+ maxfile, maxtotal, addtotal, removetotal, binary = 0, 0, 0, 0, False
for f, a, r, b in stats:
maxfile = max(maxfile, encoding.colwidth(f))
+ maxtotal = max(maxtotal, a + r)
addtotal += a
removetotal += r
binary = binary or b
- return maxfile, addtotal, removetotal, binary
+ return maxfile, maxtotal, addtotal, removetotal, binary
def diffstatdata(lines):
diffre = re.compile('^diff .*-r [a-z0-9]+\s(.*)$')
@@ -1712,8 +1713,7 @@
def diffstat(lines, width=80, git=False):
output = []
stats = diffstatdata(lines)
- maxname, totaladds, totalremoves, hasbinary = diffstatsum(stats)
- maxtotal = totaladds + totalremoves
+ maxname, maxtotal, totaladds, totalremoves, hasbinary = diffstatsum(stats)
countwidth = len(str(maxtotal))
if hasbinary and countwidth < 3:
diff -r a6b543e05305 -r 9d58fbe994b4 mercurial/templatekw.py
--- a/mercurial/templatekw.py Wed May 25 10:06:17 2011 +0200
+++ b/mercurial/templatekw.py Thu May 26 22:51:02 2011 +0800
@@ -186,7 +186,7 @@
"modified files: +added/-removed lines"
"""
stats = patch.diffstatdata(util.iterlines(ctx.diff()))
- maxname, adds, removes, binary = patch.diffstatsum(stats)
+ maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
return '%s: +%s/-%s' % (len(stats), adds, removes)
def showextras(**args):
diff -r a6b543e05305 -r 9d58fbe994b4 tests/test-diffstat.t
--- a/tests/test-diffstat.t Wed May 25 10:06:17 2011 +0200
+++ b/tests/test-diffstat.t Thu May 26 22:51:02 2011 +0800
@@ -2,18 +2,22 @@
$ cd repo
$ i=0; while [ "$i" -lt 213 ]; do echo a >> a; i=`expr $i + 1`; done
$ hg add a
+ $ cp a b
+ $ hg add b
Wide diffstat:
$ hg diff --stat
a | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 1 files changed, 213 insertions(+), 0 deletions(-)
+ b | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 426 insertions(+), 0 deletions(-)
diffstat width:
$ COLUMNS=24 hg diff --config ui.interactive=true --stat
a | 213 ++++++++++++++
- 1 files changed, 213 insertions(+), 0 deletions(-)
+ b | 213 ++++++++++++++
+ 2 files changed, 426 insertions(+), 0 deletions(-)
$ hg ci -m adda
@@ -31,19 +35,19 @@
$ hg ci -m appenda
- $ printf '\0' > b
- $ hg add b
+ $ printf '\0' > c
+ $ hg add c
Binary diffstat:
$ hg diff --stat
- b | 0
+ c | 0
1 files changed, 0 insertions(+), 0 deletions(-)
Binary git diffstat:
$ hg diff --stat --git
- b | Bin
+ c | Bin
1 files changed, 0 insertions(+), 0 deletions(-)
$ hg ci -m createb
More information about the Mercurial-devel
mailing list