Mercurial > hg
changeset 49203:f923bdd7477d
branchmap: use a context manager when writing the branchmap
This is cleaner and safer. The previous code date from long before we had
context manager available.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 13 May 2022 15:19:57 +0200 |
parents | 71774d799de7 |
children | b5858e02e3ba |
files | mercurial/branchmap.py |
diffstat | 1 files changed, 16 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/branchmap.py Tue Apr 05 05:01:58 2022 +0200 +++ b/mercurial/branchmap.py Fri May 13 15:19:57 2022 +0200 @@ -428,22 +428,22 @@ self._delayed = True return try: - f = repo.cachevfs(self._filename(repo), b"w", atomictemp=True) - cachekey = [hex(self.tipnode), b'%d' % self.tiprev] - if self.filteredhash is not None: - cachekey.append(hex(self.filteredhash)) - f.write(b" ".join(cachekey) + b'\n') - nodecount = 0 - for label, nodes in sorted(self._entries.items()): - label = encoding.fromlocal(label) - for node in nodes: - nodecount += 1 - if node in self._closednodes: - state = b'c' - else: - state = b'o' - f.write(b"%s %s %s\n" % (hex(node), state, label)) - f.close() + filename = self._filename(repo) + with repo.cachevfs(filename, b"w", atomictemp=True) as f: + cachekey = [hex(self.tipnode), b'%d' % self.tiprev] + if self.filteredhash is not None: + cachekey.append(hex(self.filteredhash)) + f.write(b" ".join(cachekey) + b'\n') + nodecount = 0 + for label, nodes in sorted(self._entries.items()): + label = encoding.fromlocal(label) + for node in nodes: + nodecount += 1 + if node in self._closednodes: + state = b'c' + else: + state = b'o' + f.write(b"%s %s %s\n" % (hex(node), state, label)) repo.ui.log( b'branchcache', b'wrote %s with %d labels and %d nodes\n',