diff -r d1d458fb96a5 -r a445194f0a4d mercurial/transaction.py --- a/mercurial/transaction.py Wed May 03 00:12:34 2023 +0200 +++ b/mercurial/transaction.py Wed May 03 00:16:38 2023 +0200 @@ -414,6 +414,11 @@ if vfs.exists(file): filepath = vfs.join(file) backuppath = vfs.join(backupfile) + # store encoding may result in different directory here. + # so we have to ensure the destination directory exist + final_dir_name = os.path.dirname(backuppath) + util.makedirs(final_dir_name, mode=vfs.createmode, notindexed=True) + # then we can copy the backup util.copyfile(filepath, backuppath, hardlink=hardlink) else: backupfile = b''