exchange: use context manager for locks and transaction in unbundle()
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 10 Jan 2018 11:02:20 -0800
changeset 35578 86f9aabed67b
parent 35577 ac7ee75ee664
child 35579 15ddf83fbf84
exchange: use context manager for locks and transaction in unbundle() Note that the transactionmanager doesn't actually create a transaction -- that is done the first time .transaction() is called on it (if at all). Consequently, .close() and .release() won't do anything if no transaction has been created. This makes it a little unusual, but it still works as a context manager. Differential Revision: https://phab.mercurial-scm.org/D1841
mercurial/exchange.py
--- a/mercurial/exchange.py	Wed Jan 10 10:49:12 2018 -0800
+++ b/mercurial/exchange.py	Wed Jan 10 11:02:20 2018 -0800
@@ -1345,11 +1345,8 @@
                     " %s") % (', '.join(sorted(missing)))
             raise error.Abort(msg)
 
-    wlock = lock = None
-    try:
-        wlock = pullop.repo.wlock()
-        lock = pullop.repo.lock()
-        pullop.trmanager = transactionmanager(repo, 'pull', remote.url())
+    pullop.trmanager = transactionmanager(repo, 'pull', remote.url())
+    with repo.wlock(), repo.lock(), pullop.trmanager:
         # This should ideally be in _pullbundle2(). However, it needs to run
         # before discovery to avoid extra work.
         _maybeapplyclonebundle(pullop)
@@ -1361,9 +1358,6 @@
         _pullphase(pullop)
         _pullbookmarks(pullop)
         _pullobsolete(pullop)
-        pullop.trmanager.close()
-    finally:
-        lockmod.release(pullop.trmanager, lock, wlock)
 
     # storing remotenames
     if repo.ui.configbool('experimental', 'remotenames'):