~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/groupcompress_repo.py

  • Committer: Ian Clatworthy
  • Date: 2009-12-03 23:21:16 UTC
  • mfrom: (4852.4.1 RCStoVCS)
  • mto: This revision was merged to the branch mainline in revision 4860.
  • Revision ID: ian.clatworthy@canonical.com-20091203232116-f8igfvc6muqrn4yx
Revision Control -> Version Control in docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd
 
1
# Copyright (C) 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Repository formats using CHK inventories and groupcompress compression."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
import time
22
20
 
23
21
from bzrlib import (
24
 
    controldir,
 
22
    bzrdir,
25
23
    chk_map,
26
24
    chk_serializer,
27
25
    debug,
28
26
    errors,
29
27
    index as _mod_index,
30
28
    inventory,
 
29
    knit,
31
30
    osutils,
32
31
    pack,
 
32
    remote,
33
33
    revision as _mod_revision,
34
34
    trace,
35
35
    ui,
36
 
    versionedfile,
37
36
    )
38
37
from bzrlib.btree_index import (
39
38
    BTreeGraphIndex,
40
39
    BTreeBuilder,
41
40
    )
42
 
from bzrlib.decorators import needs_write_lock
43
41
from bzrlib.groupcompress import (
44
42
    _GCGraphIndex,
45
43
    GroupCompressVersionedFiles,
46
44
    )
47
45
from bzrlib.repofmt.pack_repo import (
48
 
    _DirectPackAccess,
49
46
    Pack,
50
47
    NewPack,
51
 
    PackRepository,
 
48
    KnitPackRepository,
 
49
    KnitPackStreamSource,
52
50
    PackRootCommitBuilder,
53
51
    RepositoryPackCollection,
54
52
    RepositoryFormatPack,
55
53
    ResumedPack,
56
54
    Packer,
57
55
    )
58
 
from bzrlib.vf_repository import (
59
 
    StreamSource,
60
 
    )
61
56
from bzrlib.static_tuple import StaticTuple
62
57
 
63
58
 
268
263
        remaining_keys = set(keys)
269
264
        counter = [0]
270
265
        if self._gather_text_refs:
 
266
            bytes_to_info = inventory.CHKInventory._bytes_to_utf8name_key
271
267
            self._text_refs = set()
272
268
        def _get_referenced_stream(root_keys, parse_leaf_nodes=False):
273
269
            cur_keys = root_keys
294
290
                    # Store is None, because we know we have a LeafNode, and we
295
291
                    # just want its entries
296
292
                    for file_id, bytes in node.iteritems(None):
297
 
                        self._text_refs.add(chk_map._bytes_to_text_key(bytes))
 
293
                        name_utf8, file_id, revision_id = bytes_to_info(bytes)
 
294
                        self._text_refs.add((file_id, revision_id))
298
295
                def next_stream():
299
296
                    stream = source_vf.get_record_stream(cur_keys,
300
297
                                                         'as-requested', True)
356
353
        """Build a VersionedFiles instance on top of this group of packs."""
357
354
        index_name = index_name + '_index'
358
355
        index_to_pack = {}
359
 
        access = _DirectPackAccess(index_to_pack,
360
 
                                   reload_func=self._reload_func)
 
356
        access = knit._DirectPackAccess(index_to_pack)
361
357
        if for_write:
362
358
            # Use new_pack
363
359
            if self.new_pack is None:
425
421
        inventory_keys = source_vf.keys()
426
422
        missing_inventories = set(self.revision_keys).difference(inventory_keys)
427
423
        if missing_inventories:
428
 
            # Go back to the original repo, to see if these are really missing
429
 
            # https://bugs.launchpad.net/bzr/+bug/437003
430
 
            # If we are packing a subset of the repo, it is fine to just have
431
 
            # the data in another Pack file, which is not included in this pack
432
 
            # operation.
433
 
            inv_index = self._pack_collection.repo.inventories._index
434
 
            pmap = inv_index.get_parent_map(missing_inventories)
435
 
            really_missing = missing_inventories.difference(pmap)
