[PATCH 10 of 13] revlog: use context manager for index file lifetime in checkinlinesize
Boris Feld
boris.feld at octobus.net
Tue Feb 6 08:21:31 EST 2018
# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1517848497 -3600
# Mon Feb 05 17:34:57 2018 +0100
# Node ID 1a212682563740e031380befc949167e73b476bd
# Parent c4015bae897ca99b12933bf74a176fa6a349681b
# EXP-Topic revlog-fp
# Available At https://bitbucket.org/octobus/mercurial-devel/
# hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 1a2126825637
revlog: use context manager for index file lifetime in checkinlinesize
This is clearer, safer and more modern.
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1863,16 +1863,16 @@ class revlog(object):
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()
More information about the Mercurial-devel
mailing list