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.
--- 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(