changeset 35971:0f2c51afafb2

revlog: use context manager for index file lifetime in checkinlinesize This is clearer, safer and more modern.
author Boris Feld <boris.feld@octobus.net>
date Mon, 05 Feb 2018 17:34:57 +0100
parents 69cf2e422490
children 82afb1a5ed94
files mercurial/revlog.py
diffstat 1 files changed, 9 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Mon Feb 05 17:34:47 2018 +0100
+++ b/mercurial/revlog.py	Mon Feb 05 17:34:57 2018 +0100
@@ -1863,16 +1863,16 @@
             for r in self:
                 df.write(self._getsegmentforrevs(r, r)[1])
 
-        fp = self._indexfp('w')
-        self.version &= ~FLAG_INLINE_DATA
-        self._inline = False
-        for i in self:
-            e = self._io.packentry(self.index[i], self.node, self.version, i)
-            fp.write(e)
+        with self._indexfp('w') as fp:
+            self.version &= ~FLAG_INLINE_DATA
+            self._inline = False
+            io = self._io
+            for i in self:
+                e = io.packentry(self.index[i], self.node, self.version, i)
+                fp.write(e)
 
-        # if we don't call close, the temp file will never replace the
-        # real index
-        fp.close()
+            # the temp file replace the real index when we exit the context
+            # manager
 
         tr.replace(self.indexfile, trindex * self._io.size)
         self._chunkclear()