diffstat: use width 80 by default and avoid division by zero
authorMatt Mackall <mpm@selenic.com>
Fri, 20 Mar 2009 14:38:50 -0500
changeset 7860 162fd31bbd93
parent 7857 6af7c0e5908c
child 7861 2bc14da14992
diffstat: use width 80 by default and avoid division by zero
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)