dirstate: avoid transaction backup/restore if we do not hold the lock
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 15 Feb 2023 21:31:37 +0100
changeset 50058 d1215f905818
parent 50057 cf8b9c80d67c
child 50059 3236643066c4
dirstate: avoid transaction backup/restore if we do not hold the lock Doing overwriting the dirstate content without holding the lock is a recipe for disaster.
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Tue Dec 13 09:59:22 2022 +0100
+++ b/mercurial/localrepo.py	Wed Feb 15 21:31:37 2023 +0100
@@ -2533,7 +2533,8 @@
                 # out) in this transaction
                 narrowspec.restorebackup(self, b'journal.narrowspec')
                 narrowspec.restorewcbackup(self, b'journal.narrowspec.dirstate')
-                repo.dirstate.restorebackup(None, b'journal.dirstate')
+                if repo.currentwlock() is not None:
+                    repo.dirstate.restorebackup(None, b'journal.dirstate')
 
                 repo.invalidate(clearfilecache=True)
 
@@ -2657,7 +2658,8 @@
 
     @unfilteredmethod
     def _writejournal(self, desc):
-        self.dirstate.savebackup(None, b'journal.dirstate')
+        if self.currentwlock() is not None:
+            self.dirstate.savebackup(None, b'journal.dirstate')
         narrowspec.savewcbackup(self, b'journal.narrowspec.dirstate')
         narrowspec.savebackup(self, b'journal.narrowspec')
         self.vfs.write(