# HG changeset patch # User Gregory Szorc # Date 2016-01-02 23:09:58 # Node ID 14f5ea7cc4c23a549be95a53a7f3b18d6eea2512 # Parent 22e362da27cfca1d060e17c5bc7c04b300385f9f 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. diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py --- a/mercurial/streamclone.py +++ b/mercurial/streamclone.py @@ -319,12 +319,12 @@ def consumev1(repo, fp, filecount, bytec 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()