Patchwork D1841: exchange: use context manager for locks and transaction in unbundle()

login
register
mail settings
Submitter phabricator
Date Jan. 10, 2018, 7:23 p.m.
Message ID <differential-rev-PHID-DREV-fan2ps2rjwm5e22g6eoi-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/26645/
State Superseded
Headers show

Comments

phabricator - Jan. 10, 2018, 7:23 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/exchange.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -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'):