comparison mercurial/streamclone.py @ 27870:ed9950ba091e

with: use context manager for transaction in consumev1
author Bryan O'Sullivan <bryano@fb.com>
date Fri, 15 Jan 2016 13:14:49 -0800
parents f55a5ace8e69
children 319b0bf6ecc9
comparison
equal deleted inserted replaced
27869:76ecf0227ea5 27870:ed9950ba091e
295 (filecount, util.bytecount(bytecount))) 295 (filecount, util.bytecount(bytecount)))
296 handled_bytes = 0 296 handled_bytes = 0
297 repo.ui.progress(_('clone'), 0, total=bytecount) 297 repo.ui.progress(_('clone'), 0, total=bytecount)
298 start = time.time() 298 start = time.time()
299 299
300 tr = repo.transaction('clone') 300 with repo.transaction('clone'):
301 try:
302 for i in xrange(filecount): 301 for i in xrange(filecount):
303 # XXX doesn't support '\n' or '\r' in filenames 302 # XXX doesn't support '\n' or '\r' in filenames
304 l = fp.readline() 303 l = fp.readline()
305 try: 304 try:
306 name, size = l.split('\0', 1) 305 name, size = l.split('\0', 1)
316 for chunk in util.filechunkiter(fp, limit=size): 315 for chunk in util.filechunkiter(fp, limit=size):
317 handled_bytes += len(chunk) 316 handled_bytes += len(chunk)
318 repo.ui.progress(_('clone'), handled_bytes, 317 repo.ui.progress(_('clone'), handled_bytes,
319 total=bytecount) 318 total=bytecount)
320 ofp.write(chunk) 319 ofp.write(chunk)
321 tr.close()
322 finally:
323 tr.release()
324 320
325 # Writing straight to files circumvented the inmemory caches 321 # Writing straight to files circumvented the inmemory caches
326 repo.invalidate() 322 repo.invalidate()
327 323
328 elapsed = time.time() - start 324 elapsed = time.time() - start