##// END OF EJS Templates
findrenames: refactor the score computation
Benoit Boissinot -
r9926:4b044b81 default
parent child Browse files
Show More
@@ -276,24 +276,28 b' def findrenames(repo, added, removed, th'
276 if r not in ctx:
276 if r not in ctx:
277 continue
277 continue
278 fctx = ctx.filectx(r)
278 fctx = ctx.filectx(r)
279 rr = fctx.data()
279 orig = fctx.data()
280 for a in added:
280
281 bestscore = copies.get(a, (None, threshold))[1]
281 def score(text):
282 aa = repo.wread(a)
282 if not len(text):
283 return 0.0
283 # bdiff.blocks() returns blocks of matching lines
284 # bdiff.blocks() returns blocks of matching lines
284 # count the number of bytes in each
285 # count the number of bytes in each
285 equal = 0
286 equal = 0
286 alines = mdiff.splitnewlines(aa)
287 alines = mdiff.splitnewlines(text)
287 matches = bdiff.blocks(aa, rr)
288 matches = bdiff.blocks(text, orig)
288 for x1,x2,y1,y2 in matches:
289 for x1,x2,y1,y2 in matches:
289 for line in alines[x1:x2]:
290 for line in alines[x1:x2]:
290 equal += len(line)
291 equal += len(line)
291
292
292 lengths = len(aa) + len(rr)
293 lengths = len(text) + len(orig)
293 if lengths:
294 return equal*2.0 / lengths
294 myscore = equal*2.0 / lengths
295
295 if myscore >= bestscore:
296 for a in added:
296 copies[a] = (r, myscore)
297 bestscore = copies.get(a, (None, threshold))[1]
298 myscore = score(repo.wread(a))
299 if myscore >= bestscore:
300 copies[a] = (r, myscore)
297 for dest, v in copies.iteritems():
301 for dest, v in copies.iteritems():
298 source, score = v
302 source, score = v
299 yield source, dest, score
303 yield source, dest, score
General Comments 0
You need to be logged in to leave comments. Login now