# HG changeset patch # User Pierre-Yves David # Date 1727129764 -7200 # Node ID 7032da07557221da9af6af04a56baf5318c43027 # Parent 9f7cf869e9f43aee93db9b02d08af16f8b4427ce rev-branch-cache: make sure we close the name file we open We were various opening without with or try. Adding a try would not hurt. diff -r 9f7cf869e9f4 -r 7032da075572 mercurial/branching/rev_cache.py --- a/mercurial/branching/rev_cache.py Mon Sep 23 23:52:45 2024 +0200 +++ b/mercurial/branching/rev_cache.py Tue Sep 24 00:16:04 2024 +0200 @@ -316,27 +316,30 @@ def _writenames(self, repo): """write the new branch names to revbranchcache""" - if self._rbcnamescount != 0: - f = repo.cachevfs.open(_rbcnames, b'ab') - if f.tell() == self._rbcsnameslen: - f.write(b'\0') - else: + f = None + try: + if self._rbcnamescount != 0: + f = repo.cachevfs.open(_rbcnames, b'ab') + if f.tell() == self._rbcsnameslen: + f.write(b'\0') + else: + f.close() + f = None + repo.ui.debug(b"%s changed - rewriting it\n" % _rbcnames) + self._rbcnamescount = 0 + self._rbcrevslen = 0 + if self._rbcnamescount == 0: + # before rewriting names, make sure references are removed + repo.cachevfs.unlinkpath(_rbcrevs, ignoremissing=True) + f = repo.cachevfs.open(_rbcnames, b'wb') + names = self._names[self._rbcnamescount :] + from_local = encoding.fromlocal + data = b'\0'.join(from_local(b) for b in names) + f.write(data) + self._rbcsnameslen = f.tell() + finally: + if f is not None: f.close() - repo.ui.debug(b"%s changed - rewriting it\n" % _rbcnames) - self._rbcnamescount = 0 - self._rbcrevslen = 0 - if self._rbcnamescount == 0: - # before rewriting names, make sure references are removed - repo.cachevfs.unlinkpath(_rbcrevs, ignoremissing=True) - f = repo.cachevfs.open(_rbcnames, b'wb') - f.write( - b'\0'.join( - encoding.fromlocal(b) - for b in self._names[self._rbcnamescount :] - ) - ) - self._rbcsnameslen = f.tell() - f.close() self._rbcnamescount = len(self._names) def _writerevs(self, repo, start):