##// END OF EJS Templates
clonebundle: use context managers for lock and transaction
Martin von Zweigbergk -
r32843:a470bbb4 default
parent child Browse files
Show More
@@ -1989,29 +1989,21 b' def sortclonebundleentries(ui, entries):'
1989
1989
1990 def trypullbundlefromurl(ui, repo, url):
1990 def trypullbundlefromurl(ui, repo, url):
1991 """Attempt to apply a bundle from a URL."""
1991 """Attempt to apply a bundle from a URL."""
1992 lock = repo.lock()
1992 with repo.lock(), repo.transaction('bundleurl') as tr:
1993 try:
1994 tr = repo.transaction('bundleurl')
1995 try:
1993 try:
1996 try:
1994 fh = urlmod.open(ui, url)
1997 fh = urlmod.open(ui, url)
1995 cg = readbundle(ui, fh, 'stream')
1998 cg = readbundle(ui, fh, 'stream')
1999
1996
2000 if isinstance(cg, bundle2.unbundle20):
1997 if isinstance(cg, bundle2.unbundle20):
2001 bundle2.processbundle(repo, cg, lambda: tr)
1998 bundle2.processbundle(repo, cg, lambda: tr)
2002 elif isinstance(cg, streamclone.streamcloneapplier):
1999 elif isinstance(cg, streamclone.streamcloneapplier):
2003 cg.apply(repo)
2000 cg.apply(repo)
2004 else:
2001 else:
2005 cg.apply(repo, 'clonebundles', url)
2002 cg.apply(repo, 'clonebundles', url)
2006 tr.close()
2003 return True
2007 return True
2004 except urlerr.httperror as e:
2008 except urlerr.httperror as e:
2005 ui.warn(_('HTTP error fetching bundle: %s\n') % str(e))
2009 ui.warn(_('HTTP error fetching bundle: %s\n') % str(e))
2006 except urlerr.urlerror as e:
2010 except urlerr.urlerror as e:
2007 ui.warn(_('error fetching bundle: %s\n') % e.reason)
2011 ui.warn(_('error fetching bundle: %s\n') % e.reason)
2012
2008
2013 return False
2009 return False
2014 finally:
2015 tr.release()
2016 finally:
2017 lock.release()
General Comments 0
You need to be logged in to leave comments. Login now