Mercurial > hg > mercurial-source
changeset 36755:1f2b8a644dd4
revlog: use context manager for index file life time in __init__
This is clearer, safer and more modern.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Mon, 05 Feb 2018 17:34:19 +0100 |
parents | 91b3b11565e5 |
children | 69cf2e422490 |
files | mercurial/revlog.py |
diffstat | 1 files changed, 6 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -621,13 +621,12 @@ indexdata = '' self._initempty = True try: - f = self._indexfp() - if (mmapindexthreshold is not None and - self.opener.fstat(f).st_size >= mmapindexthreshold): - indexdata = util.buffer(util.mmapread(f)) - else: - indexdata = f.read() - f.close() + with self._indexfp() as f: + if (mmapindexthreshold is not None and + self.opener.fstat(f).st_size >= mmapindexthreshold): + indexdata = util.buffer(util.mmapread(f)) + else: + indexdata = f.read() if len(indexdata) > 0: v = versionformat_unpack(indexdata[:4])[0] self._initempty = False