churn: issue833 was reintroduced in 9bc46d069a76, correct it and add a test
authorNicolas Dumazet <nicdumz.commits@gmail.com>
Mon, 24 Aug 2009 12:47:44 +0200
changeset 9388 f7968bba2307
parent 9384 d91078a2652f
child 9389 7cca980317c5
child 9402 5d49fdef6fd0
churn: issue833 was reintroduced in 9bc46d069a76, correct it and add a test
hgext/churn.py
tests/test-churn
tests/test-churn.out
--- a/hgext/churn.py	Sun Aug 23 11:32:44 2009 +0200
+++ b/hgext/churn.py	Mon Aug 24 12:47:44 2009 +0200
@@ -146,7 +146,8 @@
     sortfn = ((not opts.get('sort')) and (lambda a, b: cmp(b[1], a[1])) or None)
     rate.sort(sortfn)
 
-    maxcount = float(max([v for k, v in rate]))
+    # Be careful not to have a zero maxcount (issue833)
+    maxcount = float(max([v for k, v in rate])) or 1.0
     maxname = max([len(k) for k, v in rate])
 
     ttywidth = util.termwidth()
--- a/tests/test-churn	Sun Aug 23 11:32:44 2009 +0200
+++ b/tests/test-churn	Mon Aug 24 12:47:44 2009 +0200
@@ -48,3 +48,13 @@
 echo % churn by hour
 hg churn -f '%H' -s
 
+cd ..
+
+# issue 833: ZeroDivisionError
+hg init issue-833
+cd issue-833
+touch foo
+hg ci -Am foo
+# this was failing with a ZeroDivisionError
+hg churn
+cd ..
--- a/tests/test-churn.out	Sun Aug 23 11:32:44 2009 +0200
+++ b/tests/test-churn.out	Mon Aug 24 12:47:44 2009 +0200
@@ -28,3 +28,5 @@
 09      2 *********************************
 12      4 ******************************************************************
 13      1 ****************
+adding foo
+test      0