~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/groupcompress_repo.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-06-18 19:13:45 UTC
  • mfrom: (4360.4.17 1.15-pack-source)
  • Revision ID: pqm@pqm.ubuntu.com-20090618191345-vgsr5zv78uesqsdg
(jam) Get rid of InterPackRepository in favor of PackStreamSource.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    Pack,
49
49
    NewPack,
50
50
    KnitPackRepository,
 
51
    KnitPackStreamSource,
51
52
    PackRootCommitBuilder,
52
53
    RepositoryPackCollection,
53
54
    RepositoryFormatPack,
736
737
        # make it raise to trap naughty direct users.
737
738
        raise NotImplementedError(self._iter_inventory_xmls)
738
739
 
739
 
    def _find_parent_ids_of_revisions(self, revision_ids):
740
 
        # TODO: we probably want to make this a helper that other code can get
741
 
        #       at
742
 
        parent_map = self.get_parent_map(revision_ids)
743
 
        parents = set()
744
 
        map(parents.update, parent_map.itervalues())
745
 
        parents.difference_update(revision_ids)
746
 
        parents.discard(_mod_revision.NULL_REVISION)
747
 
        return parents
748
 
 
749
 
    def _find_present_inventory_ids(self, revision_ids):
750
 
        keys = [(r,) for r in revision_ids]
751
 
        parent_map = self.inventories.get_parent_map(keys)
752
 
        present_inventory_ids = set(k[-1] for k in parent_map)
753
 
        return present_inventory_ids
 
740
    def _find_present_inventory_keys(self, revision_keys):
 
741
        parent_map = self.inventories.get_parent_map(revision_keys)
 
742
        present_inventory_keys = set(k for k in parent_map)
 
743
        return present_inventory_keys
754
744
 
755
745
    def fileids_altered_by_revision_ids(self, revision_ids, _inv_weave=None):
756
746
        """Find the file ids and versions affected by revisions.
767
757
        file_id_revisions = {}
768
758
        pb = ui.ui_factory.nested_progress_bar()
769
759
        try:
770
 
            parent_ids = self._find_parent_ids_of_revisions(revision_ids)
771
 
            present_parent_inv_ids = self._find_present_inventory_ids(parent_ids)
 
760
            revision_keys = [(r,) for r in revision_ids]
 
761
            parent_keys = self._find_parent_keys_of_revisions(revision_keys)
 
762
            # TODO: instead of using _find_present_inventory_keys, change the
 
763
            #       code paths to allow missing inventories to be tolerated.
 
764
            #       However, we only want to tolerate missing parent
 
765
            #       inventories, not missing inventories for revision_ids
 
766
            present_parent_inv_keys = self._find_present_inventory_keys(
 
767
                                        parent_keys)
 
768
            present_parent_inv_ids = set(
 
769
                [k[-1] for k in present_parent_inv_keys])
772
770
            uninteresting_root_keys = set()
773
771
            interesting_root_keys = set()
774
 
            inventories_to_read = set(present_parent_inv_ids)
775
 
            inventories_to_read.update(revision_ids)
 
772
            inventories_to_read = set(revision_ids)
 
773
            inventories_to_read.update(present_parent_inv_ids)
776
774
            for inv in self.iter_inventories(inventories_to_read):
777
775
                entry_chk_root_key = inv.id_to_entry.key()
778
776
                if inv.revision_id in present_parent_inv_ids:
846
844
        return super(CHKInventoryRepository, self)._get_source(to_format)
847
845
 
848
846
 
849
 
class GroupCHKStreamSource(repository.StreamSource):
 
847
class GroupCHKStreamSource(KnitPackStreamSource):
850
848
    """Used when both the source and target repo are GroupCHK repos."""
851
849
 
852
850
    def __init__(self, from_repository, to_format):
854
852
        super(GroupCHKStreamSource, self).__init__(from_repository, to_format)
855
853
        self._revision_keys = None
856
854
        self._text_keys = None
 
855
        self._text_fetch_order = 'groupcompress'
857
856
        self._chk_id_roots = None
858
857
        self._chk_p_id_roots = None
859
858
 
898
897
            p_id_roots_set.clear()
899
898
        return ('inventories', _filtered_inv_stream())
900
899
 
901
 
    def _find_present_inventories(self, revision_ids):
902
 
        revision_keys = [(r,) for r in revision_ids]
903
 
        inventories = self.from_repository.inventories
904
 
        present_inventories = inventories.get_parent_map(revision_keys)
905
 
        return [p[-1] for p in present_inventories]
906
 
 
907
 
    def _get_filtered_chk_streams(self, excluded_revision_ids):
 
900
    def _get_filtered_chk_streams(self, excluded_revision_keys):
908
901
        self._text_keys = set()
909
 
        excluded_revision_ids.discard(_mod_revision.NULL_REVISION)
910
 
        if not excluded_revision_ids:
 
902
        excluded_revision_keys.discard(_mod_revision.NULL_REVISION)
 
903
        if not excluded_revision_keys:
911
904
            uninteresting_root_keys = set()
912
905
            uninteresting_pid_root_keys = set()
913
906
        else:
915
908
            # actually present
916
909
            # TODO: Update Repository.iter_inventories() to add
917
910
            #       ignore_missing=True
918
 
            present_ids = self.from_repository._find_present_inventory_ids(
919
 
                            excluded_revision_ids)
920
 
            present_ids = self._find_present_inventories(excluded_revision_ids)
 
911
            present_keys = self.from_repository._find_present_inventory_keys(
 
912
                            excluded_revision_keys)
 
913
            present_ids = [k[-1] for k in present_keys]
921
914
            uninteresting_root_keys = set()
922
915
            uninteresting_pid_root_keys = set()
923
916
            for inv in self.from_repository.iter_inventories(present_ids):
948
941
            self._chk_p_id_roots = None
949
942
        yield 'chk_bytes', _get_parent_id_basename_to_file_id_pages()
950
943
 
951
 
    def _get_text_stream(self):
952
 
        # Note: We know we don't have to handle adding root keys, because both
953
 
        # the source and target are GCCHK, and those always support rich-roots
954
 
        # We may want to request as 'unordered', in case the source has done a
955
 
        # 'split' packing
956
 
        return ('texts', self.from_repository.texts.get_record_stream(
957
 
                            self._text_keys, 'groupcompress', False))
958
 
 
959
944
    def get_stream(self, search):
960
945
        revision_ids = search.get_keys()
961
946
        for stream_info in self._fetch_revision_texts(revision_ids):
966
951
        # For now, exclude all parents that are at the edge of ancestry, for
967
952
        # which we have inventories
968
953
        from_repo = self.from_repository
969
 
        parent_ids = from_repo._find_parent_ids_of_revisions(revision_ids)
970
 
        for stream_info in self._get_filtered_chk_streams(parent_ids):
 
954
        parent_keys = from_repo._find_parent_keys_of_revisions(
 
955
                        self._revision_keys)
 
956
        for stream_info in self._get_filtered_chk_streams(parent_keys):
971
957
            yield stream_info
972
958
        yield self._get_text_stream()
973
959
 
991
977
        # no unavailable texts when the ghost inventories are not filled in.
992
978
        yield self._get_inventory_stream(missing_inventory_keys,
993
979
                                         allow_absent=True)
994
 
        # We use the empty set for excluded_revision_ids, to make it clear that
995
 
        # we want to transmit all referenced chk pages.
 
980
        # We use the empty set for excluded_revision_keys, to make it clear
 
981
        # that we want to transmit all referenced chk pages.
996
982
        for stream_info in self._get_filtered_chk_streams(set()):
997
983
            yield stream_info
998
984