changeset 42853:37debb6771f5

httppeer: use context manager when reading temporary bundle to send Differential Revision: https://phab.mercurial-scm.org/D6784
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 04 Sep 2019 14:35:39 -0700
parents 58f73e9ccfff
children db51a4ac85ac
files mercurial/httppeer.py
diffstat 1 files changed, 3 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/httppeer.py	Wed Sep 04 10:42:26 2019 -0700
+++ b/mercurial/httppeer.py	Wed Sep 04 14:35:39 2019 -0700
@@ -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)