436
 
            if really_missing:
437
 
                missing_inventories = sorted(really_missing)
438
 
                raise ValueError('We are missing inventories for revisions: %s'
439
 
                    % (missing_inventories,))
 
424
            missing_inventories = sorted(missing_inventories)
 
425
            raise ValueError('We are missing inventories for revisions: %s'
 
426
                % (missing_inventories,))
440
427
        self._copy_stream(source_vf, target_vf, inventory_keys,
441
428
                          'inventories', self._get_filtered_inv_stream, 2)
442
429
 
443
 
    def _get_chk_vfs_for_copy(self):
444
 
        return self._build_vfs('chk', False, False)
445
 
 
446
430
    def _copy_chk_texts(self):
447
 
        source_vf, target_vf = self._get_chk_vfs_for_copy()
 
431
        source_vf, target_vf = self._build_vfs('chk', False, False)
448
432
        # TODO: This is technically spurious... if it is a performance issue,
449
433
        #       remove it
450
434
        total_keys = source_vf.keys()
596
580
        return new_pack.data_inserted() and self._data_changed
597
581
 
598
582
 
599
 
class GCCHKCanonicalizingPacker(GCCHKPacker):
600
 
    """A packer that ensures inventories have canonical-form CHK maps.
601
 
    
602
 
    Ideally this would be part of reconcile, but it's very slow and rarely
603
 
    needed.  (It repairs repositories affected by
604
 
    https://bugs.launchpad.net/bzr/+bug/522637).
605
 
    """
606
 
 
607
 
    def __init__(self, *args, **kwargs):
608
 
        super(GCCHKCanonicalizingPacker, self).__init__(*args, **kwargs)
609
 
        self._data_changed = False
610
 
 
611
 
    def _exhaust_stream(self, source_vf, keys, message, vf_to_stream, pb_offset):
612
 
        """Create and exhaust a stream, but don't insert it.
613
 
 
614
 
        This is useful to get the side-effects of generating a stream.
615
 
        """
616
 
        self.pb.update('scanning %s' % (message,), pb_offset)
617
 
        child_pb = ui.ui_factory.nested_progress_bar()
618
 
        try:
619
 
            list(vf_to_stream(source_vf, keys, message, child_pb))
620
 
        finally:
621
 
            child_pb.finished()
622
 
 
623
 
    def _copy_inventory_texts(self):
624
 
        source_vf, target_vf = self._build_vfs('inventory', True, True)
625
 
        source_chk_vf, target_chk_vf = self._get_chk_vfs_for_copy()
626
 
        inventory_keys = source_vf.keys()
627
 
        # First, copy the existing CHKs on the assumption that most of them
628
 
        # will be correct.  This will save us from having to reinsert (and
629
 
        # recompress) these records later at the cost of perhaps preserving a
630
 
        # few unused CHKs. 
631
 
        # (Iterate but don't insert _get_filtered_inv_stream to populate the
632
 
        # variables needed by GCCHKPacker._copy_chk_texts.)
633
 
        self._exhaust_stream(source_vf, inventory_keys, 'inventories',
634
 
                self._get_filtered_inv_stream, 2)
635
 
        GCCHKPacker._copy_chk_texts(self)
636
 
        # Now copy and fix the inventories, and any regenerated CHKs.
637
 
        def chk_canonicalizing_inv_stream(source_vf, keys, message, pb=None):
638
 
            return self._get_filtered_canonicalizing_inv_stream(
639
 
                source_vf, keys, message, pb, source_chk_vf, target_chk_vf)
640
 
        self._copy_stream(source_vf, target_vf, inventory_keys,
641
 
                          'inventories', chk_canonicalizing_inv_stream, 4)
642
 
 
643
 
    def _copy_chk_texts(self):
644
 
        # No-op; in this class this happens during _copy_inventory_texts.
645
 
        pass
646
 
 
647
 
    def _get_filtered_canonicalizing_inv_stream(self, source_vf, keys, message,
648
 
            pb=None, source_chk_vf=None, target_chk_vf=None):
