addremove: comparing two empty files caused ZeroDivisionError
authorThomas Arendsen Hein <thomas@intevation.de>
Fri, 01 Jun 2007 16:00:40 +0200
changeset 4471 736e49292809
parent 4470 1196998c62e3
child 4472 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
+++ b/mercurial/cmdutil.py
@@ -160,9 +160,11 @@ def findrenames(repo, added=None, remove
                 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
+++ b/tests/test-addremove-similar
@@ -16,6 +16,12 @@ hg addremove -s50
 
 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
+++ b/tests/test-addremove-similar.out
@@ -4,6 +4,10 @@ adding another-file
 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