Patchwork [09,of,16] merge: include ancestor node in merge actions

login
register
mail settings
Submitter Mads Kiilerich
Date March 2, 2014, 7:15 p.m.
Message ID <f35dafc5600776ed2382.1393787742@localhost.localdomain>
Download mbox | patch
Permalink /patch/3821/
State Accepted
Commit 003cb972178d8d8d6670ddf53917c11cf5e535c2
Headers show

Comments

Mads Kiilerich - March 2, 2014, 7:15 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1393551513 -3600
#      Fri Feb 28 02:38:33 2014 +0100
# Node ID f35dafc5600776ed238241565e5cbfa7e2dfd71c
# Parent  5ccd6ac8072b4d7077959cbe4bdf2b2f49488688
merge: include ancestor node in merge actions

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -280,7 +280,7 @@  def _checkcollision(repo, wmf, actions):
             pmmf.discard(f)
         pmmf.add(fd)
     def mergeop(f, args):
-        f2, fa, fd, move = args
+        f2, fa, fd, move, anc = args
         if move:
             pmmf.discard(f)
         pmmf.add(fd)
@@ -408,7 +408,8 @@  def manifestmerge(repo, wctx, p2, pa, br
             elif nol and n1 == a: # local only changed 'x'
                 actions.append((f, "g", (fl1,), "remote is newer"))
             else: # both changed something
-                actions.append((f, "m", (f, fa, f, False), "versions differ"))
+                actions.append((f, "m", (f, fa, f, False, pa.node()),
+                               "versions differ"))
         elif f in copied: # files we'll deal with on m2 side
             pass
         elif n1 and f in movewithdir: # directory rename
@@ -417,7 +418,7 @@  def manifestmerge(repo, wctx, p2, pa, br
                             "remote renamed directory to " + f2))
         elif n1 and f in copy:
             f2 = copy[f]
-            actions.append((f, "m", (f2, f2, f, False),
+            actions.append((f, "m", (f2, f2, f, False, pa.node()),
                             "local copied/moved to " + f2))
         elif n1 and f in ma: # clean, a different, no remote
             if n1 != ma[f]:
@@ -436,10 +437,10 @@  def manifestmerge(repo, wctx, p2, pa, br
         elif n2 and f in copy:
             f2 = copy[f]
             if f2 in m2:
-                actions.append((f2, "m", (f, f2, f, False),
+                actions.append((f2, "m", (f, f2, f, False, pa.node()),
                                 "remote copied to " + f))
             else:
-                actions.append((f2, "m", (f, f2, f, True),
+                actions.append((f2, "m", (f, f2, f, True, pa.node()),
                                 "remote moved to " + f))
         elif n2 and f not in ma:
             # local unknown, remote created: the logic is described by the
@@ -460,7 +461,7 @@  def manifestmerge(repo, wctx, p2, pa, br
                 different = _checkunknownfile(repo, wctx, p2, f)
                 if force and branchmerge and different:
                     # FIXME: This is wrong - f is not in ma ...
-                    actions.append((f, "m", (f, f, f, False),
+                    actions.append((f, "m", (f, f, f, False, pa.node()),
                                     "remote differs from untracked local"))
                 elif not force and different:
                     aborts.append((f, "ud"))
@@ -536,12 +537,11 @@  def getremove(repo, mctx, overwrite, arg
     if i > 0:
         yield i, f
 
-def applyupdates(repo, actions, wctx, mctx, actx, overwrite):
+def applyupdates(repo, actions, wctx, mctx, overwrite):
     """apply the merge action list to the working directory
 
     wctx is the working copy context
     mctx is the context to be merged into the working copy
-    actx is the context of the common ancestor
 
     Return a tuple of counts (updated, merged, removed, unresolved) that
     describes how many files were affected by the update.
@@ -558,18 +558,14 @@  def applyupdates(repo, actions, wctx, mc
         f, m, args, msg = a
         repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m))
         if m == "m": # merge
-            f2, fa, fd, move = args
+            f2, fa, fd, move, anc = args
             if fd == '.hgsubstate': # merged internally
                 continue
             repo.ui.debug("  preserving %s for resolve of %s\n" % (f, fd))
             fcl = wctx[f]
             fco = mctx[f2]
-            if mctx == actx: # backwards, use working dir parent as ancestor
-                if fcl.parents():
-                    fca = fcl.p1()
-                else:
-                    fca = repo.filectx(f, fileid=nullrev)
-            elif fa in actx:
+            actx = repo[anc]
+            if fa in actx:
                 fca = actx[fa]
             else:
                 fca = repo.filectx(f, fileid=nullrev)
@@ -623,7 +619,7 @@  def applyupdates(repo, actions, wctx, mc
         f, m, args, msg = a
         progress(_updating, z + i + 1, item=f, total=numupdates, unit=_files)
         if m == "m": # merge
-            f2, fa, fd, move = args
+            f2, fa, fd, move, anc = args
             if fd == '.hgsubstate': # subrepo states need updating
                 subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
                                  overwrite)
@@ -733,7 +729,7 @@  def recordupdates(repo, actions, branchm
             else:
                 repo.dirstate.normal(f)
         elif m == "m": # merge
-            f2, fa, fd, move = args
+            f2, fa, fd, move, anc = args
             if branchmerge:
                 # We've done a branch merge, mark this file as merged
                 # so that we properly record the merger later
@@ -939,7 +935,7 @@  def update(repo, node, branchmerge, forc
             # note that we're in the middle of an update
             repo.vfs.write('updatestate', p2.hex())
 
-        stats = applyupdates(repo, actions, wc, p2, pa, overwrite)
+        stats = applyupdates(repo, actions, wc, p2, overwrite)
 
         if not partial:
             repo.setparents(fp1, fp2)