mercurial/transaction.py
branchstable
changeset 50286 3d0b5760851c
parent 50284 a43f0562220c
child 50287 7ce9862fca7c
equal deleted inserted replaced
50285:473103758373 50286:3d0b5760851c
     9 # Copyright 2005, 2006 Olivia Mackall <olivia@selenic.com>
     9 # Copyright 2005, 2006 Olivia Mackall <olivia@selenic.com>
    10 #
    10 #
    11 # This software may be used and distributed according to the terms of the
    11 # This software may be used and distributed according to the terms of the
    12 # GNU General Public License version 2 or any later version.
    12 # GNU General Public License version 2 or any later version.
    13 
    13 
       
    14 import errno
    14 import os
    15 import os
    15 
    16 
    16 from .i18n import _
    17 from .i18n import _
    17 from . import (
    18 from . import (
    18     error,
    19     error,
    35                 b'cannot use transaction when it is already committed/aborted'
    36                 b'cannot use transaction when it is already committed/aborted'
    36             )
    37             )
    37         return func(self, *args, **kwds)
    38         return func(self, *args, **kwds)
    38 
    39 
    39     return _active
    40     return _active
       
    41 
       
    42 
       
    43 UNDO_BACKUP = b'undo.backupfiles'
       
    44 
       
    45 
       
    46 def cleanup_undo_files(repo):
       
    47     """remove "undo" files used by the rollback logic
       
    48 
       
    49     This is useful to prevent rollback running in situation were it does not
       
    50     make sense. For example after a strip.
       
    51     """
       
    52     backup_entries = []
       
    53     undo_files = []
       
    54     vfsmap = repo.vfs_map
       
    55     try:
       
    56         with repo.svfs(UNDO_BACKUP) as f:
       
    57             backup_entries = read_backup_files(repo.ui.warn, f)
       
    58     except OSError as e:
       
    59         if e.errno != errno.ENOENT:
       
    60             msg = _(b'could not read %s: %s\n')
       
    61             msg %= (repo.svfs.join(UNDO_BACKUP), stringutil.forcebytestr(e))
       
    62             repo.ui.warn(msg)
       
    63 
       
    64     for location, f, backup_path, c in backup_entries:
       
    65         if location in vfsmap and backup_path:
       
    66             undo_files.append((vfsmap[location], backup_path))
       
    67 
       
    68     undo_files.append((repo.svfs, UNDO_BACKUP))
       
    69     undo_files.extend(repo.undofiles())
       
    70     for undovfs, undofile in undo_files:
       
    71         try:
       
    72             undovfs.unlink(undofile)
       
    73         except OSError as e:
       
    74             if e.errno != errno.ENOENT:
       
    75                 msg = _(b'error removing %s: %s\n')
       
    76                 msg %= (undovfs.join(undofile), stringutil.forcebytestr(e))
       
    77                 repo.ui.warn(msg)
    40 
    78 
    41 
    79 
    42 def _playback(
    80 def _playback(
    43     journal,
    81     journal,
    44     report,
    82     report,