649
 
        """Filter the texts of inventories, regenerating CHKs to make sure they
650
 
        are canonical.
651
 
        """
652
 
        total_keys = len(keys)
653
 
        target_chk_vf = versionedfile.NoDupeAddLinesDecorator(target_chk_vf)
654
 
        def _filtered_inv_stream():
655
 
            stream = source_vf.get_record_stream(keys, 'groupcompress', True)
656
 
            search_key_name = None
657
 
            for idx, record in enumerate(stream):
658
 
                # Inventories should always be with revisions; assume success.
659
 
                bytes = record.get_bytes_as('fulltext')
660
 
                chk_inv = inventory.CHKInventory.deserialise(
661
 
                    source_chk_vf, bytes, record.key)
662
 
                if pb is not None:
663
 
                    pb.update('inv', idx, total_keys)
664
 
                chk_inv.id_to_entry._ensure_root()
665
 
                if search_key_name is None:
666
 
                    # Find the name corresponding to the search_key_func
667
 
                    search_key_reg = chk_map.search_key_registry
668
 
                    for search_key_name, func in search_key_reg.iteritems():
669
 
                        if func == chk_inv.id_to_entry._search_key_func:
670
 
                            break
671
 
                canonical_inv = inventory.CHKInventory.from_inventory(
672
 
                    target_chk_vf, chk_inv,
673
 
                    maximum_size=chk_inv.id_to_entry._root_node._maximum_size,
674
 
                    search_key_name=search_key_name)
675
 
                if chk_inv.id_to_entry.key() != canonical_inv.id_to_entry.key():
676
 
                    trace.mutter(
677
 
                        'Non-canonical CHK map for id_to_entry of inv: %s '
678
 
                        '(root is %s, should be %s)' % (chk_inv.revision_id,
679
 
                        chk_inv.id_to_entry.key()[0],
680
 
                        canonical_inv.id_to_entry.key()[0]))
681
 
                    self._data_changed = True
682
 
                p_id_map = chk_inv.parent_id_basename_to_file_id
683
 
                p_id_map._ensure_root()
684
 
                canon_p_id_map = canonical_inv.parent_id_basename_to_file_id
685
 
                if p_id_map.key() != canon_p_id_map.key():
686
 
                    trace.mutter(
687
 
                        'Non-canonical CHK map for parent_id_to_basename of '
688
 
                        'inv: %s (root is %s, should be %s)'
689
 
                        % (chk_inv.revision_id, p_id_map.key()[0],
690
 
                           canon_p_id_map.key()[0]))
691
 
                    self._data_changed = True
692
 
                yield versionedfile.ChunkedContentFactory(record.key,
693
 
                        record.parents, record.sha1,
694
 
                        canonical_inv.to_lines())
695
 
            # We have finished processing all of the inventory records, we
696
 
            # don't need these sets anymore
697
 
        return _filtered_inv_stream()
698
 
 
699
 
    def _use_pack(self, new_pack):
700
 
        """Override _use_pack to check for reconcile having changed content."""
701
 
        return new_pack.data_inserted() and self._data_changed
702
 
 
703
 
 
704
583
class GCRepositoryPackCollection(RepositoryPackCollection):
705
584
 
706
585
    pack_factory = GCPack
707
586
    resumed_pack_factory = ResumedGCPack
708
 
    normal_packer_class = GCCHKPacker
709
 
    optimising_packer_class = GCCHKPacker
710
587
 
711
588
    def _check_new_inventories(self):
