[PATCH 5 of 5 V2] streamclone: use context manager for writing files
Gregory Szorc
gregory.szorc at gmail.com
Sat Jan 2 18:45:33 CST 2016
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1451776198 28800
# Sat Jan 02 15:09:58 2016 -0800
# Node ID 3523527da243b2d150d54d77aa630b23b2e9ad7d
# Parent 438dce208879a651879d123d646c6782e3936f42
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
@@ -314,22 +314,22 @@ def consumev1(repo, fp, filecount, bytec
size = int(size)
except (ValueError, TypeError):
raise error.ResponseError(
_('unexpected response from remote server:'), l)
if repo.ui.debugflag:
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()
# Writing straight to files circumvented the inmemory caches
repo.invalidate()
elapsed = time.time() - start
More information about the Mercurial-devel
mailing list