[PATCH 14 of 16] merge: keep track of all ancestors in update, select in calculateupdates

Mads Kiilerich mads at kiilerich.com
Sun Mar 2 13:15:47 CST 2014


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1393552352 -3600
#      Fri Feb 28 02:52:32 2014 +0100
# Node ID 2a40d688a6d74c7cf6aad31ed471098364ac73ad
# Parent  b9fc8516a99c48202c0cbd52798d3da206aa65ca
merge: keep track of all ancestors in update, select in calculateupdates

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -365,10 +365,10 @@ def overridecheckunknownfile(origfn, rep
 # Finally, the merge.applyupdates function will then take care of
 # writing the files into the working copy and lfcommands.updatelfiles
 # will update the largefiles.
-def overridecalculateupdates(origfn, repo, p1, p2, pa, branchmerge, force,
+def overridecalculateupdates(origfn, repo, p1, p2, pas, branchmerge, force,
                              partial, acceptremote, followcopies):
     overwrite = force and not branchmerge
-    actions = origfn(repo, p1, p2, pa, branchmerge, force, partial,
+    actions = origfn(repo, p1, p2, pas, branchmerge, force, partial,
                      acceptremote, followcopies)
 
     if overwrite:
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -663,9 +663,13 @@ def applyupdates(repo, actions, wctx, mc
 
     return updated, merged, removed, unresolved
 
-def calculateupdates(repo, wctx, mctx, ancestor, branchmerge, force, partial,
+def calculateupdates(repo, wctx, mctx, ancestors, branchmerge, force, partial,
                      acceptremote, followcopies):
-    "Calculate the actions needed to merge mctx into wctx using ancestor"
+    "Calculate the actions needed to merge mctx into wctx using ancestors"
+
+    ancestor = ancestors[0]
+    if len(ancestors) > 1:
+        ancestor = wctx.ancestor(mctx)
 
     actions = manifestmerge(repo, wctx, mctx,
                              ancestor,
@@ -819,9 +823,9 @@ def update(repo, node, branchmerge, forc
         wc = repo[None]
         pl = wc.parents()
         p1 = pl[0]
-        pa = None
+        pas = [None]
         if ancestor:
-            pa = repo[ancestor]
+            pas = [repo[ancestor]]
 
         if node is None:
             # Here is where we should consider bookmarks, divergent bookmarks,
@@ -860,13 +864,14 @@ def update(repo, node, branchmerge, forc
                     # get the max revision for the given successors set,
                     # i.e. the 'tip' of a set
                     node = repo.revs("max(%ln)", successors)[0]
-                    pa = p1
+                    pas = [p1]
 
         overwrite = force and not branchmerge
 
         p2 = repo[node]
-        if pa is None:
-            pa = p1.ancestor(p2)
+        if pas[0] is None:
+            ancs = repo.changelog.commonancestors(p1.node(), p2.node())
+            pas = [repo[anc] for anc in (sorted(ancs) or [nullid])]
 
         fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2)
 
@@ -874,10 +879,10 @@ def update(repo, node, branchmerge, forc
         if not overwrite and len(pl) > 1:
             raise util.Abort(_("outstanding uncommitted merges"))
         if branchmerge:
-            if pa == p2:
+            if pas == [p2]:
                 raise util.Abort(_("merging with a working directory ancestor"
                                    " has no effect"))
-            elif pa == p1:
+            elif pas == [p1]:
                 if not mergeancestor and p1.branch() == p2.branch():
                     raise util.Abort(_("nothing to merge"),
                                      hint=_("use 'hg update' "
@@ -897,7 +902,7 @@ def update(repo, node, branchmerge, forc
                 repo.hook('update', parent1=xp2, parent2='', error=0)
                 return 0, 0, 0, 0
 
-            if pa not in (p1, p2):  # nonlinear
+            if pas not in ([p1], [p2]):  # nonlinear
                 dirty = wc.dirty(missing=True)
                 if dirty or onode is None:
                     # Branching is a bit strange to ensure we do the minimal
@@ -905,7 +910,7 @@ def update(repo, node, branchmerge, forc
                     foreground = obsolete.foreground(repo, [p1.node()])
                     # note: the <node> variable contains a random identifier
                     if repo[node].node() in foreground:
-                        pa = p1  # allow updating to successors
+                        pas = [p1]  # allow updating to successors
                     elif dirty:
                         msg = _("uncommitted changes")
                         if onode is None:
@@ -921,20 +926,20 @@ def update(repo, node, branchmerge, forc
                         raise util.Abort(msg, hint=hint)
                 else:
                     # Allow jumping branches if clean and specific rev given
-                    pa = p1
+                    pas = [p1]
 
         followcopies = False
         if overwrite:
-            pa = wc
-        elif pa == p2: # backwards
-            pa = wc.p1()
+            pas = [wc]
+        elif pas == [p2]: # backwards
+            pas = [wc.p1()]
         elif not branchmerge and not wc.dirty(missing=True):
             pass
-        elif pa and repo.ui.configbool("merge", "followcopies", True):
+        elif pas[0] and repo.ui.configbool("merge", "followcopies", True):
             followcopies = True
 
         ### calculate phase
-        actions = calculateupdates(repo, wc, p2, pa, branchmerge, force,
+        actions = calculateupdates(repo, wc, p2, pas, branchmerge, force,
                                    partial, mergeancestor, followcopies)
 
         ### apply phase


More information about the Mercurial-devel mailing list