changeset 31589:2efd9771323e

similar: take the first match instead of the last It seems more natural. This makes the next patch slightly cleaner.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 23 Mar 2017 20:52:41 +0900
parents 2e254165a37c
children 985a98c6bad0
files mercurial/similar.py tests/test-addremove-similar.t
diffstat 2 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/similar.py	Thu Mar 23 21:17:08 2017 +0900
+++ b/mercurial/similar.py	Thu Mar 23 20:52:41 2017 +0900
@@ -25,7 +25,7 @@
 
     # Get hashes of removed files.
     hashes = {}
-    for i, fctx in enumerate(removed):
+    for i, fctx in enumerate(reversed(removed)):
         repo.ui.progress(_('searching for exact renames'), i, total=numfiles,
                          unit=_('files'))
         h = hashlib.sha1(fctx.data()).digest()
@@ -85,7 +85,7 @@
             if data is None:
                 data = _ctxdata(r)
             myscore = _score(a, data)
-            if myscore >= bestscore:
+            if myscore > bestscore:
                 copies[a] = (r, myscore)
     repo.ui.progress(_('searching'), None)
 
--- a/tests/test-addremove-similar.t	Thu Mar 23 21:17:08 2017 +0900
+++ b/tests/test-addremove-similar.t	Thu Mar 23 20:52:41 2017 +0900
@@ -101,7 +101,7 @@
   removing 8
   removing 9
   adding a
-  recording removal of 9 as rename to a (100% similar)
+  recording removal of 0 as rename to a (100% similar)
   $ hg revert -aq
 
 pick one from many similar files
@@ -124,7 +124,7 @@
   removing 8
   removing 9
   adding a
-  recording removal of 9 as rename to a (99% similar)
+  recording removal of 0 as rename to a (99% similar)
   $ hg commit -m 'always the same file should be selected'
 
 should all fail