# HG changeset patch # User Siddharth Agarwal # Date 1365031961 25200 # Node ID 7a1292523db31e684d02cc9656893627b8d51288 # Parent 2487a594b439d4db87b94338b70e791736016026 scmutil.addremove: factor out code to find renames This code will be used in a different context in upcoming patches. diff -r 2487a594b439 -r 7a1292523db3 mercurial/scmutil.py --- a/mercurial/scmutil.py Wed Apr 03 15:32:15 2013 -0700 +++ b/mercurial/scmutil.py Wed Apr 03 16:32:41 2013 -0700 @@ -703,15 +703,8 @@ status = _('removing %s\n') % ((pats and rel) or abs) repo.ui.status(status) - renames = {} - if similarity > 0: - for old, new, score in similar.findrenames(repo, - added + unknown, removed + deleted, similarity): - if repo.ui.verbose or not m.exact(old) or not m.exact(new): - repo.ui.status(_('recording removal of %s as rename to %s ' - '(%d%% similar)\n') % - (m.rel(old), m.rel(new), score * 100)) - renames[new] = old + renames = _findrenames(repo, m, added + unknown, removed + deleted, + similarity) if not dry_run: wctx = repo[None] @@ -755,6 +748,21 @@ return added, unknown, deleted, removed +def _findrenames(repo, matcher, added, removed, similarity): + '''Find renames from removed files to added ones.''' + renames = {} + if similarity > 0: + for old, new, score in similar.findrenames(repo, added, removed, + similarity): + if (repo.ui.verbose or not matcher.exact(old) + or not matcher.exact(new)): + repo.ui.status(_('recording removal of %s as rename to %s ' + '(%d%% similar)\n') % + (matcher.rel(old), matcher.rel(new), + score * 100)) + renames[new] = old + return renames + def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None): """Update the dirstate to reflect the intent of copying src to dst. For different reasons it might not end with dst being marked as copied from src.