[PATCH] churn: issue833 was reintroduced in 9bc46d069a76, correct it and add a test

Nicolas Dumazet nicdumz at gmail.com
Mon Aug 24 06:41:39 CDT 2009


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1251110864 -7200
# Node ID 27aea279ff6ad71ab9388e86d5fba08e384fc4c9
# Parent  9a1a497b8c4d9b90a92d5467e6387efc44b57f4b
churn: issue833 was reintroduced in 9bc46d069a76, correct it and add a test

diff --git a/hgext/churn.py b/hgext/churn.py
--- a/hgext/churn.py
+++ b/hgext/churn.py
@@ -148,7 +148,8 @@
     sortkey = ((not opts.get('sort')) and (lambda x: -x[1]) or None)
     rate.sort(key=sortkey)
 
-    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.
     maxname = max([len(k) for k, v in rate])
 
     ttywidth = util.termwidth()
diff --git a/tests/test-churn b/tests/test-churn
--- a/tests/test-churn
+++ b/tests/test-churn
@@ -50,3 +50,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 ..
diff --git a/tests/test-churn.out b/tests/test-churn.out
--- a/tests/test-churn.out
+++ b/tests/test-churn.out
@@ -28,3 +28,5 @@
 09      2 *********************************
 12      4 ******************************************************************
 13      1 ****************
+adding foo
+test      0 


More information about the Mercurial-devel mailing list