712
589
        """Detect missing inventories or chk root entries for the new revisions
770
647
        chk_diff = chk_map.iter_interesting_nodes(
771
648
            chk_bytes_no_fallbacks, root_key_info.interesting_root_keys,
772
649
            root_key_info.uninteresting_root_keys)
 
650
        bytes_to_info = inventory.CHKInventory._bytes_to_utf8name_key
773
651
        text_keys = set()
774
652
        try:
775
 
            for record in _filter_text_keys(chk_diff, text_keys,
776
 
                                            chk_map._bytes_to_text_key):
 
653
            for record in _filter_text_keys(chk_diff, text_keys, bytes_to_info):
777
654
                pass
778
655
        except errors.NoSuchRevision, e:
779
656
            # XXX: It would be nice if we could give a more precise error here.
794
671
                % (sorted(missing_text_keys),))
795
672
        return problems
796
673
 
797
 
 
798
 
class CHKInventoryRepository(PackRepository):
799
 
    """subclass of PackRepository that uses CHK based inventories."""
 
674
    def _execute_pack_operations(self, pack_operations,
 
675
                                 _packer_class=GCCHKPacker,
 
676
                                 reload_func=None):
 
677
        """Execute a series of pack operations.
 
678
 
 
679
        :param pack_operations: A list of [revision_count, packs_to_combine].
 
680
        :param _packer_class: The class of packer to use (default: Packer).
 
681
        :return: None.
 
682
        """
 
683
        # XXX: Copied across from RepositoryPackCollection simply because we
 
684
        #      want to override the _packer_class ... :(
 
685
        for revision_count, packs in pack_operations:
 
686
            # we may have no-ops from the setup logic
 
687
            if len(packs) == 0:
 
688
                continue
 
689
            packer = GCCHKPacker(self, packs, '.autopack',
 
690
                                 reload_func=reload_func)
 
691
            try:
 
692
                result = packer.pack()
 
693
            except errors.RetryWithNewPacks:
 
694
                # An exception is propagating out of this context, make sure
 
695
                # this packer has cleaned up. Packer() doesn't set its new_pack
 
696
                # state into the RepositoryPackCollection object, so we only
 
697
                # have access to it directly here.
 
698
                if packer.new_pack is not None:
 
699
                    packer.new_pack.abort()
 
700
                raise
 
701
            if result is None:
 
702
                return
 
703
            for pack in packs:
 
704
                self._remove_pack_from_memory(pack)
 
705
        # record the newly available packs and stop advertising the old
 
706
        # packs
 
707
        result = self._save_pack_names(clear_obsolete_packs=True)
 
708
        # Move the old packs out of the way now they are no longer referenced.
 
709
        for revision_count, packs in pack_operations:
 
710
            self._obsolete_packs(packs)
 
711
        return result
 
712
 
 
713
 
 
714
class CHKInventoryRepository(KnitPackRepository):
 
715
    """subclass of KnitPackRepository that uses CHK based inventories."""
800
716
 
801
717
    def __init__(self, _format, a_bzrdir, control_files, _commit_builder_class,
802
718
        _serializer):
803
719
        """Overridden to change pack collection class."""
804
 
        super(CHKInventoryRepository, self).__init__(_format, a_bzrdir,
805
 
            control_files, _commit_builder_class, _serializer)
 
720
        KnitPackRepository.__init__(self, _format, a_bzrdir, control_files,
 
721
            _commit_builder_class, _serializer)
 
722
        # and now replace everything it did :)
806
723
        index_transport = self._transport.clone('indices')
807
724
        self._pack_collection = GCRepositoryPackCollection(self,
808
725
            self._transport, index_transport,
946
863
        if basis_inv is None:
947
864
            if basis_revision_id == _mod_revision.NULL_REVISION:
948
865
                new_inv = self._create_inv_from_null(delta, new_revision_id)
949
 
                if new_inv.root_id is None:
950
 
                    raise errors.RootMissing()
951
866
                inv_lines = new_inv.to_lines()
952
867
                return self._inventory_add_lines(new_revision_id, parents,
953
868
                    inv_lines, check_content=False), new_inv
954
869
            else:
955
870
                basis_tree = self.revision_tree(basis_revision_id)
956
871
                basis_tree.lock_read()
957
 
                basis_inv = basis_tree.root_inventory
 
872
                basis_inv = basis_tree.inventory
958
873
        try:
959
874
            result = basis_inv.create_by_apply_delta(delta, new_revision_id,
960
875
                propagate_caches=propagate_caches)
965
880
            if basis_tree is not None:
966
881
                basis_tree.unlock()
967
882
 
968
 
    def _deserialise_inventory(self, revision_id, bytes):
 
883
    def deserialise_inventory(self, revision_id, bytes):
969
884
        return inventory.CHKInventory.deserialise(self.chk_bytes, bytes,
970
885
            (revision_id,))
971
886
 
980
895
            if record.storage_kind != 'absent':
981
896
                texts[record.key] = record.get_bytes_as('fulltext')
982
897
            else:
983
 
                texts[record.key] = None
 
898
                raise errors.NoSuchRevision(self, record.key)
984
899
        for key in keys:
985
 
            bytes = texts[key]
986
 
            if bytes is None:
987
 
                yield (None, key[-1])
988
 
            else:
989
 
                yield (inventory.CHKInventory.deserialise(
990
 
                    self.chk_bytes, bytes, key), key[-1])
 
900
            yield inventory.CHKInventory.deserialise(self.chk_bytes, texts[key], key)
991
901
 
992
 
    def _get_inventory_xml(self, revision_id):
993
 
        """Get serialized inventory as a string."""
 
902
    def _iter_inventory_xmls(self, revision_ids, ordering):
994
903
        # Without a native 'xml' inventory, this method doesn't make sense.
995
904
        # However older working trees, and older bundles want it - so we supply
996
 
        # it allowing _get_inventory_xml to work. Bundles currently use the
 
905
        # it allowing get_inventory_xml to work. Bundles currently use the
997
906
        # serializer directly; this also isn't ideal, but there isn't an xml
998
 
        # iteration interface offered at all for repositories.
999
 
        return self._serializer.write_inventory_to_string(
1000
 
            self.get_inventory(revision_id))
 
907
        # iteration interface offered at all for repositories. We could make
 
908
        # _iter_inventory_xmls be part of the contract, even if kept private.
 
909
        inv_to_str = self._serializer.write_inventory_to_string
 
910
        for inv in self.iter_inventories(revision_ids, ordering=ordering):
 
911
            yield inv_to_str(inv), inv.revision_id
1001
912
 
1002
913
    def _find_present_inventory_keys(self, revision_keys):
1003
914
        parent_map = self.inventories.get_parent_map(revision_keys)
1087
998
        finally:
1088
999
            pb.finished()
1089
1000
 
1090
 
    @needs_write_lock
1091
 
    def reconcile_canonicalize_chks(self):
1092
 
        """Reconcile this repository to make sure all CHKs are in canonical
