# HG changeset patch # User Martin von Zweigbergk # Date 1537825597 25200 # Node ID 0132221c25cdb980e12151fa53b92b633d2b003c # Parent b87a009d1b3b5776ee8ab256a048d816c990d274 localrepo: use context manager for lock and transaction in commitctx() Differential Revision: https://phab.mercurial-scm.org/D5624 diff -r b87a009d1b3b -r 0132221c25cd 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):