# HG changeset patch # User Boris Feld # Date 1527546380 -7200 # Node ID d4be8ea8f22db67a0cd6331a50f1d70f5ac980ea # Parent da2a7d8354b2e1c0e35ca926f445d45d9e143c17 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 -r da2a7d8354b2 -r d4be8ea8f22d mercurial/merge.py --- 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)