##// END OF EJS Templates
similar: remove caching from the module level...
Pierre-Yves David -
r30809:86145461 default
parent child Browse files
Show More
@@ -13,7 +13,6 b' from .i18n import _'
13 from . import (
13 from . import (
14 bdiff,
14 bdiff,
15 mdiff,
15 mdiff,
16 util,
17 )
16 )
18
17
19 def _findexactmatches(repo, added, removed):
18 def _findexactmatches(repo, added, removed):
@@ -43,16 +42,14 b' def _findexactmatches(repo, added, remov'
43 # Done
42 # Done
44 repo.ui.progress(_('searching for exact renames'), None)
43 repo.ui.progress(_('searching for exact renames'), None)
45
44
46 @util.cachefunc
47 def _ctxdata(fctx):
45 def _ctxdata(fctx):
48 # lazily load text
46 # lazily load text
49 orig = fctx.data()
47 orig = fctx.data()
50 return orig, mdiff.splitnewlines(orig)
48 return orig, mdiff.splitnewlines(orig)
51
49
52 @util.cachefunc
50 def _score(fctx, otherdata):
53 def score(fctx1, fctx2):
51 orig, lines = otherdata
54 text = fctx1.data()
52 text = fctx.data()
55 orig, lines = _ctxdata(fctx2)
56 # bdiff.blocks() returns blocks of matching lines
53 # bdiff.blocks() returns blocks of matching lines
57 # count the number of bytes in each
54 # count the number of bytes in each
58 equal = 0
55 equal = 0
@@ -64,6 +61,9 b' def score(fctx1, fctx2):'
64 lengths = len(text) + len(orig)
61 lengths = len(text) + len(orig)
65 return equal * 2.0 / lengths
62 return equal * 2.0 / lengths
66
63
64 def score(fctx1, fctx2):
65 return _score(fctx1, _ctxdata(fctx2))
66
67 def _findsimilarmatches(repo, added, removed, threshold):
67 def _findsimilarmatches(repo, added, removed, threshold):
68 '''find potentially renamed files based on similar file content
68 '''find potentially renamed files based on similar file content
69
69
@@ -75,9 +75,12 b' def _findsimilarmatches(repo, added, rem'
75 repo.ui.progress(_('searching for similar files'), i,
75 repo.ui.progress(_('searching for similar files'), i,
76 total=len(removed), unit=_('files'))
76 total=len(removed), unit=_('files'))
77
77
78 data = None
78 for a in added:
79 for a in added:
79 bestscore = copies.get(a, (None, threshold))[1]
80 bestscore = copies.get(a, (None, threshold))[1]
80 myscore = score(a, r)
81 if data is None:
82 data = _ctxdata(r)
83 myscore = _score(a, data)
81 if myscore >= bestscore:
84 if myscore >= bestscore:
82 copies[a] = (r, myscore)
85 copies[a] = (r, myscore)
83 repo.ui.progress(_('searching'), None)
86 repo.ui.progress(_('searching'), None)
General Comments 0
You need to be logged in to leave comments. Login now