diff contrib/churn.py @ 5588:083b6e3142a2

churn: avoid division by zero
author Matt Mackall <mpm@selenic.com>
date Sun, 02 Dec 2007 17:04:16 -0600
parents e5eedd74e70f
children d0576d065993
line wrap: on
line diff
--- a/contrib/churn.py	Sun Dec 02 16:26:56 2007 -0600
+++ b/contrib/churn.py	Sun Dec 02 17:04:16 2007 -0600
@@ -125,6 +125,7 @@
         ui.note("rev %d: %d lines by %s\n" % (rev, lines, who))
 
         if progress:
+            nr_revs = max(nr_revs, 1)
             if int(100.0*(cur_rev - 1)/nr_revs) < int(100.0*cur_rev/nr_revs):
                 ui.write("%d%%.." % (int(100.0*cur_rev/nr_revs),))
                 sys.stdout.flush()
@@ -144,6 +145,7 @@
         return s[0:l]
 
     def graph(n, maximum, width, char):
+        maximum = max(1, maximum)
         n = int(n * width / float(maximum))
 
         return char * (n)
@@ -178,6 +180,8 @@
     ordered = stats.items()
     ordered.sort(lambda x, y: cmp(y[1], x[1]))
 
+    if not ordered:
+        return
     maximum = ordered[0][1]
 
     width = get_tty_width()