localrepo: use context manager for lock and transaction in commitctx()
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 24 Sep 2018 14:46:37 -0700
changeset 41364 0132221c25cd
parent 41363 b87a009d1b3b
child 41365 876494fd967d
localrepo: use context manager for lock and transaction in commitctx() Differential Revision: https://phab.mercurial-scm.org/D5624
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Wed Jan 16 17:34:59 2019 -0800
+++ b/mercurial/localrepo.py	Mon Sep 24 14:46:37 2018 -0700
@@ -2502,13 +2502,10 @@
         from p1 or p2 are excluded from the committed ctx.files().
         """
 
-        tr = None
         p1, p2 = ctx.p1(), ctx.p2()
         user = ctx.user()
 
-        lock = self.lock()
-        try:
-            tr = self.transaction("commit")
+        with self.lock(), self.transaction("commit") as tr:
             trp = weakref.proxy(tr)
 
             if ctx.manifestnode():
@@ -2605,12 +2602,7 @@
                 #
                 # if minimal phase was 0 we don't need to retract anything
                 phases.registernew(self, tr, targetphase, [n])
-            tr.close()
             return n
-        finally:
-            if tr:
-                tr.release()
-            lock.release()
 
     @unfilteredmethod
     def destroying(self):