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

login
register
mail settings
Submitter Boris Feld
Date June 7, 2018, 2:11 p.m.
Message ID <ade0ce417ac654814fa0.1528380667@Laptop-Boris.lan>
Download mbox | patch
Permalink /patch/32002/
State Accepted
Headers show

Comments

Boris Feld - June 7, 2018, 2:11 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@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

Patch

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)