Patchwork [6,of,7,v2] merge: migrate to context manager for changing dirstate parents

login
register
mail settings
Submitter Augie Fackler
Date May 19, 2017, 9:38 p.m.
Message ID <bf1e831b74a414ce05f0.1495229926@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/20742/
State Accepted
Headers show

Comments

Augie Fackler - May 19, 2017, 9:38 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1495141884 14400
#      Thu May 18 17:11:24 2017 -0400
# Node ID bf1e831b74a414ce05f006176c0f1d79a6f8dcd0
# Parent  5bd022476c63199c76166cb6157b5923181a5290
merge: migrate to context manager for changing dirstate parents

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1696,15 +1696,14 @@  def update(repo, node, branchmerge, forc
         stats = applyupdates(repo, actions, wc, p2, overwrite, labels=labels)
 
         if not partial:
-            repo.dirstate.beginparentchange()
-            repo.setparents(fp1, fp2)
-            recordupdates(repo, actions, branchmerge)
-            # update completed, clear state
-            util.unlink(repo.vfs.join('updatestate'))
+            with repo.dirstate.parentchange():
+                repo.setparents(fp1, fp2)
+                recordupdates(repo, actions, branchmerge)
+                # update completed, clear state
+                util.unlink(repo.vfs.join('updatestate'))
 
-            if not branchmerge:
-                repo.dirstate.setbranch(p2.branch())
-            repo.dirstate.endparentchange()
+                if not branchmerge:
+                    repo.dirstate.setbranch(p2.branch())
 
     if not partial:
         repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
@@ -1742,10 +1741,9 @@  def graft(repo, ctx, pctx, labels, keepp
         parents.remove(pctx)
         pother = parents[0].node()
 
-    repo.dirstate.beginparentchange()
-    repo.setparents(repo['.'].node(), pother)
-    repo.dirstate.write(repo.currenttransaction())
-    # fix up dirstate for copies and renames
-    copies.duplicatecopies(repo, ctx.rev(), pctx.rev())
-    repo.dirstate.endparentchange()
+    with repo.dirstate.parentchange():
+        repo.setparents(repo['.'].node(), pother)
+        repo.dirstate.write(repo.currenttransaction())
+        # fix up dirstate for copies and renames
+        copies.duplicatecopies(repo, ctx.rev(), pctx.rev())
     return stats