Mercurial > hg-stable
changeset 50282:4bcb91c8b9d8 stable
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.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 06 Mar 2023 13:31:04 +0100 |
parents | f34887316f1f |
children | dda43856ef96 |
files | mercurial/repair.py tests/test-empty.t |
diffstat | 2 files changed, 21 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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: