undo-files: cleanup backup when cleaning undos
Previously, the backups were left behind, by operation cleaning the undo's like
strip, narrow and stream clone.
The remaining elevant in the room is the transaction itself, who does not
properly cleanup undo backup before copying the new ones.
--- a/mercurial/repair.py Mon Mar 06 13:30:41 2023 +0100
+++ b/mercurial/repair.py Mon Mar 06 13:31:04 2023 +0100
@@ -26,6 +26,7 @@
phases,
requirements,
scmutil,
+ transaction,
util,
)
from .utils import (
@@ -113,14 +114,32 @@
return s
+UNDO_BACKUP = b'undo.backupfiles'
+
+
def cleanup_undo_files(repo):
"""remove "undo" files used by the rollback logic
This is useful to prevent rollback running in situation were it does not
make sense. For example after a strip.
"""
- # XXX need to remove the backups themselve too
- undo_files = [(repo.svfs, b'undo.backupfiles')]
+ backup_entries = []
+ undo_files = []
+ vfsmap = repo.vfs_map
+ try:
+ with repo.svfs(UNDO_BACKUP) as f:
+ backup_entries = transaction.read_backup_files(repo.ui.warn, f)
+ except OSError as e:
+ if e.errno != errno.ENOENT:
+ msg = _(b'could not read %s: %s\n')
+ msg %= (repo.svfs.join(UNDO_BACKUP), stringutil.forcebytestr(e))
+ repo.ui.warn(msg)
+
+ for location, f, backup_path, c in backup_entries:
+ if location in vfsmap and backup_path:
+ undo_files.append((vfsmap[location], backup_path))
+
+ undo_files.append((repo.svfs, UNDO_BACKUP))
undo_files.extend(repo.undofiles())
for undovfs, undofile in undo_files:
try:
--- a/tests/test-empty.t Mon Mar 06 13:30:41 2023 +0100
+++ b/tests/test-empty.t Mon Mar 06 13:31:04 2023 +0100
@@ -40,7 +40,6 @@
hgrc
requires
store
- undo.backup.branch
wcache
Should be empty (except for the "basic" requires):