exchange: simplify unbundle locking using context managers
Differential Revision: https://phab.mercurial-scm.org/D393
--- 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