From patchwork Thu Sep 5 18:57:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D6784: httppeer: use context manager when reading temporary bundle to send From: phabricator X-Patchwork-Id: 41475 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Thu, 5 Sep 2019 18:57:53 +0000 Closed by commit rHG37debb6771f5: httppeer: use context manager when reading temporary bundle to send (authored by martinvonz). This revision was automatically updated to reflect the committed changes. This revision was not accepted when it landed; it landed in state "Needs Review". REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D6784?vs=16370&id=16373 CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D6784/new/ REVISION DETAIL https://phab.mercurial-scm.org/D6784 AFFECTED FILES mercurial/httppeer.py CHANGE DETAILS To: martinvonz, #hg-reviewers Cc: mercurial-devel diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py --- a/mercurial/httppeer.py +++ b/mercurial/httppeer.py @@ -490,7 +490,6 @@ os.unlink(tempname) def _calltwowaystream(self, cmd, fp, **args): - fp_ = None filename = None try: # dump bundle to disk @@ -501,12 +500,10 @@ 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'} - return self._callstream(cmd, data=fp_, headers=headers, **args) + with httpconnection.httpsendfile(self.ui, filename, "rb") as fp_: + headers = {r'Content-Type': r'application/mercurial-0.1'} + return self._callstream(cmd, data=fp_, headers=headers, **args) finally: - if fp_ is not None: - fp_.close() if filename is not None: os.unlink(filename)