# HG changeset patch # User Pierre-Yves David # Date 1677765017 -3600 # Node ID df76808d5f210c06ab39d1029c844396226c7409 # Parent 444fa55f5dd28a30848212b3d53df9074f13297c dirstate: use a context manager to handle the file used for writing the branch This is more modern. diff -r 444fa55f5dd2 -r df76808d5f21 mercurial/dirstate.py --- a/mercurial/dirstate.py Thu Mar 02 11:54:21 2023 +0100 +++ b/mercurial/dirstate.py Thu Mar 02 14:50:17 2023 +0100 @@ -613,19 +613,17 @@ def setbranch(self, branch): self.__class__._branch.set(self, encoding.fromlocal(branch)) - f = self._opener(b'branch', b'w', atomictemp=True, checkambig=True) - try: + vfs = self._opener + with vfs(b'branch', b'w', atomictemp=True, checkambig=True) as f: f.write(self._branch + b'\n') - f.close() - # make sure filecache has the correct stat info for _branch after # replacing the underlying file + # + # XXX do we actually need this, + # refreshing the attribute is quite cheap ce = self._filecache[b'_branch'] if ce: ce.refresh() - except: # re-raises - f.discard() - raise def invalidate(self): """Causes the next access to reread the dirstate.