changeset 19152:7a1292523db3

scmutil.addremove: factor out code to find renames This code will be used in a different context in upcoming patches.
author Siddharth Agarwal <sid0@fb.com>
date Wed, 03 Apr 2013 16:32:41 -0700
parents 2487a594b439
children 9a4e219bda89
files mercurial/scmutil.py
diffstat 1 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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.