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.
--- a/mercurial/patch.py Tue May 24 17:48:16 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:
--- a/mercurial/templatekw.py Tue May 24 17:48:16 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):
--- a/tests/test-diffstat.t Tue May 24 17:48:16 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