[PATCH 08 of 25 RFC] merge: add a 'keepconflictparent' argument to graft

Boris Feld boris.feld at octobus.net
Thu Jun 7 10:11:07 EDT 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1527546380 -7200
#      Tue May 29 00:26:20 2018 +0200
# Node ID ade0ce417ac654814fa0eda21637933f262ceac0
# Parent  0093905b9797a6f76730cd37a45a6f1b843c5b03
# EXP-Topic graftshelve
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r ade0ce417ac6
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

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -2207,7 +2207,8 @@ def update(repo, node, branchmerge, forc
                   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
@@ -2220,6 +2221,7 @@ def graft(repo, ctx, pctx, labels, keepp
     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
@@ -2233,11 +2235,15 @@ def graft(repo, ctx, pctx, labels, keepp
     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)


More information about the Mercurial-devel mailing list