diff 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
line wrap: on
line diff
--- a/mercurial/transaction.py	Mon Mar 06 13:31:04 2023 +0100
+++ b/mercurial/transaction.py	Mon Mar 06 19:19:27 2023 +0100
@@ -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 os
 
 from .i18n import _
 from . import (
@@ -637,6 +638,12 @@
         if self._undoname is None:
             return
 
+        def undoname(fn: bytes) -> bytes:
+            base, name = os.path.split(fn)
+            assert name.startswith(self._journal)
+            new_name = name.replace(self._journal, self._undoname, 1)
+            return os.path.join(base, new_name)
+
         undo_backup_path = b"%s.backupfiles" % self._undoname
         undobackupfile = self._opener.open(undo_backup_path, b'w')
         undobackupfile.write(b'%d\n' % version)
@@ -653,10 +660,7 @@
                     )
                     continue
                 vfs = self._vfsmap[l]
-                base, name = vfs.split(b)
-                assert name.startswith(self._journal), name
-                uname = name.replace(self._journal, self._undoname, 1)
-                u = vfs.reljoin(base, uname)
+                u = undoname(b)
                 util.copyfile(vfs.join(b), vfs.join(u), hardlink=True)
             undobackupfile.write(b"%s\0%s\0%s\0%d\n" % (l, f, u, c))
         undobackupfile.close()