[PATCH 3 of 6] scmutil.addremove: factor out code to find renames

Siddharth Agarwal sid0 at fb.com
Mon May 6 19:12:29 CDT 2013


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1365031961 25200
#      Wed Apr 03 16:32:41 2013 -0700
# Node ID bc4a797e7206ac8180f20cebf6a3c0ea927e127d
# Parent  7873f7c6b8a355aa6f710b9af682275a12f241e4
scmutil.addremove: factor out code to find renames

This code will be used in a different context in upcoming patches.

diff -r 7873f7c6b8a3 -r bc4a797e7206 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 @@ def addremove(repo, pats=[], opts={}, dr
                 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 @@ def _interestingfiles(repo, matcher):
 
     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.


More information about the Mercurial-devel mailing list