Mercurial > public > mercurial-scm > hg
diff mercurial/similar.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 59c9d3cc810f |
children | 687b865b95ad |
line wrap: on
line diff
--- 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)