Patchwork [2,of,7,v2] mq: 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 <f495181d4e42e53d4f3b.1495229922@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/20739/
State Accepted
Headers show

Comments

Augie Fackler - May 19, 2017, 9:38 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1495141853 14400
#      Thu May 18 17:10:53 2017 -0400
# Node ID f495181d4e42e53d4f3b1a9ca5132ff6f7703890
# Parent  2f0dd5450eedbf11e49a529544654b3b399310c2
mq: migrate to context manager for changing dirstate parents

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -932,14 +932,13 @@  class queue(object):
                         merged.append(f)
                     else:
                         removed.append(f)
-                repo.dirstate.beginparentchange()
-                for f in removed:
-                    repo.dirstate.remove(f)
-                for f in merged:
-                    repo.dirstate.merge(f)
-                p1, p2 = repo.dirstate.parents()
-                repo.setparents(p1, merge)
-                repo.dirstate.endparentchange()
+                with repo.dirstate.parentchange():
+                    for f in removed:
+                        repo.dirstate.remove(f)
+                    for f in merged:
+                        repo.dirstate.merge(f)
+                    p1, p2 = repo.dirstate.parents()
+                    repo.setparents(p1, merge)
 
             if all_files and '.hgsubstate' in all_files:
                 wctx = repo[None]
@@ -1580,16 +1579,15 @@  class queue(object):
                 if keepchanges and tobackup:
                     raise error.Abort(_("local changes found, qrefresh first"))
                 self.backup(repo, tobackup)
-                repo.dirstate.beginparentchange()
-                for f in a:
-                    repo.wvfs.unlinkpath(f, ignoremissing=True)
-                    repo.dirstate.drop(f)
-                for f in m + r:
-                    fctx = ctx[f]
-                    repo.wwrite(f, fctx.data(), fctx.flags())
-                    repo.dirstate.normal(f)
-                repo.setparents(qp, nullid)
-                repo.dirstate.endparentchange()
+                with repo.dirstate.parentchange():
+                    for f in a:
+                        repo.wvfs.unlinkpath(f, ignoremissing=True)
+                        repo.dirstate.drop(f)
+                    for f in m + r:
+                        fctx = ctx[f]
+                        repo.wwrite(f, fctx.data(), fctx.flags())
+                        repo.dirstate.normal(f)
+                    repo.setparents(qp, nullid)
             for patch in reversed(self.applied[start:end]):
                 self.ui.status(_("popping %s\n") % patch.name)
             del self.applied[start:end]