# HG changeset patch # User Matt Mackall # Date 1237577930 18000 # Node ID 162fd31bbd93b8f1c9249dd4c17f6b1f80f44591 # Parent 6af7c0e5908c55e1fd25d45b5f5ef2c065ad5902 diffstat: use width 80 by default and avoid division by zero diff -r 6af7c0e5908c -r 162fd31bbd93 mercurial/patch.py --- a/mercurial/patch.py Wed Mar 18 17:49:11 2009 +0100 +++ b/mercurial/patch.py Fri Mar 20 14:38:50 2009 -0500 @@ -1359,10 +1359,9 @@ if filename: yield (filename, adds, removes) -def diffstat(lines): +def diffstat(lines, width=80): output = [] stats = list(diffstatdata(lines)) - width = util.termwidth() - 2 maxtotal, maxname = 0, 0 totaladds, totalremoves = 0, 0 @@ -1377,7 +1376,7 @@ if graphwidth < 10: graphwidth = 10 - factor = int(math.ceil(float(maxtotal) / graphwidth)) + factor = max(int(math.ceil(float(maxtotal) / graphwidth)), 1) for filename, adds, removes in stats: # If diffstat runs out of room it doesn't print anything, which @@ -1389,7 +1388,7 @@ adds+removes, pluses, minuses)) if stats: - output.append(' %d files changed, %d insertions(+), %d deletions(-)\n' % - (len(stats), totaladds, totalremoves)) + output.append(' %d files changed, %d insertions(+), %d deletions(-)\n' + % (len(stats), totaladds, totalremoves)) return ''.join(output)