Mercurial > hg-stable
changeset 50280:5e568d70f54d stable
undo-files: add a utility function to read the backup-files definition
We will need it in multiple places. so lets factor the logic around.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 06 Mar 2023 13:22:47 +0100 |
parents | 97e91001a4e0 |
children | f34887316f1f |
files | mercurial/transaction.py |
diffstat | 1 files changed, 28 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/transaction.py Mon Mar 06 13:05:43 2023 +0100 +++ b/mercurial/transaction.py Mon Mar 06 13:22:47 2023 +0100 @@ -737,6 +737,32 @@ ) +def read_backup_files(report, fp): + """parse an (already open) backup file an return contained backup entries + + entries are in the form: (location, file, backupfile, xxx) + + :location: the vfs identifier (vfsmap's key) + :file: original file path (in the vfs) + :backupfile: path of the backup (in the vfs) + :cache: a boolean currently always set to False + """ + lines = fp.readlines() + backupentries = [] + if lines: + ver = lines[0][:-1] + if ver != (b'%d' % version): + report(BAD_VERSION_MSG) + else: + for line in lines[1:]: + if line: + # Shave off the trailing newline + line = line[:-1] + l, f, b, c = line.split(b'\0') + backupentries.append((l, f, b, bool(c))) + return backupentries + + def rollback( opener, vfsmap, @@ -776,19 +802,8 @@ backupjournal = b"%s.backupfiles" % file if opener.exists(backupjournal): - fp = opener.open(backupjournal) - lines = fp.readlines() - if lines: - ver = lines[0][:-1] - if ver != (b'%d' % version): - report(BAD_VERSION_MSG) - else: - for line in lines[1:]: - if line: - # Shave off the trailing newline - line = line[:-1] - l, f, b, c = line.split(b'\0') - backupentries.append((l, f, b, bool(c))) + with opener.open(backupjournal) as fp: + backupentries = read_backup_files(report, fp) if skip_journal_pattern is not None: keep = lambda x: not skip_journal_pattern.match(x[1]) backupentries = [x for x in backupentries if keep(x)]