--- a/mercurial/similar.py Sat Oct 05 10:29:34 2019 -0400
+++ b/mercurial/similar.py Sun Oct 06 09:45:02 2019 -0400
@@ -8,9 +8,8 @@
from __future__ import absolute_import
from .i18n import _
-from . import (
- mdiff,
-)
+from . import mdiff
+
def _findexactmatches(repo, added, removed):
'''find renamed files that have no changes
@@ -21,9 +20,11 @@
# Build table of removed files: {hash(fctx.data()): [fctx, ...]}.
# We use hash() to discard fctx.data() from memory.
hashes = {}
- progress = repo.ui.makeprogress(_('searching for exact renames'),
- total=(len(added) + len(removed)),
- unit=_('files'))
+ progress = repo.ui.makeprogress(
+ _('searching for exact renames'),
+ total=(len(added) + len(removed)),
+ unit=_('files'),
+ )
for fctx in removed:
progress.increment()
h = hash(fctx.data())
@@ -46,11 +47,13 @@
# Done
progress.complete()
+
def _ctxdata(fctx):
# lazily load text
orig = fctx.data()
return orig, mdiff.splitnewlines(orig)
+
def _score(fctx, otherdata):
orig, lines = otherdata
text = fctx.data()
@@ -65,9 +68,11 @@
lengths = len(text) + len(orig)
return equal * 2.0 / lengths
+
def score(fctx1, fctx2):
return _score(fctx1, _ctxdata(fctx2))
+
def _findsimilarmatches(repo, added, removed, threshold):
'''find potentially renamed files based on similar file content
@@ -75,8 +80,9 @@
(before, after, score) tuples of partial matches.
'''
copies = {}
- progress = repo.ui.makeprogress(_('searching for similar files'),
- unit=_('files'), total=len(removed))
+ progress = repo.ui.makeprogress(
+ _('searching for similar files'), unit=_('files'), total=len(removed)
+ )
for r in removed:
progress.increment()
data = None
@@ -93,9 +99,11 @@
source, bscore = v
yield source, dest, bscore
+
def _dropempty(fctxs):
return [x for x in fctxs if x.size() > 0]
+
def findrenames(repo, added, removed, threshold):
'''find renamed files -- yields (before, after, score) tuples'''
wctx = repo[None]
@@ -116,6 +124,7 @@
# If the user requested similar files to be matched, search for them also.
if threshold < 1.0:
addedfiles = [x for x in addedfiles if x not in matchedfiles]
- for (a, b, score) in _findsimilarmatches(repo, addedfiles,
- removedfiles, threshold):
+ for (a, b, score) in _findsimilarmatches(
+ repo, addedfiles, removedfiles, threshold
+ ):
yield (a.path(), b.path(), score)