Skip to content
Snippets Groups Projects
Commit 3d0b5760 authored by Pierre-Yves David's avatar Pierre-Yves David :octopus:
Browse files

undo-files: move the undo cleanup code in the transaction module

Now that undo creation is gathered in the transaction module, let us move the code cleaning them up there too.

This will be useful to better clean previous undo files up before creating new
ones.
parent 47310375
No related branches found
No related tags found
3 merge requests!506Merge stable into default,!502tests: fix timeout adjustement in delaypush.py,!491properly cleanup previous undo files before creating new ones
......@@ -19,6 +19,7 @@
repair,
requirements,
scmutil,
transaction,
util,
wireprototypes,
)
......@@ -293,7 +294,7 @@
finally:
f.close()
repair.cleanup_undo_files(repo)
transaction.cleanup_undo_files(repo)
# Remove partial backup only if there were no exceptions
op._widen_uninterr.__exit__(None, None, None)
......
......@@ -7,8 +7,6 @@
# GNU General Public License version 2 or any later version.
import errno
from .i18n import _
from .node import (
hex,
......@@ -31,7 +29,6 @@
)
from .utils import (
hashutil,
stringutil,
urlutil,
)
......@@ -114,43 +111,6 @@
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.
"""
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:
undovfs.unlink(undofile)
except OSError as e:
if e.errno != errno.ENOENT:
msg = _(b'error removing %s: %s\n')
msg %= (undovfs.join(undofile), stringutil.forcebytestr(e))
repo.ui.warn(msg)
def strip(ui, repo, nodelist, backup=True, topic=b'backup'):
# This function requires the caller to lock the repo, but it operates
# within a transaction of its own, and thus requires there to be no current
......@@ -299,7 +259,7 @@
bmchanges = [(m, repo[newbmtarget].node()) for m in updatebm]
repo._bookmarks.applychanges(repo, tr, bmchanges)
cleanup_undo_files(repo)
transaction.cleanup_undo_files(repo)
except: # re-raises
if backupfile:
......
......@@ -20,7 +20,6 @@
narrowspec,
phases,
pycompat,
repair,
requirements as requirementsmod,
scmutil,
store,
......@@ -24,6 +23,7 @@
requirements as requirementsmod,
scmutil,
store,
transaction,
util,
)
from .revlogutils import (
......@@ -932,4 +932,4 @@
dest_repo.store.write(tr)
# clean up transaction file as they do not make sense
repair.cleanup_undo_files(dest_repo)
transaction.cleanup_undo_files(dest_repo)
......@@ -11,6 +11,7 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
import errno
import os
from .i18n import _
......@@ -39,6 +40,43 @@
return _active
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.
"""
backup_entries = []
undo_files = []
vfsmap = repo.vfs_map
try:
with repo.svfs(UNDO_BACKUP) as f:
backup_entries = 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:
undovfs.unlink(undofile)
except OSError as e:
if e.errno != errno.ENOENT:
msg = _(b'error removing %s: %s\n')
msg %= (undovfs.join(undofile), stringutil.forcebytestr(e))
repo.ui.warn(msg)
def _playback(
journal,
report,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment