changeset 50114:d1215f905818

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 15 Feb 2023 21:31:37 +0100
parents cf8b9c80d67c
children 3236643066c4
files mercurial/localrepo.py
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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(