mercurial/copies.py
changeset 30203 b94b92f0c683
parent 30202 a005c33d0bd7
child 30204 1894c830ee74
--- a/mercurial/copies.py	Tue Oct 04 12:51:54 2016 +0200
+++ b/mercurial/copies.py	Tue Oct 11 04:25:59 2016 +0200
@@ -413,10 +413,10 @@
                                       baselabel='topological common ancestor')
 
     for f in u1u:
-        _checkcopies(c1, f, m1, m2, base, tca, limit, data1)
+        _checkcopies(c1, f, m1, m2, base, tca, dirtyc1, limit, data1)
 
     for f in u2u:
-        _checkcopies(c2, f, m2, m1, base, tca, limit, data2)
+        _checkcopies(c2, f, m2, m1, base, tca, dirtyc2, limit, data2)
 
     copy = dict(data1['copy'].items() + data2['copy'].items())
     fullcopy = dict(data1['fullcopy'].items() + data2['fullcopy'].items())
@@ -460,8 +460,8 @@
              'incompletediverge': bothincompletediverge
             }
     for f in bothnew:
-        _checkcopies(c1, f, m1, m2, base, tca, limit, both1)
-        _checkcopies(c2, f, m2, m1, base, tca, limit, both2)
+        _checkcopies(c1, f, m1, m2, base, tca, dirtyc1, limit, both1)
+        _checkcopies(c2, f, m2, m1, base, tca, dirtyc2, limit, both2)
     if dirtyc1:
         assert both2['incomplete'] == {}
         remainder = _combinecopies({}, both1['incomplete'], copy, bothdiverge,
@@ -590,7 +590,7 @@
     except StopIteration:
         return False
 
-def _checkcopies(ctx, f, m1, m2, base, tca, limit, data):
+def _checkcopies(ctx, f, m1, m2, base, tca, remotebase, limit, data):
     """
     check possible copies of f from m1 to m2
 
@@ -600,6 +600,7 @@
     m2 = the destination manifest
     base = the changectx used as a merge base
     tca = topological common ancestor for graft-like scenarios
+    remotebase = True if base is outside tca::ctx, False otherwise
     limit = the rev number to not search beyond
     data = dictionary of dictionary to store copy data. (see mergecopies)
 
@@ -619,7 +620,7 @@
     # In the case there is both backward and forward renames (before and after
     # the base) this is more complicated as we must detect a divergence.
     # We use 'backwards = False' in that case.
-    backwards = base != tca and f in mb
+    backwards = not remotebase and base != tca and f in mb
     getfctx = _makegetfctx(ctx)
 
     of = None
@@ -652,6 +653,10 @@
                 data['copy'][of] = f
             elif of in mb:
                 data['copy'][f] = of
+            elif remotebase: # special case: a <- b <- a -> b "ping-pong" rename
+                data['copy'][of] = f
+                del data['fullcopy'][f]
+                data['fullcopy'][of] = f
             else: # divergence w.r.t. graft CA on one side of topological CA
                 for sf in seen:
                     if sf in mb: