Mercurial > hg-stable
changeset 30809:8614546154cb
similar: remove caching from the module level
To prevent Bad Thingsā¢ from happening, let's rework the logic to not use
util.cachefunc.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Fri, 13 Jan 2017 11:42:36 -0800 |
parents | 8540967cd9e0 |
children | df5d3734b3df |
files | mercurial/similar.py |
diffstat | 1 files changed, 10 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/similar.py Mon Jan 09 11:01:45 2017 -0800 +++ b/mercurial/similar.py Fri Jan 13 11:42:36 2017 -0800 @@ -13,7 +13,6 @@ from . import ( bdiff, mdiff, - util, ) def _findexactmatches(repo, added, removed): @@ -43,16 +42,14 @@ # Done repo.ui.progress(_('searching for exact renames'), None) -@util.cachefunc def _ctxdata(fctx): # lazily load text orig = fctx.data() return orig, mdiff.splitnewlines(orig) -@util.cachefunc -def score(fctx1, fctx2): - text = fctx1.data() - orig, lines = _ctxdata(fctx2) +def _score(fctx, otherdata): + orig, lines = otherdata + text = fctx.data() # bdiff.blocks() returns blocks of matching lines # count the number of bytes in each equal = 0 @@ -64,6 +61,9 @@ 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,9 +75,12 @@ repo.ui.progress(_('searching for similar files'), i, total=len(removed), unit=_('files')) + data = None for a in added: bestscore = copies.get(a, (None, threshold))[1] - myscore = score(a, r) + if data is None: + data = _ctxdata(r) + myscore = _score(a, data) if myscore >= bestscore: copies[a] = (r, myscore) repo.ui.progress(_('searching'), None)