Patchwork [2,of,4] copy: move mergecopies file logic to a function

login
register
mail settings
Submitter Durham Goode
Date Feb. 3, 2015, 3:20 a.m.
Message ID <8241440835148535f6d7.1422933600@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/7621/
State Accepted
Headers show

Comments

Durham Goode - Feb. 3, 2015, 3:20 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1422408198 28800
#      Tue Jan 27 17:23:18 2015 -0800
# Node ID 8241440835148535f6d70f93affbb74fe2305436
# Parent  83bf8c0ecb425fb64903d93918227c162bca111d
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).

Patch

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -208,6 +208,22 @@  def pathcopies(x, y):
         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 @@  def mergecopies(repo, c1, c2, ca):
 
     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)