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

Nicolas Dumazet nicdumz at gmail.com
Mon Aug 24 08:18:55 CDT 2009


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1251110864 -7200
# Node ID abbe5decbc95a0663b09c21b0eda7d7ada6def6d
# Parent  a4c7cc7dabcb4498e535a1f38d68338cc7b8f87a
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.0
     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