backout: use context manager for dirstateguard
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 14 Jun 2018 15:28:32 -0700
changeset 38320 eef4668be8a3
parent 38319 0d6d0aa3c4bf
child 38321 9b1536b02221
backout: use context manager for dirstateguard Differential Revision: https://phab.mercurial-scm.org/D3743
mercurial/commands.py
--- a/mercurial/commands.py	Thu Jun 14 15:26:18 2018 -0700
+++ b/mercurial/commands.py	Thu Jun 14 15:28:32 2018 -0700
@@ -617,20 +617,16 @@
     bheads = repo.branchheads(branch)
     rctx = scmutil.revsingle(repo, hex(parent))
     if not opts.get('merge') and op1 != node:
-        dsguard = dirstateguard.dirstateguard(repo, 'backout')
-        try:
+        with dirstateguard.dirstateguard(repo, 'backout'):
             overrides = {('ui', 'forcemerge'): opts.get('tool', '')}
             with ui.configoverride(overrides, 'backout'):
                 stats = mergemod.update(repo, parent, True, True, node, False)
             repo.setparents(op1, op2)
-            dsguard.close()
-            hg._showstats(repo, stats)
-            if stats.unresolvedcount:
-                repo.ui.status(_("use 'hg resolve' to retry unresolved "
-                                 "file merges\n"))
-                return 1
-        finally:
-            lockmod.release(dsguard)
+        hg._showstats(repo, stats)
+        if stats.unresolvedcount:
+            repo.ui.status(_("use 'hg resolve' to retry unresolved "
+                             "file merges\n"))
+            return 1
     else:
         hg.clean(repo, node, show_stats=False)
         repo.dirstate.setbranch(branch)