Mercurial > public > mercurial-scm > hg
comparison mercurial/transaction.py @ 50283:dda43856ef96 stable
undo-files: add a undoname closure to the _write_undo method
We will also needs it when the transaction will take care of the other journal
files, which is soon?.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 06 Mar 2023 19:19:27 +0100 |
parents | 5e568d70f54d |
children | a43f0562220c |
comparison
equal
deleted
inserted
replaced
50282:4bcb91c8b9d8 | 50283:dda43856ef96 |
---|---|
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 os | |
14 | 15 |
15 from .i18n import _ | 16 from .i18n import _ |
16 from . import ( | 17 from . import ( |
17 error, | 18 error, |
18 pycompat, | 19 pycompat, |
635 def _writeundo(self): | 636 def _writeundo(self): |
636 """write transaction data for possible future undo call""" | 637 """write transaction data for possible future undo call""" |
637 if self._undoname is None: | 638 if self._undoname is None: |
638 return | 639 return |
639 | 640 |
641 def undoname(fn: bytes) -> bytes: | |
642 base, name = os.path.split(fn) | |
643 assert name.startswith(self._journal) | |
644 new_name = name.replace(self._journal, self._undoname, 1) | |
645 return os.path.join(base, new_name) | |
646 | |
640 undo_backup_path = b"%s.backupfiles" % self._undoname | 647 undo_backup_path = b"%s.backupfiles" % self._undoname |
641 undobackupfile = self._opener.open(undo_backup_path, b'w') | 648 undobackupfile = self._opener.open(undo_backup_path, b'w') |
642 undobackupfile.write(b'%d\n' % version) | 649 undobackupfile.write(b'%d\n' % version) |
643 for l, f, b, c in self._backupentries: | 650 for l, f, b, c in self._backupentries: |
644 if not f: # temporary file | 651 if not f: # temporary file |
651 b"couldn't remove %s: unknown cache location" | 658 b"couldn't remove %s: unknown cache location" |
652 b"%s\n" % (b, l) | 659 b"%s\n" % (b, l) |
653 ) | 660 ) |
654 continue | 661 continue |
655 vfs = self._vfsmap[l] | 662 vfs = self._vfsmap[l] |
656 base, name = vfs.split(b) | 663 u = undoname(b) |
657 assert name.startswith(self._journal), name | |
658 uname = name.replace(self._journal, self._undoname, 1) | |
659 u = vfs.reljoin(base, uname) | |
660 util.copyfile(vfs.join(b), vfs.join(u), hardlink=True) | 664 util.copyfile(vfs.join(b), vfs.join(u), hardlink=True) |
661 undobackupfile.write(b"%s\0%s\0%s\0%d\n" % (l, f, u, c)) | 665 undobackupfile.write(b"%s\0%s\0%s\0%d\n" % (l, f, u, c)) |
662 undobackupfile.close() | 666 undobackupfile.close() |
663 | 667 |
664 def _abort(self): | 668 def _abort(self): |