equal
deleted
inserted
replaced
735 BAD_VERSION_MSG = _( |
735 BAD_VERSION_MSG = _( |
736 b"journal was created by a different version of Mercurial\n" |
736 b"journal was created by a different version of Mercurial\n" |
737 ) |
737 ) |
738 |
738 |
739 |
739 |
|
740 def read_backup_files(report, fp): |
|
741 """parse an (already open) backup file an return contained backup entries |
|
742 |
|
743 entries are in the form: (location, file, backupfile, xxx) |
|
744 |
|
745 :location: the vfs identifier (vfsmap's key) |
|
746 :file: original file path (in the vfs) |
|
747 :backupfile: path of the backup (in the vfs) |
|
748 :cache: a boolean currently always set to False |
|
749 """ |
|
750 lines = fp.readlines() |
|
751 backupentries = [] |
|
752 if lines: |
|
753 ver = lines[0][:-1] |
|
754 if ver != (b'%d' % version): |
|
755 report(BAD_VERSION_MSG) |
|
756 else: |
|
757 for line in lines[1:]: |
|
758 if line: |
|
759 # Shave off the trailing newline |
|
760 line = line[:-1] |
|
761 l, f, b, c = line.split(b'\0') |
|
762 backupentries.append((l, f, b, bool(c))) |
|
763 return backupentries |
|
764 |
|
765 |
740 def rollback( |
766 def rollback( |
741 opener, |
767 opener, |
742 vfsmap, |
768 vfsmap, |
743 file, |
769 file, |
744 report, |
770 report, |
774 _(b"couldn't read journal entry %r!\n") % pycompat.bytestr(l) |
800 _(b"couldn't read journal entry %r!\n") % pycompat.bytestr(l) |
775 ) |
801 ) |
776 |
802 |
777 backupjournal = b"%s.backupfiles" % file |
803 backupjournal = b"%s.backupfiles" % file |
778 if opener.exists(backupjournal): |
804 if opener.exists(backupjournal): |
779 fp = opener.open(backupjournal) |
805 with opener.open(backupjournal) as fp: |
780 lines = fp.readlines() |
806 backupentries = read_backup_files(report, fp) |
781 if lines: |
|
782 ver = lines[0][:-1] |
|
783 if ver != (b'%d' % version): |
|
784 report(BAD_VERSION_MSG) |
|
785 else: |
|
786 for line in lines[1:]: |
|
787 if line: |
|
788 # Shave off the trailing newline |
|
789 line = line[:-1] |
|
790 l, f, b, c = line.split(b'\0') |
|
791 backupentries.append((l, f, b, bool(c))) |
|
792 if skip_journal_pattern is not None: |
807 if skip_journal_pattern is not None: |
793 keep = lambda x: not skip_journal_pattern.match(x[1]) |
808 keep = lambda x: not skip_journal_pattern.match(x[1]) |
794 backupentries = [x for x in backupentries if keep(x)] |
809 backupentries = [x for x in backupentries if keep(x)] |
795 |
810 |
796 _playback( |
811 _playback( |