1093
 
        form.
1094
 
        """
1095
 
        from bzrlib.reconcile import PackReconciler
1096
 
        reconciler = PackReconciler(self, thorough=True, canonicalize_chks=True)
1097
 
        reconciler.reconcile()
1098
 
        return reconciler
1099
 
 
1100
1001
    def _reconcile_pack(self, collection, packs, extension, revs, pb):
1101
1002
        packer = GCCHKReconcilePacker(collection, packs, extension)
1102
1003
        return packer.pack(pb)
1103
1004
 
1104
 
    def _canonicalize_chks_pack(self, collection, packs, extension, revs, pb):
1105
 
        packer = GCCHKCanonicalizingPacker(collection, packs, extension, revs)
1106
 
        return packer.pack(pb)
1107
 
 
1108
1005
    def _get_source(self, to_format):
1109
1006
        """Return a source for streaming from this repository."""
1110
1007
        if self._format._serializer == to_format._serializer:
1115
1012
            return GroupCHKStreamSource(self, to_format)
1116
1013
        return super(CHKInventoryRepository, self)._get_source(to_format)
1117
1014
 
1118
 
    def _find_inconsistent_revision_parents(self, revisions_iterator=None):
1119
 
        """Find revisions with different parent lists in the revision object
1120
 
        and in the index graph.
1121
 
 
1122
 
        :param revisions_iterator: None, or an iterator of (revid,
1123
 
            Revision-or-None). This iterator controls the revisions checked.
1124
 
        :returns: an iterator yielding tuples of (revison-id, parents-in-index,
1125
 
            parents-in-revision).
