Mercurial > hg
changeset 42185:ececa45c80d8
revbranchcache: use context manager in _writerevs() to write to file
The other _writenames() is a bit complicated to use context manager.
Differential Revision: https://phab.mercurial-scm.org/D6292
author | Pulkit Goyal <pulkit@yandex-team.ru> |
---|---|
date | Sat, 20 Apr 2019 00:48:16 +0300 |
parents | 09fd338522fa |
children | fd384911f51b |
files | mercurial/branchmap.py |
diffstat | 1 files changed, 9 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/branchmap.py Sat Apr 20 00:44:18 2019 +0300 +++ b/mercurial/branchmap.py Sat Apr 20 00:48:16 2019 +0300 @@ -652,18 +652,15 @@ def _writerevs(self, repo, start): """ write the new revs to revbranchcache """ - revs = min(len(repo.changelog), - len(self._rbcrevs) // _rbcrecsize) - f = repo.cachevfs.open(_rbcrevs, 'ab') - if f.tell() != start: - repo.ui.debug("truncating cache/%s to %d\n" - % (_rbcrevs, start)) - f.seek(start) + revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize) + with repo.cachevfs.open(_rbcrevs, 'ab') as f: if f.tell() != start: - start = 0 + repo.ui.debug("truncating cache/%s to %d\n" % (_rbcrevs, start)) f.seek(start) - f.truncate() - end = revs * _rbcrecsize - f.write(self._rbcrevs[start:end]) - f.close() + if f.tell() != start: + start = 0 + f.seek(start) + f.truncate() + end = revs * _rbcrecsize + f.write(self._rbcrevs[start:end]) self._rbcrevslen = revs