changeset 33794:389f7b17ffb3

exchange: simplify unbundle locking using context managers Differential Revision: https://phab.mercurial-scm.org/D393
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 28 Jul 2017 22:04:27 -0700
parents bbbbd3c30bfc
children cf300c1ad7bf
files mercurial/exchange.py
diffstat 1 files changed, 3 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/exchange.py	Fri Jul 28 22:42:10 2017 -0700
+++ b/mercurial/exchange.py	Fri Jul 28 22:04:27 2017 -0700
@@ -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