changeset 38498:d4be8ea8f22d

merge: add a 'keepconflictparent' argument to graft Before this change, `merge.graft` was always dropping the "grafted" changeset from the parent. This is impractical in case of conflict as the second parent can be useful to help with conflict resolution. We add a new boolean parameter to control this behavior. This will make using `merge.graft` directly in shelve practicable. Differential Revision: https://phab.mercurial-scm.org/D3692
author Boris Feld <boris.feld@octobus.net>
date Tue, 29 May 2018 00:26:20 +0200
parents da2a7d8354b2
children ba6d2c32f34a
files mercurial/merge.py
diffstat 1 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/merge.py	Thu Jun 28 18:07:22 2018 -0700
+++ b/mercurial/merge.py	Tue May 29 00:26:20 2018 +0200
@@ -2194,7 +2194,8 @@
                   error=stats.unresolvedcount)
     return stats
 
-def graft(repo, ctx, pctx, labels, keepparent=False):
+def graft(repo, ctx, pctx, labels, keepparent=False,
+          keepconflictparent=False):
     """Do a graft-like merge.
 
     This is a merge where the merge ancestor is chosen such that one
@@ -2207,6 +2208,7 @@
     pctx - merge base, usually ctx.p1()
     labels - merge labels eg ['local', 'graft']
     keepparent - keep second parent if any
+    keepparent - if unresolved, keep parent used for the merge
 
     """
     # If we're grafting a descendant onto an ancestor, be sure to pass
@@ -2220,11 +2222,15 @@
     stats = update(repo, ctx.node(), True, True, pctx.node(),
                    mergeancestor=mergeancestor, labels=labels)
 
-    pother = nullid
-    parents = ctx.parents()
-    if keepparent and len(parents) == 2 and pctx in parents:
-        parents.remove(pctx)
-        pother = parents[0].node()
+
+    if keepconflictparent and stats.unresolvedcount:
+        pother = ctx.node()
+    else:
+        pother = nullid
+        parents = ctx.parents()
+        if keepparent and len(parents) == 2 and pctx in parents:
+            parents.remove(pctx)
+            pother = parents[0].node()
 
     with repo.dirstate.parentchange():
         repo.setparents(repo['.'].node(), pother)