Patchwork D8026: graft: let caller pass in overlayworkingctx to merge.graft()

login
register
mail settings
Submitter phabricator
Date Jan. 28, 2020, 11:53 p.m.
Message ID <differential-rev-PHID-DREV-cd5urlqj37alre6pcrzx-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44714/
State Superseded
Headers show

Comments

phabricator - Jan. 28, 2020, 11:53 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Passing in a different `wctx` than `repo[None]` is useful because it
  allows the caller to decide to not touch the working directory.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -2578,7 +2578,13 @@ 
 
 
 def graft(
-    repo, ctx, base, labels=None, keepparent=False, keepconflictparent=False
+    repo,
+    ctx,
+    base,
+    labels=None,
+    keepparent=False,
+    keepconflictparent=False,
+    wctx=None,
 ):
     """Do a graft-like merge.
 
@@ -2601,7 +2607,7 @@ 
     # to copy commits), and 2) informs update that the incoming changes are
     # newer than the destination so it doesn't prompt about "remote changed foo
     # which local deleted".
-    wctx = repo[None]
+    wctx = wctx or repo[None]
     pctx = wctx.p1()
     mergeancestor = repo.changelog.isancestor(pctx.node(), ctx.node())
 
@@ -2613,6 +2619,7 @@ 
         base.node(),
         mergeancestor=mergeancestor,
         labels=labels,
+        wc=wctx,
     )
 
     if keepconflictparent and stats.unresolvedcount:
@@ -2627,11 +2634,16 @@ 
     if pother == pctx.node():
         pother = nullid
 
-    with repo.dirstate.parentchange():
-        repo.setparents(pctx.node(), pother)
-        repo.dirstate.write(repo.currenttransaction())
+    if wctx.isinmemory():
+        wctx.setparents(pctx.node(), pother)
         # fix up dirstate for copies and renames
         copies.graftcopies(wctx, ctx, base)
+    else:
+        with repo.dirstate.parentchange():
+            repo.setparents(pctx.node(), pother)
+            repo.dirstate.write(repo.currenttransaction())
+            # fix up dirstate for copies and renames
+            copies.graftcopies(wctx, ctx, base)
     return stats