1126
 
        """
1127
 
        if not self.is_locked():
1128
 
            raise AssertionError()
1129
 
        vf = self.revisions
1130
 
        if revisions_iterator is None:
1131
 
            revisions_iterator = self._iter_revisions(None)
1132
 
        for revid, revision in revisions_iterator:
1133
 
            if revision is None:
1134
 
                pass
1135
 
            parent_map = vf.get_parent_map([(revid,)])
1136
 
            parents_according_to_index = tuple(parent[-1] for parent in
1137
 
                parent_map[(revid,)])
1138
 
            parents_according_to_revision = tuple(revision.parent_ids)
1139
 
            if parents_according_to_index != parents_according_to_revision:
1140
 
                yield (revid, parents_according_to_index,
1141
 
                    parents_according_to_revision)
1142
 
 
1143
 
    def _check_for_inconsistent_revision_parents(self):
1144
 
        inconsistencies = list(self._find_inconsistent_revision_parents())
1145
 
        if inconsistencies:
1146
 
            raise errors.BzrCheckError(
1147
 
                "Revision index has inconsistent parents.")
1148
 
 
1149
 
 
1150
 
class GroupCHKStreamSource(StreamSource):
 
1015
 
 
1016
class GroupCHKStreamSource(KnitPackStreamSource):
1151
1017
    """Used when both the source and target repo are GroupCHK repos."""
1152
1018
 
1153
1019
    def __init__(self, from_repository, to_format):
1220
1086
                uninteresting_root_keys.add(inv.id_to_entry.key())
1221
1087
                uninteresting_pid_root_keys.add(
1222
1088
                    inv.parent_id_basename_to_file_id.key())
 
1089
        bytes_to_info = inventory.CHKInventory._bytes_to_utf8name_key
1223
1090
        chk_bytes = self.from_repository.chk_bytes
1224
1091
        def _filter_id_to_entry():
1225
1092
            interesting_nodes = chk_map.iter_interesting_nodes(chk_bytes,
1226
1093
                        self._chk_id_roots, uninteresting_root_keys)
1227
1094
            for record in _filter_text_keys(interesting_nodes, self._text_keys,
1228
 
                    chk_map._bytes_to_text_key):
 
1095
                    bytes_to_info):
1229
1096
                if record is not None:
1230
1097
                    yield record
1231
1098
            # Consumed
1240
1107
            self._chk_p_id_roots = None
1241
1108
        yield 'chk_bytes', _get_parent_id_basename_to_file_id_pages()
1242
1109
 
1243
 
    def _get_text_stream(self):
1244
 
        # Note: We know we don't have to handle adding root keys, because both
1245
 
        # the source and target are the identical network name.
1246
 
        text_stream = self.from_repository.texts.get_record_stream(
1247
 
                        self._text_keys, self._text_fetch_order, False)
1248
 
        return ('texts', text_stream)
1249
 
 
1250
1110
    def get_stream(self, search):
1251
 
        def wrap_and_count(pb, rc, stream):
1252
 
            """Yield records from stream while showing progress."""
1253
 
            count = 0
1254
 
            for record in stream:
1255
 
                if count == rc.STEP:
1256
 
                    rc.increment(count)
1257
 
                    pb.update('Estimate', rc.current, rc.max)
1258
 
                    count = 0
1259
 
                count += 1
1260
 
                yield record
1261
 
 
1262
1111
        revision_ids = search.get_keys()
1263
 
        pb = ui.ui_factory.nested_progress_bar()
1264
 
        rc = self._record_counter
1265
 
        self._record_counter.setup(len(revision_ids))
1266
1112
        for stream_info in self._fetch_revision_texts(revision_ids):
1267
 
            yield (stream_info[0],
1268
 
                wrap_and_count(pb, rc, stream_info[1]))
 
1113
            yield stream_info
1269
1114
        self._revision_keys = [(rev_id,) for rev_id in revision_ids]
 
1115
        self.from_repository.revisions.clear_cache()
 
1116
        self.from_repository.signatures.clear_cache()
 
1117
        yield self._get_inventory_stream(self._revision_keys)
 
1118
        self.from_repository.inventories.clear_cache()
1270
1119
        # TODO: The keys to exclude might be part of the search recipe
1271
1120
        # For now, exclude all parents that are at the edge of ancestry, for
1272
1121
        # which we have inventories
1273
1122
        from_repo = self.from_repository
1274
1123
        parent_keys = from_repo._find_parent_keys_of_revisions(
1275
1124
                        self._revision_keys)
1276
 
        self.from_repository.revisions.clear_cache()
1277
 
        self.from_repository.signatures.clear_cache()
1278
 
        # Clear the repo's get_parent_map cache too.
1279
 
        self.from_repository._unstacked_provider.disable_cache()
1280
 
        self.from_repository._unstacked_provider.enable_cache()
1281
 
        s = self._get_inventory_stream(self._revision_keys)
1282
 
        yield (s[0], wrap_and_count(pb, rc, s[1]))
1283
 
        self.from_repository.inventories.clear_cache()
1284
1125
        for stream_info in self._get_filtered_chk_streams(parent_keys):
1285
 
            yield (stream_info[0], wrap_and_count(pb, rc, stream_info[1]))
 
1126
            yield stream_info
1286
1127
        self.from_repository.chk_bytes.clear_cache()
1287
 
        s = self._get_text_stream()
1288
 
        yield (s[0], wrap_and_count(pb, rc, s[1]))
 
1128
        yield self._get_text_stream()
1289
1129
        self.from_repository.texts.clear_cache()
1290
 
        pb.update('Done', rc.max, rc.max)
1291
 
        pb.finished()
1292
1130
 
1293
1131
    def get_stream_for_missing_keys(self, missing_keys):
1294
1132
        # missing keys can only occur when we are byte copying and not
1348
1186
    return result
1349
1187
 
1350
1188
 
1351
 
def _filter_text_keys(interesting_nodes_iterable, text_keys, bytes_to_text_key):
 
1189
def _filter_text_keys(interesting_nodes_iterable, text_keys, bytes_to_info):
1352
1190
    """Iterate the result of iter_interesting_nodes, yielding the records
1353
1191
    and adding to text_keys.
1354
1192
    """
1355
 
    text_keys_update = text_keys.update
1356
1193
    for record, items in interesting_nodes_iterable:
1357
 
        text_keys_update([bytes_to_text_key(b) for n,b in items])
 
1194
        for name, bytes in items:
 
1195
            # Note: we don't care about name_utf8, because groupcompress repos
 
1196
            # are always rich-root, so there are no synthesised root records to
 
1197
            # ignore.
 
1198
            _, file_id, revision_id = bytes_to_info(bytes)
 
1199
            file_id = intern(file_id)
 
1200
            revision_id = intern(revision_id)
 
1201
            text_keys.add(StaticTuple(file_id, revision_id).intern())
1358
1202
        yield record
1359
1203
 
1360
1204
 
1361
 
class RepositoryFormat2a(RepositoryFormatPack):
1362
 
    """A CHK repository that uses the bencode revision serializer."""
 
1205
 
 
1206
 
 
1207
class RepositoryFormatCHK1(RepositoryFormatPack):
 
1208
    """A hashed CHK+group compress pack repository."""
1363
1209
 
1364
1210
    repository_class = CHKInventoryRepository
1365
1211
    supports_external_lookups = True
1366
1212
    supports_chks = True
 
1213
    # For right now, setting this to True gives us InterModel1And2 rather
 
1214
    # than InterDifferingSerializer
1367
1215
    _commit_builder_class = PackRootCommitBuilder
1368
1216
    rich_root_data = True
1369
 
    _serializer = chk_serializer.chk_bencode_serializer
 
1217
    _serializer = chk_serializer.chk_serializer_255_bigpage
1370
1218
    _commit_inv_deltas = True
1371
1219
    # What index classes to use
1372
1220
    index_builder_class = BTreeBuilder
1383
1231
    pack_compresses = True
1384
1232
 
1385
1233
    def _get_matching_bzrdir(self):
1386
 
        return controldir.format_registry.make_bzrdir('2a')
1387
 
 
1388
 
    def _ignore_setting_bzrdir(self, format):
1389
 
        pass
1390
 
 
1391
 
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
1392
 
 
1393
 
    @classmethod
1394
 
    def get_format_string(cls):
 
1234
        return bzrdir.format_registry.make_bzrdir('development6-rich-root')
 
1235
 
 
1236
    def _ignore_setting_bzrdir(self, format):
 
1237
        pass
 
1238
 
 
1239
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
1240
 
 
1241
    def get_format_string(self):
 
1242
        """See RepositoryFormat.get_format_string()."""
 
1243
        return ('Bazaar development format - group compression and chk inventory'
 
1244
                ' (needs bzr.dev from 1.14)\n')
 
1245
 
 
1246
    def get_format_description(self):
 
1247
        """See RepositoryFormat.get_format_description()."""
 
1248
        return ("Development repository format - rich roots, group compression"
 
1249
            " and chk inventories")
 
1250
 
 
1251
 
 
1252
class RepositoryFormatCHK2(RepositoryFormatCHK1):
 
1253
    """A CHK repository that uses the bencode revision serializer."""
 
1254
 
 
1255
    _serializer = chk_serializer.chk_bencode_serializer
 
1256
 
 
1257
    def _get_matching_bzrdir(self):
 
1258
        return bzrdir.format_registry.make_bzrdir('development7-rich-root')
 
1259
 
 
1260
    def _ignore_setting_bzrdir(self, format):
 
1261
        pass
 
1262
 
 
1263
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
1264
 
 
1265
    def get_format_string(self):
 
1266
        """See RepositoryFormat.get_format_string()."""
 
1267
        return ('Bazaar development format - chk repository with bencode '
 
1268
                'revision serialization (needs bzr.dev from 1.16)\n')
 
1269
 
 
1270
 
 
1271
class RepositoryFormat2a(RepositoryFormatCHK2):
 
1272
    """A CHK repository that uses the bencode revision serializer.
 
