~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: 2011-04-16 01:09:56 UTC
  • mfrom: (5784.1.4 760435-less-fail)
  • Revision ID: pqm@pqm.ubuntu.com-20110416010956-5wrpm136qq2hz5f3
(mbp) rename and deprecate failUnlessExists and failIfExists (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    errors,
27
27
    index as _mod_index,
28
28
    inventory,
 
29
    knit,
29
30
    osutils,
30
31
    pack,
31
32
    revision as _mod_revision,
605
606
    def __init__(self, *args, **kwargs):
606
607
        super(GCCHKCanonicalizingPacker, self).__init__(*args, **kwargs)
607
608
        self._data_changed = False
608
 
 
 
609
    
609
610
    def _exhaust_stream(self, source_vf, keys, message, vf_to_stream, pb_offset):
610
611
        """Create and exhaust a stream, but don't insert it.
611
 
 
 
612
        
612
613
        This is useful to get the side-effects of generating a stream.
613
614
        """
614
615
        self.pb.update('scanning %s' % (message,), pb_offset)
703
704
 
704
705
    pack_factory = GCPack
705
706
    resumed_pack_factory = ResumedGCPack
706
 
    normal_packer_class = GCCHKPacker
707
 
    optimising_packer_class = GCCHKPacker
708
707
 
709
708
    def _check_new_inventories(self):
710
709
        """Detect missing inventories or chk root entries for the new revisions
792
791
                % (sorted(missing_text_keys),))
793
792
        return problems
794
793
 
 
794
    def _execute_pack_operations(self, pack_operations,
 
795
                                 _packer_class=GCCHKPacker,
 
796
                                 reload_func=None):
 
797
        """Execute a series of pack operations.
 
798
 
 
799
        :param pack_operations: A list of [revision_count, packs_to_combine].
 
800
        :param _packer_class: The class of packer to use (default: Packer).
 
801
        :return: None.
 
802
        """
 
803
        # XXX: Copied across from RepositoryPackCollection simply because we
 
804
        #      want to override the _packer_class ... :(
 
805
        for revision_count, packs in pack_operations:
 
806
            # we may have no-ops from the setup logic
 
807
            if len(packs) == 0:
 
808
                continue
 
809
            packer = GCCHKPacker(self, packs, '.autopack',
 
810
                                 reload_func=reload_func)
 
811
            try:
 
812
                result = packer.pack()
 
813
            except errors.RetryWithNewPacks:
 
814
                # An exception is propagating out of this context, make sure
 
815
                # this packer has cleaned up. Packer() doesn't set its new_pack
 
816
                # state into the RepositoryPackCollection object, so we only
 
817
                # have access to it directly here.
 
818
                if packer.new_pack is not None:
 
819
                    packer.new_pack.abort()
 
820
                raise
 
821
            if result is None:
 
822
                return
 
823
            for pack in packs:
 
824
                self._remove_pack_from_memory(pack)
 
825
        # record the newly available packs and stop advertising the old
 
826
        # packs
 
827
        to_be_obsoleted = []
 
828
        for _, packs in pack_operations:
 
829
            to_be_obsoleted.extend(packs)
 
830
        result = self._save_pack_names(clear_obsolete_packs=True,
 
831
                                       obsolete_packs=to_be_obsoleted)
 
832
        return result
 
833
 
795
834
 
796
835
class CHKInventoryRepository(PackRepository):
797
836
    """subclass of PackRepository that uses CHK based inventories."""
799
838
    def __init__(self, _format, a_bzrdir, control_files, _commit_builder_class,
800
839
        _serializer):
801
840
        """Overridden to change pack collection class."""
802
 
        super(CHKInventoryRepository, self).__init__(_format, a_bzrdir,
803
 
            control_files, _commit_builder_class, _serializer)
 
841
        super(CHKInventoryRepository, self).__init__(_format, a_bzrdir, control_files,
 
842
            _commit_builder_class, _serializer)
804
843
        index_transport = self._transport.clone('indices')
805
844
        self._pack_collection = GCRepositoryPackCollection(self,
806
845
            self._transport, index_transport,
1109
1148
            return GroupCHKStreamSource(self, to_format)
1110
1149
        return super(CHKInventoryRepository, self)._get_source(to_format)
1111
1150
 
1112
 
    def _find_inconsistent_revision_parents(self, revisions_iterator=None):
1113
 
        """Find revisions with different parent lists in the revision object
1114
 
        and in the index graph.
1115
 
 
1116
 
        :param revisions_iterator: None, or an iterator of (revid,
1117
 
            Revision-or-None). This iterator controls the revisions checked.
1118
 
        :returns: an iterator yielding tuples of (revison-id, parents-in-index,
1119
 
            parents-in-revision).
1120
 
        """
1121
 
        if not self.is_locked():
1122
 
            raise AssertionError()
1123
 
        vf = self.revisions
1124
 
        if revisions_iterator is None:
1125
 
            revisions_iterator = self._iter_revisions(None)
1126
 
        for revid, revision in revisions_iterator:
1127
 
            if revision is None:
1128
 
                pass
1129
 
            parent_map = vf.get_parent_map([(revid,)])
1130
 
            parents_according_to_index = tuple(parent[-1] for parent in
1131
 
                parent_map[(revid,)])
1132
 
            parents_according_to_revision = tuple(revision.parent_ids)
1133
 
            if parents_according_to_index != parents_according_to_revision:
1134
 
                yield (revid, parents_according_to_index,
1135
 
                    parents_according_to_revision)
1136
 
 
1137
 
    def _check_for_inconsistent_revision_parents(self):
1138
 
        inconsistencies = list(self._find_inconsistent_revision_parents())
1139
 
        if inconsistencies:
1140
 
            raise errors.BzrCheckError(
1141
 
                "Revision index has inconsistent parents.")
1142
 
 
1143
1151
 
1144
1152
class GroupCHKStreamSource(StreamSource):
1145
1153
    """Used when both the source and target repo are GroupCHK repos."""