changeset 48682:cdb0d857afe2

dirstate: use a context manager when writing the dirstate This make sure the file is closed in a timely manner. We define a lambda for the file opening. It might seems a bit overkill here but a future changeset will need to do more of those. Differential Revision: https://phab.mercurial-scm.org/D12122
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 31 Jan 2022 08:23:54 +0100
parents e845537f6adb
children 111f5a0cbcaa
files mercurial/dirstate.py
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Wed Feb 02 17:24:05 2022 +0100
+++ b/mercurial/dirstate.py	Mon Jan 31 08:23:54 2022 +0100
@@ -713,8 +713,9 @@
             )
             return
 
-        st = self._opener(filename, b"w", atomictemp=True, checkambig=True)
-        self._writedirstate(tr, st)
+        file = lambda f: self._opener(f, b"w", atomictemp=True, checkambig=True)
+        with file(self._filename) as f:
+            self._writedirstate(tr, f)
 
     def addparentchangecallback(self, category, callback):
         """add a callback to be called when the wd parents are changed