# HG changeset patch # User Bryan O'Sullivan # Date 1259102729 28800 # Node ID a9cab6c49d61d3fe10dc524377952f1b1d0bc128 # Parent ea3acaae25bb93f3f85869f7c7142d20b6d3b324# Parent 193a8d539e21b80baa695002d3c3549fbfe1ace4 Merge with mpm diff -r ea3acaae25bb -r a9cab6c49d61 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Tue Nov 24 14:32:19 2009 +0200 +++ b/mercurial/cmdutil.py Tue Nov 24 14:45:29 2009 -0800 @@ -270,31 +270,42 @@ def findrenames(repo, added, removed, threshold): '''find renamed files -- yields (before, after, score) tuples''' + copies = {} ctx = repo['.'] - for a in added: - aa = repo.wread(a) - bestname, bestscore = None, threshold - for r in removed: - if r not in ctx: - continue - rr = ctx.filectx(r).data() + for r in removed: + if r not in ctx: + continue + fctx = ctx.filectx(r) + def score(text): + if not len(text): + return 0.0 + if not fctx.cmp(text): + return 1.0 + if threshold == 1.0: + return 0.0 + orig = fctx.data() # bdiff.blocks() returns blocks of matching lines # count the number of bytes in each equal = 0 - alines = mdiff.splitnewlines(aa) - matches = bdiff.blocks(aa, rr) - for x1,x2,y1,y2 in matches: + alines = mdiff.splitnewlines(text) + matches = bdiff.blocks(text, orig) + for x1, x2, y1, y2 in matches: for line in alines[x1:x2]: equal += len(line) - lengths = len(aa) + len(rr) - if lengths: - myscore = equal*2.0 / lengths - if myscore >= bestscore: - bestname, bestscore = r, myscore - if bestname: - yield bestname, a, bestscore + lengths = len(text) + len(orig) + return equal * 2.0 / lengths + + for a in added: + bestscore = copies.get(a, (None, threshold))[1] + myscore = score(repo.wread(a)) + if myscore >= bestscore: + copies[a] = (r, myscore) + + for dest, v in copies.iteritems(): + source, score = v + yield source, dest, score def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None): if dry_run is None: