Mercurial > hg-stable
changeset 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 | 22e362da27cf |
children | 60268a5f731a |
files | mercurial/streamclone.py |
diffstat | 1 files changed, 6 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/streamclone.py Sat Jan 02 15:19:47 2016 -0800 +++ b/mercurial/streamclone.py Sat Jan 02 15:09:58 2016 -0800 @@ -319,12 +319,12 @@ repo.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size))) # for backwards compat, name was partially encoded - ofp = repo.svfs(store.decodedir(name), 'w') - for chunk in util.filechunkiter(fp, limit=size): - handled_bytes += len(chunk) - repo.ui.progress(_('clone'), handled_bytes, total=bytecount) - ofp.write(chunk) - ofp.close() + with repo.svfs(store.decodedir(name), 'w') as ofp: + for chunk in util.filechunkiter(fp, limit=size): + handled_bytes += len(chunk) + repo.ui.progress(_('clone'), handled_bytes, + total=bytecount) + ofp.write(chunk) tr.close() finally: tr.release()