addremove: comparing two empty files caused ZeroDivisionError
(found by Giorgos Keramidas)
--- a/mercurial/cmdutil.py Fri Jun 01 13:03:21 2007 +0200
+++ b/mercurial/cmdutil.py Fri Jun 01 16:00:40 2007 +0200
@@ -160,9 +160,11 @@
for line in alines[x1:x2]:
equal += len(line)
- myscore = equal*2.0 / (len(aa)+len(rr))
- if myscore >= bestscore:
- bestname, bestscore = r, myscore
+ lengths = len(aa) + len(rr)
+ if lengths:
+ myscore = equal*2.0 / lengths
+ if myscore >= bestscore:
+ bestname, bestscore = r, myscore
if bestname:
yield bestname, a, bestscore
--- a/tests/test-addremove-similar Fri Jun 01 13:03:21 2007 +0200
+++ b/tests/test-addremove-similar Fri Jun 01 16:00:40 2007 +0200
@@ -16,6 +16,12 @@
hg commit -m B
+echo % comparing two empty files caused ZeroDivisionError in the past
+hg update -C 0
+rm empty-file
+touch another-empty-file
+hg addremove -s50
+
cd ..
hg init rep2; cd rep2
--- a/tests/test-addremove-similar.out Fri Jun 01 13:03:21 2007 +0200
+++ b/tests/test-addremove-similar.out Fri Jun 01 16:00:40 2007 +0200
@@ -4,6 +4,10 @@
removing empty-file
removing large-file
recording removal of large-file as rename to another-file (99% similar)
+% comparing two empty files caused ZeroDivisionError in the past
+2 files updated, 0 files merged, 1 files removed, 0 files unresolved
+adding another-empty-file
+removing empty-file
adding large-file
adding tiny-file
adding small-file