Patchwork [5,of,7] mergecopies: process rotated-DAG divergences from _checkcopies

login
register
mail settings
Submitter Gábor Stefanik
Date Oct. 7, 2016, 12:31 p.m.
Message ID <90c51e2c2df282184f2a.1475843498@waste.org>
Download mbox | patch
Permalink /patch/16880/
State Changes Requested
Delegated to: Matt Mackall
Headers show

Comments

Gábor Stefanik - Oct. 7, 2016, 12:31 p.m.
# HG changeset patch
# User Gábor Stefanik <gabor.stefanik@nng.com>
# Date 1475578314 -7200
#      Tue Oct 04 12:51:54 2016 +0200
# Node ID 90c51e2c2df282184f2a991fe690dceac4c79aa8
# Parent  76b744060475aa20751310e9e2eab76ab78b9cc6
mergecopies: process rotated-DAG divergences from _checkcopies

Patch

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -321,6 +321,7 @@ 
     if repo.ui.configbool('experimental', 'disablecopytrace'):
         return {}, {}, {}, {}
 
+    dirtyc1 = False # dummy bool for later use
     limit = _findlimit(repo, c1.rev(), c2.rev())
     if limit is None:
         # no common ancestor, no copies
@@ -357,6 +358,27 @@ 
     movewithdir = dict(movewithdir1.items() + movewithdir2.items())
     fullcopy = dict(fullcopy1.items() + fullcopy2.items())
 
+    # combine partial copy paths discovered in the previous step
+    def _combinecopies(copyfrom, copyto, diverge):
+        remainder = {}
+        for f in copyfrom:
+            if f in copyto:
+                copy[copyto[f]] = copyfrom[f]
+                del copyto[f]
+        for f in incompletediverge:
+            assert f not in diverge
+            ic = incompletediverge[f]
+            if ic[0] in copyto:
+                diverge[f] = [copyto[ic[0]], ic[1]]
+            else:
+                remainder[f] = ic
+        return remainder
+
+    if dirtyc1:
+        _combinecopies(incomplete2, incomplete1, diverge)
+    else:
+        _combinecopies(incomplete1, incomplete2, diverge)
+
     renamedelete = {}
     renamedeleteset = set()
     divergeset = set()
@@ -383,6 +405,18 @@ 
                      _fullcopy, incomplete1, incompletediverge)
         _checkcopies(c2, f, m2, m1, ca, ca, False, limit, bothdiverge, _copy,
                      _fullcopy, incomplete2, incompletediverge)
+    if dirtyc1:
+        assert incomplete2 == {}
+        remainder = _combinecopies({}, incomplete1, bothdiverge)
+    else:
+        assert incomplete1 == {}
+        remainder = _combinecopies({}, incomplete2, bothdiverge)
+    for f in remainder:
+        assert f not in bothdiverge
+        ic = remainder[f]
+        if ic[0] in (m1 if dirtyc1 else m2):
+            # backed-out rename on one side, but watch out for deleted files
+            bothdiverge[f] = ic
     for of, fl in bothdiverge.items():
         if len(fl) == 2 and fl[0] == fl[1]:
             copy[fl[0]] = of # not actually divergent, just matching renames