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

login
register
mail settings
Submitter Siddharth Agarwal
Date May 7, 2013, 12:12 a.m.
Message ID <bc4a797e7206ac8180f2.1367885549@sid0x220>
Download mbox | patch
Permalink /patch/1572/
State Accepted, archived
Commit 7a1292523db31e684d02cc9656893627b8d51288
Delegated to: Augie Fackler
Headers show

Comments

Siddharth Agarwal - May 7, 2013, 12:12 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@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.

Patch

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.