diff --git a/mercurial/exchange.py b/mercurial/exchange.py --- a/mercurial/exchange.py +++ b/mercurial/exchange.py @@ -459,7 +459,9 @@ def push(repo, remote, force=False, revs 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 @@ def push(repo, remote, force=False, revs _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