/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bundle/serializer/v4.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 
49
49
    def __init__(self, repo, inventory_keys):
50
50
        super(_MPDiffInventoryGenerator, self).__init__(repo.inventories,
51
 
            inventory_keys)
 
51
                                                        inventory_keys)
52
52
        self.repo = repo
53
53
        self.sha1s = {}
54
54
 
139
139
        metadata = {b'parents': parents,
140
140
                    b'storage_kind': b'mpdiff'}
141
141
        self._add_record(bytes, {b'parents': parents,
142
 
            b'storage_kind': b'fulltext'}, repo_kind, revision_id, None)
 
142
                                 b'storage_kind': b'fulltext'}, repo_kind, revision_id, None)
143
143
 
144
144
    def add_info_record(self, kwargs):
145
145
        """Add an info record to the bundle
154
154
    def encode_name(content_kind, revision_id, file_id=None):
155
155
        """Encode semantic ids as a container name"""
156
156
        if content_kind not in ('revision', 'file', 'inventory', 'signature',
157
 
                'info'):
 
157
                                'info'):
158
158
            raise ValueError(content_kind)
159
159
        if content_kind == 'file':
160
160
            if file_id is None:
333
333
        """Write bundle records for all revisions of all files"""
334
334
        text_keys = []
335
335
        altered_fileids = self.repository.fileids_altered_by_revision_ids(
336
 
                self.revision_ids)
 
336
            self.revision_ids)
337
337
        for file_id, revision_ids in viewitems(altered_fileids):
338
338
            for revision_id in revision_ids:
339
339
                text_keys.append((file_id, revision_id))
343
343
        """Write bundle records for all revisions and signatures"""
344
344
        inv_vf = self.repository.inventories
345
345
        topological_order = [key[-1] for key in multiparent.topo_iter_keys(
346
 
                                inv_vf, self.revision_keys)]
 
346
            inv_vf, self.revision_keys)]
347
347
        revision_order = topological_order
348
348
        if self.target is not None and self.target in self.revision_ids:
349
349
            # Make sure the target revision is always the last entry
389
389
            parents = parent_map.get(revision_id, None)
390
390
            revision_text = revision_to_bytes(revision)
391
391
            self.bundle.add_fulltext_record(revision_text, parents,
392
 
                                       'revision', revision_id)
 
392
                                            'revision', revision_id)
393
393
            try:
394
394
                self.bundle.add_fulltext_record(
395
395
                    self.repository.get_signature_text(
396
 
                    revision_id), parents, 'signature', revision_id)
 
396
                        revision_id), parents, 'signature', revision_id)
397
397
            except errors.NoSuchRevision:
398
398
                pass
399
399
 
434
434
class BundleInfoV4(object):
435
435
 
436
436
    """Provide (most of) the BundleInfo interface"""
 
437
 
437
438
    def __init__(self, fileobj, serializer):
438
439
        self._fileobj = fileobj
439
440
        self._serializer = serializer
478
479
            self.__real_revisions = []
479
480
            bundle_reader = self.get_bundle_reader()
480
481
            for bytes, metadata, repo_kind, revision_id, file_id in \
481
 
                bundle_reader.iter_records():
 
482
                    bundle_reader.iter_records():
482
483
                if repo_kind == 'info':
483
484
                    serializer =\
484
485
                        self._serializer.get_source_serializer(metadata)
536
537
        added_inv = set()
537
538
        target_revision = None
538
539
        for bytes, metadata, repo_kind, revision_id, file_id in\
539
 
            self._container.iter_records():
 
540
                self._container.iter_records():
540
541
            if repo_kind == 'info':
541
542
                if self._info is not None:
542
543
                    raise AssertionError()
543
544
                self._handle_info(metadata)
544
545
            if (pending_file_records and
545
 
                (repo_kind, file_id) != ('file', current_file)):
 
546
                    (repo_kind, file_id) != ('file', current_file)):
546
547
                # Flush the data for a single file - prevents memory
547
548
                # spiking due to buffering all files in memory.
548
549
                self._install_mp_records_keys(self._repository.texts,
549
 
                    pending_file_records)
 
550
                                              pending_file_records)
550
551
                current_file = None
551
552
                del pending_file_records[:]
552
553
            if len(pending_inventory_records) > 0 and repo_kind != 'inventory':
553
554
                self._install_inventory_records(pending_inventory_records)
554
555
                pending_inventory_records = []
555
556
            if repo_kind == 'inventory':
556
 
                pending_inventory_records.append(((revision_id,), metadata, bytes))
 
557
                pending_inventory_records.append(
 
558
                    ((revision_id,), metadata, bytes))
557
559
            if repo_kind == 'revision':
558
560
                target_revision = revision_id
559
561
                self._install_revision(revision_id, metadata, bytes)
561
563
                self._install_signature(revision_id, metadata, bytes)
562
564
            if repo_kind == 'file':
563
565
                current_file = file_id
564
 
                pending_file_records.append(((file_id, revision_id), metadata, bytes))
565
 
        self._install_mp_records_keys(self._repository.texts, pending_file_records)
 
566
                pending_file_records.append(
 
567
                    ((file_id, revision_id), metadata, bytes))
 
568
        self._install_mp_records_keys(
 
569
            self._repository.texts, pending_file_records)
566
570
        return target_revision
567
571
 
568
572
    def _handle_info(self, info):
570
574
        self._info = info
571
575
        self._source_serializer = self._serializer.get_source_serializer(info)
572
576
        if (info[b'supports_rich_root'] == 0 and
573
 
            self._repository.supports_rich_root()):
 
577
                self._repository.supports_rich_root()):
574
578
            self.update_root = True
575
579
        else:
576
580
            self.update_root = False
619
623
            # installed yet.)
620
624
            parent_keys = [(r,) for r in remaining_parent_ids]
621
625
            present_parent_map = self._repository.inventories.get_parent_map(
622
 
                                        parent_keys)
 
626
                parent_keys)
623
627
            present_parent_ids = []
624
628
            ghosts = set()
625
629
            for p_id in remaining_parent_ids:
629
633
                    ghosts.add(p_id)
630
634
            to_string = self._source_serializer.write_inventory_to_string
631
635
            for parent_inv in self._repository.iter_inventories(
632
 
                                    present_parent_ids):
 
636
                    present_parent_ids):
633
637
                p_text = to_string(parent_inv)
634
638
                inventory_cache[parent_inv.revision_id] = parent_inv
635
639
                cached_parent_texts[parent_inv.revision_id] = p_text
637
641
 
638
642
        parent_texts = [cached_parent_texts[parent_id]
639
643
                        for parent_id in parent_ids
640
 
                         if parent_id not in ghosts]
 
644
                        if parent_id not in ghosts]
641
645
        return parent_texts
642
646
 
643
647
    def _install_inventory_records(self, records):
644
648
        if (self._info[b'serializer'] == self._repository._serializer.format_num
645
 
            and self._repository._serializer.support_altered_by_hack):
 
649
                and self._repository._serializer.support_altered_by_hack):
646
650
            return self._install_mp_records_keys(self._repository.inventories,
647
 
                records)
 
651
                                                 records)
648
652
        # Use a 10MB text cache, since these are string xml inventories. Note
649
653
        # that 10MB is fairly small for large projects (a single inventory can
650
654
        # be >5MB). Another possibility is to cache 10-20 inventory texts
651
655
        # instead
652
 
        inventory_text_cache = lru_cache.LRUSizeCache(10*1024*1024)
 
656
        inventory_text_cache = lru_cache.LRUSizeCache(10 * 1024 * 1024)
653
657
        # Also cache the in-memory representation. This allows us to create
654
658
        # inventory deltas to apply rather than calling add_inventory from
655
659
        # scratch each time.
670
674
                # it would have to cast to a list of lines, which we get back
671
675
                # as lines and then cast back to a string.
672
676
                target_lines = multiparent.MultiParent.from_patch(bytes
673
 
                            ).to_lines(p_texts)
 
677
                                                                  ).to_lines(p_texts)
674
678
                inv_text = b''.join(target_lines)
675
679
                del target_lines
676
680
                sha1 = osutils.sha_string(inv_text)
691
695
                    else:
692
696
                        delta = target_inv._make_delta(parent_inv)
693
697
                        self._repository.add_inventory_by_delta(parent_ids[0],
694
 
                            delta, revision_id, parent_ids)
 
698
                                                                delta, revision_id, parent_ids)
695
699
                except errors.UnsupportedInventoryKind:
696
700
                    raise errors.IncompatibleRevision(repr(self._repository))
697
701
                inventory_cache[revision_id] = target_inv
701
705
        if self.update_root:
702
706
            text_key = (target_inv.root.file_id, revision_id)
703
707
            parent_keys = [(target_inv.root.file_id, parent) for
704
 
                parent in parent_ids]
 
708
                           parent in parent_ids]
705
709
            self._repository.texts.add_lines(text_key, parent_keys, [])
706
710
        elif not self._repository.supports_rich_root():
707
711
            if target_inv.root.revision != revision_id: