# HG changeset patch # User Steven Brown # Date 2011-05-26 14:51:02 # Node ID cbe13e6bdc34ac60bc8475ae2022f0bed0169a70 # Parent 5adb525247791d367403ec34711eae1c2f028cea 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 --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1672,14 +1672,15 @@ def trydiff(repo, revs, ctx1, ctx2, modi 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 diffstatdata(lines): 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 --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -186,7 +186,7 @@ def showdiffstat(repo, ctx, templ, **arg "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 --git a/tests/test-diffstat.t b/tests/test-diffstat.t --- a/tests/test-diffstat.t +++ b/tests/test-diffstat.t @@ -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 @@ Narrow diffstat: $ 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