1273
 
 
1274
    This is the same as RepositoryFormatCHK2 but with a public name.
 
1275
    """
 
1276
 
 
1277
    _serializer = chk_serializer.chk_bencode_serializer
 
1278
 
 
1279
    def _get_matching_bzrdir(self):
 
1280
        return bzrdir.format_registry.make_bzrdir('2a')
 
1281
 
 
1282
    def _ignore_setting_bzrdir(self, format):
 
1283
        pass
 
1284
 
 
1285
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
1286
 
 
1287
    def get_format_string(self):
1395
1288
        return ('Bazaar repository format 2a (needs bzr 1.16 or later)\n')
1396
1289
 
1397
1290
    def get_format_description(self):
1398
1291
        """See RepositoryFormat.get_format_description()."""
1399
1292
        return ("Repository format 2a - rich roots, group compression"
1400
1293
            " and chk inventories")
1401
 
 
1402
 
 
1403
 
class RepositoryFormat2aSubtree(RepositoryFormat2a):
1404
 
    """A 2a repository format that supports nested trees.
1405
 
 
1406
 
    """
1407
 
 
1408
 
    def _get_matching_bzrdir(self):
1409
 
        return controldir.format_registry.make_bzrdir('development-subtree')
1410
 
 
1411
 
    def _ignore_setting_bzrdir(self, format):
1412
 
        pass
1413
 
 
1414
 
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
1415
 
 
1416
 
    @classmethod
1417
 
    def get_format_string(cls):
1418
 
        return ('Bazaar development format 8\n')
1419
 
 
1420
 
    def get_format_description(self):
1421
 
        """See RepositoryFormat.get_format_description()."""
1422
 
        return ("Development repository format 8 - nested trees, "
1423
 
                "group compression and chk inventories")
1424
 
 
1425
 
    experimental = True
1426
 
    supports_tree_reference = True