Patchwork D6783: httppeer: use context manager when writing temporary bundle to send

login
register
mail settings
Submitter phabricator
Date Sept. 5, 2019, 6:57 p.m.
Message ID <397c1c18654b21c27949df9a10dc3dbf@localhost.localdomain>
Download mbox | patch
Permalink /patch/41474/
State Not Applicable
Headers show

Comments

phabricator - Sept. 5, 2019, 6:57 p.m.
Closed by commit rHG58f73e9ccfff: httppeer: use context manager when writing 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/D6783?vs=16369&id=16372

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6783/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6783

AFFECTED FILES
  mercurial/httppeer.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -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):