undo-files: clean existing files up before writing new one stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 06 Mar 2023 22:16:43 +0100
branchstable
changeset 50303 92734603e33e
parent 50302 94a8c354242b
child 50304 862969b6c359
undo-files: clean existing files up before writing new one the in the initial design of journal/undo interaction, ages ago, new file always overwrote previous files. This is no longer the case for a long while, so it is time to properly clean things up before writing new ones. Otherwise, inconsistent "undo" state might exist on disk, leading `hg rollback` to misbehave (more that intended).
mercurial/transaction.py
tests/test-hardlinks.t
tests/test-largefiles-cache.t
tests/test-persistent-nodemap.t
--- a/mercurial/transaction.py	Tue Mar 07 03:31:21 2023 +0100
+++ b/mercurial/transaction.py	Mon Mar 06 22:16:43 2023 +0100
@@ -690,6 +690,11 @@
         """write transaction data for possible future undo call"""
         if self._undoname is None:
             return
+        cleanup_undo_files(
+            self._report,
+            self._vfsmap,
+            undo_prefix=self._undoname,
+        )
 
         def undoname(fn: bytes) -> bytes:
             base, name = os.path.split(fn)
--- a/tests/test-hardlinks.t	Tue Mar 07 03:31:21 2023 +0100
+++ b/tests/test-hardlinks.t	Mon Mar 06 22:16:43 2023 +0100
@@ -141,8 +141,6 @@
   1 r3/.hg/store/phaseroots
   1 r3/.hg/store/requires
   1 r3/.hg/store/undo
-  1 r3/.hg/store/undo.backup.fncache (repofncache !)
-  1 r3/.hg/store/undo.backup.phaseroots
   1 r3/.hg/store/undo.backupfiles
 
 Push to repo r1 should break up most hardlinks in r2:
@@ -253,8 +251,6 @@
   2 r4/.hg/store/phaseroots
   2 r4/.hg/store/requires
   2 r4/.hg/store/undo
-  2 r4/.hg/store/undo.backup.fncache (repofncache !)
-  2 r4/.hg/store/undo.backup.phaseroots
   2 r4/.hg/store/undo.backupfiles
   [24] r4/.hg/undo.backup.branch (re)
   2 r4/\.hg/undo\.backup\.dirstate (re)
@@ -308,8 +304,6 @@
   2 r4/.hg/store/phaseroots
   2 r4/.hg/store/requires
   2 r4/.hg/store/undo
-  2 r4/.hg/store/undo.backup.fncache (repofncache !)
-  2 r4/.hg/store/undo.backup.phaseroots
   2 r4/.hg/store/undo.backupfiles
   [23] r4/.hg/undo.backup.branch (re)
   2 r4/\.hg/undo\.backup\.dirstate (re)
--- a/tests/test-largefiles-cache.t	Tue Mar 07 03:31:21 2023 +0100
+++ b/tests/test-largefiles-cache.t	Mon Mar 06 22:16:43 2023 +0100
@@ -189,7 +189,6 @@
   $ find src/.hg/largefiles/* | egrep "(dirstate|$hash)" | sort
   src/.hg/largefiles/dirstate
   src/.hg/largefiles/e2fb5f2139d086ded2cb600d5a91a196e76bf020
-  src/.hg/largefiles/undo.backup.dirstate
 
 Verify that backwards compatibility is maintained for old storage layout
   $ mv src/.hg/largefiles/$hash share_dst/.hg/largefiles
--- a/tests/test-persistent-nodemap.t	Tue Mar 07 03:31:21 2023 +0100
+++ b/tests/test-persistent-nodemap.t	Mon Mar 06 22:16:43 2023 +0100
@@ -811,8 +811,7 @@
     - manifest
   
   $ ls -1 .hg/store/ | egrep '00(changelog|manifest)(\.n|-.*\.nd)'
-  undo.backup.00changelog.n
-  undo.backup.00manifest.n
+  [1]
   $ hg debugnodemap --metadata
 
 
@@ -858,8 +857,6 @@
   00changelog.n
   00manifest-*.nd (glob)
   00manifest.n
-  undo.backup.00changelog.n
-  undo.backup.00manifest.n
 
   $ hg debugnodemap --metadata
   uid: * (glob)