Patchwork D3692: merge: add a 'keepconflictparent' argument to graft

login
register
mail settings
Submitter phabricator
Date June 5, 2018, 10:58 a.m.
Message ID <differential-rev-PHID-DREV-rb5aexixc7jrmirxfb63-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/31976/
State Superseded
Headers show

Comments

phabricator - June 5, 2018, 10:58 a.m.
lothiraldan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3692

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS




To: lothiraldan, #hg-reviewers
Cc: mercurial-devel
phabricator - June 29, 2018, 7:07 p.m.
pulkit accepted this revision.
pulkit added a comment.


  Looks like this will help fixing issue5927 <https://bz.mercurial-scm.org/show_bug.cgi?id=5927> too.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3692

To: lothiraldan, #hg-reviewers, pulkit
Cc: pulkit, mercurial-devel

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -2207,7 +2207,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
@@ -2220,6 +2221,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
@@ -2233,11 +2235,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)