Patchwork D393: exchange: simplify unbundle locking using context managers

login
register
mail settings
Submitter phabricator
Date Aug. 15, 2017, 6:14 a.m.
Message ID <81fc6b548e4add363b50fcb28ca09c41@localhost.localdomain>
Download mbox | patch
Permalink /patch/23011/
State Not Applicable
Headers show

Comments

phabricator - Aug. 15, 2017, 6:14 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG389f7b17ffb3: exchange: simplify unbundle locking using context managers (authored by martinvonz).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D393?vs=891&id=919

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

AFFECTED FILES
  mercurial/exchange.py

CHANGE DETAILS




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

Patch

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