addremove: comparing two empty files caused ZeroDivisionError
authorThomas Arendsen Hein <thomas@intevation.de>
Fri, 01 Jun 2007 16:00:40 +0200
changeset 4472 736e49292809
parent 4471 1196998c62e3
child 4473 f975e986b4bf
addremove: comparing two empty files caused ZeroDivisionError (found by Giorgos Keramidas)
mercurial/cmdutil.py
tests/test-addremove-similar
tests/test-addremove-similar.out
--- 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