# HG changeset patch # User Thomas Arendsen Hein # Date 1180706440 -7200 # Node ID 736e49292809a86cc21da07c25b74672c72584a5 # Parent 1196998c62e36d01ac6feed5a37f5945d48c8ef1 addremove: comparing two empty files caused ZeroDivisionError (found by Giorgos Keramidas) diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- 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 diff --git a/tests/test-addremove-similar b/tests/test-addremove-similar --- 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 diff --git a/tests/test-addremove-similar.out b/tests/test-addremove-similar.out --- 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