# HG changeset patch # User Benoit Boissinot # Date 2009-11-24 16:26:42 # Node ID 9dfe34bf42c767e5608a6780c1158cbc100116c3 # Parent 3d718761157b9dba2b7a9e1a45858bcc4d493766 findrenames: first loop over the removed files, it's faster Getting the file from the working dir is less expensive than getting it from the repo history, hence the speedup. benchmarked on crew repo with: rm -rf * ; hg up -C ; for i in `find . -name "*.py"` ; do mv $i $i.new;done followed by: hg addremove -s 100 before: Time: real 68.760 secs (user 65.760+0.000 sys 2.490+0.000) after : Time: real 28.890 secs (user 26.920+0.000 sys 1.450+0.000) diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -270,15 +270,16 @@ def matchfiles(repo, files): 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) + rr = fctx.data() + for a in added: + bestscore = copies.get(a, (None, threshold))[1] + aa = repo.wread(a) # bdiff.blocks() returns blocks of matching lines # count the number of bytes in each equal = 0 @@ -292,9 +293,10 @@ def findrenames(repo, added, removed, th if lengths: myscore = equal*2.0 / lengths if myscore >= bestscore: - bestname, bestscore = r, myscore - if bestname: - yield bestname, a, 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: