Mercurial > hg
changeset 50309:86dc9e097bed stable
transaction: move the restoration of backup file in a small closure
We are about to use that logic in two different location, making is a small
reusable closure prepares that.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 15 Mar 2023 13:20:12 +0100 |
parents | cab3defe6d3b |
children | 4c1061b3e55a |
files | mercurial/transaction.py |
diffstat | 1 files changed, 15 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/transaction.py Wed Mar 15 12:13:08 2023 +0100 +++ b/mercurial/transaction.py Wed Mar 15 13:20:12 2023 +0100 @@ -105,6 +105,19 @@ unlink=True, checkambigfiles=None, ): + backupfiles = [] + + def restore_one_backup(vfs, f, b, checkambig): + filepath = vfs.join(f) + backuppath = vfs.join(b) + try: + util.copyfile(backuppath, filepath, checkambig=checkambig) + backupfiles.append((vfs, b)) + except IOError as exc: + e_msg = stringutil.forcebytestr(exc) + report(_(b"failed to recover %s (%s)\n") % (f, e_msg)) + raise + for f, o in sorted(dict(entries).items()): if o or not unlink: checkambig = checkambigfiles and (f, b'') in checkambigfiles @@ -129,23 +142,14 @@ except FileNotFoundError: pass - backupfiles = [] for l, f, b, c in backupentries: if l not in vfsmap and c: report(b"couldn't handle %s: unknown cache location %s\n" % (b, l)) vfs = vfsmap[l] try: + checkambig = checkambigfiles and (f, l) in checkambigfiles if f and b: - filepath = vfs.join(f) - backuppath = vfs.join(b) - checkambig = checkambigfiles and (f, l) in checkambigfiles - try: - util.copyfile(backuppath, filepath, checkambig=checkambig) - backupfiles.append((vfs, b)) - except IOError as exc: - e_msg = stringutil.forcebytestr(exc) - report(_(b"failed to recover %s (%s)\n") % (f, e_msg)) - raise + restore_one_backup(vfs, f, b, checkambig) else: target = f or b try: