changeset 27776:6fe2da48a6dd

bundlerepo: use context manager for file I/O in _writetempbundle
author Bryan O'Sullivan <bryano@fb.com>
date Tue, 12 Jan 2016 14:48:27 -0800
parents 3ea35a0769fe
children 47ac135113ec
files mercurial/bundlerepo.py
diffstat 1 files changed, 1 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundlerepo.py	Tue Jan 12 14:47:21 2016 -0800
+++ b/mercurial/bundlerepo.py	Tue Jan 12 14:48:27 2016 -0800
@@ -245,17 +245,14 @@
             fdtemp, temp = self.vfs.mkstemp(prefix="hg-bundle-",
                                             suffix=".hg10un")
             self.tempfile = temp
-            fptemp = os.fdopen(fdtemp, 'wb')
 
-            try:
+            with os.fdopen(fdtemp, 'wb') as fptemp:
                 fptemp.write(header)
                 while True:
                     chunk = read(2**18)
                     if not chunk:
                         break
                     fptemp.write(chunk)
-            finally:
-                fptemp.close()
 
             return self.vfs.open(self.tempfile, mode="rb")
         self._tempparent = None