D393: exchange: simplify unbundle locking using context managers

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Mon Aug 14 23:46:27 UTC 2017


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D393

AFFECTED FILES
  mercurial/exchange.py

CHANGE DETAILS

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -459,7 +459,9 @@
         msg = 'cannot lock source repository: %s\n' % err
         pushop.ui.debug(msg)
 
-    try:
+    with wlock or util.nullcontextmanager(), \
+            lock or util.nullcontextmanager(), \
+            pushop.trmanager or util.nullcontextmanager():
         pushop.repo.checkpush(pushop)
         _pushdiscovery(pushop)
         if not _forcebundle1(pushop):
@@ -469,16 +471,6 @@
         _pushobsolete(pushop)
         _pushbookmark(pushop)
 
-        if pushop.trmanager:
-            pushop.trmanager.close()
-    finally:
-        if pushop.trmanager:
-            pushop.trmanager.release()
-        if lock is not None:
-            lock.release()
-        if wlock is not None:
-            wlock.release()
-
     return pushop
 
 # list of steps to perform discovery before push



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list