mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 00:14:35 +03:00
clonebundle: use context managers for lock and transaction
This commit is contained in:
parent
10f4660637
commit
c8f8b266e4
@ -1989,29 +1989,21 @@ def sortclonebundleentries(ui, entries):
|
||||
|
||||
def trypullbundlefromurl(ui, repo, url):
|
||||
"""Attempt to apply a bundle from a URL."""
|
||||
lock = repo.lock()
|
||||
try:
|
||||
tr = repo.transaction('bundleurl')
|
||||
with repo.lock(), repo.transaction('bundleurl') as tr:
|
||||
try:
|
||||
try:
|
||||
fh = urlmod.open(ui, url)
|
||||
cg = readbundle(ui, fh, 'stream')
|
||||
fh = urlmod.open(ui, url)
|
||||
cg = readbundle(ui, fh, 'stream')
|
||||
|
||||
if isinstance(cg, bundle2.unbundle20):
|
||||
bundle2.processbundle(repo, cg, lambda: tr)
|
||||
elif isinstance(cg, streamclone.streamcloneapplier):
|
||||
cg.apply(repo)
|
||||
else:
|
||||
cg.apply(repo, 'clonebundles', url)
|
||||
tr.close()
|
||||
return True
|
||||
except urlerr.httperror as e:
|
||||
ui.warn(_('HTTP error fetching bundle: %s\n') % str(e))
|
||||
except urlerr.urlerror as e:
|
||||
ui.warn(_('error fetching bundle: %s\n') % e.reason)
|
||||
if isinstance(cg, bundle2.unbundle20):
|
||||
bundle2.processbundle(repo, cg, lambda: tr)
|
||||
elif isinstance(cg, streamclone.streamcloneapplier):
|
||||
cg.apply(repo)
|
||||
else:
|
||||
cg.apply(repo, 'clonebundles', url)
|
||||
return True
|
||||
except urlerr.httperror as e:
|
||||
ui.warn(_('HTTP error fetching bundle: %s\n') % str(e))
|
||||
except urlerr.urlerror as e:
|
||||
ui.warn(_('error fetching bundle: %s\n') % e.reason)
|
||||
|
||||
return False
|
||||
finally:
|
||||
tr.release()
|
||||
finally:
|
||||
lock.release()
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user