Patchwork D622: copytrace: move the default copytracing algorithm in a new function

login
register
mail settings
Submitter phabricator
Date Sept. 6, 2017, 2:51 p.m.
Message ID <5dec02603324ee7fa1859f91483de5ba@localhost.localdomain>
Download mbox | patch
Permalink /patch/23692/
State Not Applicable
Headers show

Comments

phabricator - Sept. 6, 2017, 2:51 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGb4b196092cc3: copytrace: move the default copytracing algorithm in a new function (authored by pulkit).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D622?vs=1602&id=1632

REVISION DETAIL
  https://phab.mercurial-scm.org/D622

AFFECTED FILES
  mercurial/copies.py
  tests/test-copy-move-merge.t

CHANGE DETAILS




To: pulkit, #hg-reviewers, yuja
Cc: yuja, mercurial-devel

Patch

diff --git a/tests/test-copy-move-merge.t b/tests/test-copy-move-merge.t
--- a/tests/test-copy-move-merge.t
+++ b/tests/test-copy-move-merge.t
@@ -1,3 +1,6 @@ 
+Test for the full copytracing algorithm
+=======================================
+
   $ hg init t
   $ cd t
 
diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -306,9 +306,13 @@ 
 
 def mergecopies(repo, c1, c2, base):
     """
-    The basic algorithm for copytracing. Copytracing is used in commands like
-    rebase, merge, unshelve, etc to merge files that were moved/ copied in one
-    merge parent and modified in another. For example:
+    The function calling different copytracing algorithms on the basis of config
+    which find moves and copies between context c1 and c2 that are relevant for
+    merging. 'base' will be used as the merge base.
+
+    Copytracing is used in commands like rebase, merge, unshelve, etc to merge
+    files that were moved/ copied in one merge parent and modified in another.
+    For example:
 
     o          ---> 4 another commit
     |
@@ -324,13 +328,6 @@ 
 
     ```other changed <file> which local deleted```
 
-    If copytrace is enabled, this function finds all the new files that were
-    added from merge base up to the top commit (here 4), and for each file it
-    checks if this file was copied from another file (a.txt in the above case).
-
-    Find moves and copies between context c1 and c2 that are relevant
-    for merging. 'base' will be used as the merge base.
-
     Returns five dicts: "copy", "movewithdir", "diverge", "renamedelete" and
     "dirmove".
 
@@ -360,12 +357,24 @@ 
     if c2.node() is None and c1.node() == repo.dirstate.p1():
         return repo.dirstate.copies(), {}, {}, {}, {}
 
+    copytracing = repo.ui.config('experimental', 'copytrace')
+
     # Copy trace disabling is explicitly below the node == p1 logic above
     # because the logic above is required for a simple copy to be kept across a
     # rebase.
-    if repo.ui.config('experimental', 'copytrace') == 'off':
+    if copytracing == 'off':
         return {}, {}, {}, {}, {}
+    else:
+        return _fullcopytracing(repo, c1, c2, base)
 
+def _fullcopytracing(repo, c1, c2, base):
+    """ The full copytracing algorithm which finds all the new files that were
+    added from merge base up to the top commit and for each file it checks if
+    this file was copied from another file.
+
+    This is pretty slow when a lot of changesets are involved but will track all
+    the copies.
+    """
     # In certain scenarios (e.g. graft, update or rebase), base can be
     # overridden We still need to know a real common ancestor in this case We
     # can't just compute _c1.ancestor(_c2) and compare it to ca, because there