copy: move mergecopies file logic to a function
authorDurham Goode <durham@fb.com>
Tue, 27 Jan 2015 17:23:18 -0800
changeset 24010 a63c2b159df4
parent 24009 00d331763442
child 24011 d7d08337b3f6
copy: move mergecopies file logic to a function Moves the mergecopies nonoverlap logic to a separate function so that other extensions which may need to prefetch information about the files being processed have a hook point. This saves extensions from having to recompute this information themselves, and thus saves several seconds off of various commands (like rebase).
mercurial/copies.py
--- a/mercurial/copies.py	Mon Feb 02 16:19:35 2015 -0800
+++ b/mercurial/copies.py	Tue Jan 27 17:23:18 2015 -0800
@@ -208,6 +208,22 @@
         return _backwardrenames(x, y)
     return _chain(x, y, _backwardrenames(x, a), _forwardcopies(a, y))
 
+def _computenonoverlap(repo, m1, m2, ma):
+    """Computes the files exclusive to m1 and m2.
+    This is its own function so extensions can easily wrap this call to see what
+    files mergecopies is about to process.
+    """
+    u1 = _nonoverlap(m1, m2, ma)
+    u2 = _nonoverlap(m2, m1, ma)
+
+    if u1:
+        repo.ui.debug("  unmatched files in local:\n   %s\n"
+                      % "\n   ".join(u1))
+    if u2:
+        repo.ui.debug("  unmatched files in other:\n   %s\n"
+                      % "\n   ".join(u2))
+    return u1, u2
+
 def mergecopies(repo, c1, c2, ca):
     """
     Find moves and copies between context c1 and c2 that are relevant
@@ -261,15 +277,7 @@
 
     repo.ui.debug("  searching for copies back to rev %d\n" % limit)
 
-    u1 = _nonoverlap(m1, m2, ma)
-    u2 = _nonoverlap(m2, m1, ma)
-
-    if u1:
-        repo.ui.debug("  unmatched files in local:\n   %s\n"
-                      % "\n   ".join(u1))
-    if u2:
-        repo.ui.debug("  unmatched files in other:\n   %s\n"
-                      % "\n   ".join(u2))
+    u1, u2 = _computenonoverlap(repo, m1, m2, ma)
 
     for f in u1:
         checkcopies(ctx, f, m1, m2, ca, limit, diverge, copy, fullcopy)