# HG changeset patch # User Matt Mackall # Date 1306008398 18000 # Node ID f03f08240c325ba2a02173a62bea973dd78b09bd # Parent 7bb7be1c13853487fa6fd980b622ec4779754dc8 patch: use diffstatsum in diffstat diff -r 7bb7be1c1385 -r f03f08240c32 mercurial/patch.py --- a/mercurial/patch.py Sat May 21 15:06:36 2011 -0500 +++ b/mercurial/patch.py Sat May 21 15:06:38 2011 -0500 @@ -1721,22 +1721,9 @@ def diffstat(lines, width=80, git=False): output = [] - stats = list(diffstatdata(lines)) - - maxtotal, maxname = 0, 0 - totaladds, totalremoves = 0, 0 - hasbinary = False - - sized = [(filename, adds, removes, isbinary, encoding.colwidth(filename)) - for filename, adds, removes, isbinary in stats] - - for filename, adds, removes, isbinary, namewidth in sized: - totaladds += adds - totalremoves += removes - maxname = max(maxname, namewidth) - maxtotal = max(maxtotal, adds + removes) - if isbinary: - hasbinary = True + stats = diffstatdata(lines) + maxname, totaladds, totalremoves, hasbinary = diffstatsum(stats) + maxtotal = totaladds + totalremoves countwidth = len(str(maxtotal)) if hasbinary and countwidth < 3: @@ -1753,7 +1740,7 @@ # if there were at least some changes. return max(i * graphwidth // maxtotal, int(bool(i))) - for filename, adds, removes, isbinary, namewidth in sized: + for filename, adds, removes, isbinary in stats: if git and isbinary: count = 'Bin' else: @@ -1761,9 +1748,8 @@ pluses = '+' * scale(adds) minuses = '-' * scale(removes) output.append(' %s%s | %*s %s%s\n' % - (filename, ' ' * (maxname - namewidth), - countwidth, count, - pluses, minuses)) + (filename, ' ' * (maxname - encoding.colwidth(filename)), + countwidth, count, pluses, minuses)) if stats: output.append(_(' %d files changed, %d insertions(+), %d deletions(-)\n')