Mercurial > hg
changeset 42852:58f73e9ccfff
httppeer: use context manager when writing temporary bundle to send
Differential Revision: https://phab.mercurial-scm.org/D6783
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 04 Sep 2019 10:42:26 -0700 |
parents | 64e28b891796 |
children | 37debb6771f5 |
files | mercurial/httppeer.py |
diffstat | 1 files changed, 5 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/httppeer.py Sun Sep 01 18:06:31 2019 +0900 +++ b/mercurial/httppeer.py Wed Sep 04 10:42:26 2019 -0700 @@ -490,18 +490,16 @@ os.unlink(tempname) def _calltwowaystream(self, cmd, fp, **args): - fh = None fp_ = None filename = None try: # dump bundle to disk fd, filename = pycompat.mkstemp(prefix="hg-bundle-", suffix=".hg") - fh = os.fdopen(fd, r"wb") - d = fp.read(4096) - while d: - fh.write(d) + with os.fdopen(fd, r"wb") as fh: d = fp.read(4096) - fh.close() + while d: + fh.write(d) + d = fp.read(4096) # start http push fp_ = httpconnection.httpsendfile(self.ui, filename, "rb") headers = {r'Content-Type': r'application/mercurial-0.1'} @@ -509,8 +507,7 @@ finally: if fp_ is not None: fp_.close() - if fh is not None: - fh.close() + if filename is not None: os.unlink(filename) def _callcompressable(self, cmd, **args):