Mercurial > hg-stable
comparison mercurial/transaction.py @ 50284:a43f0562220c stable
undo-files: have the transaction directly tracks and manages journal rename
This is much simpler this way.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 06 Mar 2023 19:22:34 +0100 |
parents | dda43856ef96 |
children | 3d0b5760851c |
comparison
equal
deleted
inserted
replaced
50283:dda43856ef96 | 50284:a43f0562220c |
---|---|
151 self._vfsmap = vfsmap | 151 self._vfsmap = vfsmap |
152 self._after = after | 152 self._after = after |
153 self._offsetmap = {} | 153 self._offsetmap = {} |
154 self._newfiles = set() | 154 self._newfiles = set() |
155 self._journal = journalname | 155 self._journal = journalname |
156 self._journal_files = [] | |
156 self._undoname = undoname | 157 self._undoname = undoname |
157 self._queue = [] | 158 self._queue = [] |
158 # A callback to do something just after releasing transaction. | 159 # A callback to do something just after releasing transaction. |
159 if releasefn is None: | 160 if releasefn is None: |
160 releasefn = lambda tr, success: None | 161 releasefn = lambda tr, success: None |
631 """abort the transaction (generally called on error, or when the | 632 """abort the transaction (generally called on error, or when the |
632 transaction is not explicitly committed before going out of | 633 transaction is not explicitly committed before going out of |
633 scope)""" | 634 scope)""" |
634 self._abort() | 635 self._abort() |
635 | 636 |
637 @active | |
638 def add_journal(self, vfs_id, path): | |
639 self._journal_files.append((vfs_id, path)) | |
640 | |
636 def _writeundo(self): | 641 def _writeundo(self): |
637 """write transaction data for possible future undo call""" | 642 """write transaction data for possible future undo call""" |
638 if self._undoname is None: | 643 if self._undoname is None: |
639 return | 644 return |
640 | 645 |
662 vfs = self._vfsmap[l] | 667 vfs = self._vfsmap[l] |
663 u = undoname(b) | 668 u = undoname(b) |
664 util.copyfile(vfs.join(b), vfs.join(u), hardlink=True) | 669 util.copyfile(vfs.join(b), vfs.join(u), hardlink=True) |
665 undobackupfile.write(b"%s\0%s\0%s\0%d\n" % (l, f, u, c)) | 670 undobackupfile.write(b"%s\0%s\0%s\0%d\n" % (l, f, u, c)) |
666 undobackupfile.close() | 671 undobackupfile.close() |
672 for vfs, src in self._journal_files: | |
673 dest = undoname(src) | |
674 # if src and dest refer to a same file, vfs.rename is a no-op, | |
675 # leaving both src and dest on disk. delete dest to make sure | |
676 # the rename couldn't be such a no-op. | |
677 vfs.tryunlink(dest) | |
678 try: | |
679 vfs.rename(src, dest) | |
680 except FileNotFoundError: # journal file does not yet exist | |
681 pass | |
667 | 682 |
668 def _abort(self): | 683 def _abort(self): |
669 entries = self.readjournal() | 684 entries = self.readjournal() |
670 self._count = 0 | 685 self._count = 0 |
671 self._usages = 0 | 686 self._usages = 0 |