Mercurial > hg
diff mercurial/localrepo.py @ 50085:ff12f42415f5
localrepo: stop doing special dirstate backup at transaction open
Since the dirstate writes are already managed by the transaction, we already do
a backup of the dirstate when necessary (and even trigger one to keep `hg
rollback` happy).
We needs some special code to deal with the initial empty checkout, but it is
not too complicated.
Managing variable filename (as dirstate-v2 uses) at the "journalfile" level, is
complex and fragile (which is consistent with the fact these files are not
journal…). If we no longer do it, our life is significantly simpler.
In some sense, we apply the xkcd-1134¹ solution to our savebackup/restorebackup
problem.
[1] https://xkcd.com/1134/
(the change to test-hardlink are expect as decreasing the number of duplicated
backup drive the hardlink count down)
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 16 Feb 2023 04:02:36 +0100 |
parents | 5b9c3ae807c8 |
children | ec769cbc1fa2 |
line wrap: on
line diff
--- a/mercurial/localrepo.py Thu Feb 16 11:42:43 2023 +0100 +++ b/mercurial/localrepo.py Thu Feb 16 04:02:36 2023 +0100 @@ -2548,8 +2548,6 @@ # out) in this transaction narrowspec.restorebackup(self, b'journal.narrowspec') narrowspec.restorewcbackup(self, b'journal.narrowspec.dirstate') - if repo.currentwlock() is not None: - repo.dirstate.restorebackup(None, b'journal.dirstate') repo.invalidate(clearfilecache=True) @@ -2676,31 +2674,21 @@ return tr def _journalfiles(self): - first = ( + return ( (self.svfs, b'journal'), (self.svfs, b'journal.narrowspec'), (self.vfs, b'journal.narrowspec.dirstate'), - (self.vfs, b'journal.dirstate'), - ) - middle = [] - dirstate_data = self.dirstate.data_backup_filename(b'journal.dirstate') - if dirstate_data is not None: - middle.append((self.vfs, dirstate_data)) - end = ( (self.vfs, b'journal.branch'), (self.vfs, b'journal.desc'), (bookmarks.bookmarksvfs(self), b'journal.bookmarks'), (self.svfs, b'journal.phaseroots'), ) - return first + tuple(middle) + end def undofiles(self): return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] @unfilteredmethod def _writejournal(self, desc): - 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( @@ -2808,11 +2796,20 @@ if self.svfs.exists(b'undo.phaseroots'): self.svfs.rename(b'undo.phaseroots', b'phaseroots', checkambig=True) self.invalidate() + self.dirstate.invalidate() if parentgone: + # replace this with some explicit parent update in the future. + has_node = self.changelog.index.has_node + if not all(has_node(p) for p in self.dirstate._pl): + # There was no dirstate to backup initially, we need to drop + # the existing one. + with self.dirstate.changing_parents(self): + self.dirstate.setparents(self.nullid) + self.dirstate.clear() + narrowspec.restorebackup(self, b'undo.narrowspec') narrowspec.restorewcbackup(self, b'undo.narrowspec.dirstate') - self.dirstate.restorebackup(None, b'undo.dirstate') try: branch = self.vfs.read(b'undo.branch') self.dirstate.setbranch(encoding.tolocal(branch))