Patchwork [5,of,7] localrepo: migrate to context manager for changing dirstate parents

login
register
mail settings
Submitter Augie Fackler
Date May 18, 2017, 10:19 p.m.
Message ID <50ccaa80efc37023304c.1495145990@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/20697/
State Superseded
Headers show

Comments

Augie Fackler - May 18, 2017, 10:19 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1495141874 14400
#      Thu May 18 17:11:14 2017 -0400
# Node ID 50ccaa80efc37023304c32a12406cfee4771c0cc
# Parent  6b988519e85f29c9c273f30c742ca0877aa824a1
localrepo: migrate to context manager for changing dirstate parents

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -828,21 +828,20 @@  class localrepository(object):
         return self[changeid]
 
     def setparents(self, p1, p2=nullid):
-        self.dirstate.beginparentchange()
-        copies = self.dirstate.setparents(p1, p2)
-        pctx = self[p1]
-        if copies:
-            # Adjust copy records, the dirstate cannot do it, it
-            # requires access to parents manifests. Preserve them
-            # only for entries added to first parent.
-            for f in copies:
-                if f not in pctx and copies[f] in pctx:
-                    self.dirstate.copy(copies[f], f)
-        if p2 == nullid:
-            for f, s in sorted(self.dirstate.copies().items()):
-                if f not in pctx and s not in pctx:
-                    self.dirstate.copy(None, f)
-        self.dirstate.endparentchange()
+        with self.dirstate.parentchange():
+            copies = self.dirstate.setparents(p1, p2)
+            pctx = self[p1]
+            if copies:
+                # Adjust copy records, the dirstate cannot do it, it
+                # requires access to parents manifests. Preserve them
+                # only for entries added to first parent.
+                for f in copies:
+                    if f not in pctx and copies[f] in pctx:
+                        self.dirstate.copy(copies[f], f)
+            if p2 == nullid:
+                for f, s in sorted(self.dirstate.copies().items()):
+                    if f not in pctx and s not in pctx:
+                        self.dirstate.copy(None, f)
 
     def filectx(self, path, changeid=None, fileid=None):
         """changeid can be a changeset revision, node, or tag.