Mercurial > public > mercurial-scm > hg
comparison mercurial/streamclone.py @ 27707:14f5ea7cc4c2
streamclone: use context manager for writing files
These are the file writes that have the most to gain from background
I/O. Plug in a context manager so I can design the background I/O
mechanism with context managers in mind.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 02 Jan 2016 15:09:58 -0800 |
parents | 9fea6b38a8da |
children | 9a1f3f9bac5d |
comparison
equal
deleted
inserted
replaced
27706:22e362da27cf | 27707:14f5ea7cc4c2 |
---|---|
317 _('unexpected response from remote server:'), l) | 317 _('unexpected response from remote server:'), l) |
318 if repo.ui.debugflag: | 318 if repo.ui.debugflag: |
319 repo.ui.debug('adding %s (%s)\n' % | 319 repo.ui.debug('adding %s (%s)\n' % |
320 (name, util.bytecount(size))) | 320 (name, util.bytecount(size))) |
321 # for backwards compat, name was partially encoded | 321 # for backwards compat, name was partially encoded |
322 ofp = repo.svfs(store.decodedir(name), 'w') | 322 with repo.svfs(store.decodedir(name), 'w') as ofp: |
323 for chunk in util.filechunkiter(fp, limit=size): | 323 for chunk in util.filechunkiter(fp, limit=size): |
324 handled_bytes += len(chunk) | 324 handled_bytes += len(chunk) |
325 repo.ui.progress(_('clone'), handled_bytes, total=bytecount) | 325 repo.ui.progress(_('clone'), handled_bytes, |
326 ofp.write(chunk) | 326 total=bytecount) |
327 ofp.close() | 327 ofp.write(chunk) |
328 tr.close() | 328 tr.close() |
329 finally: | 329 finally: |
330 tr.release() | 330 tr.release() |
331 | 331 |
332 # Writing straight to files circumvented the inmemory caches | 332 # Writing straight to files circumvented the inmemory caches |