~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

Add development2 formats using BTree indices.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    ui,
29
29
    )
30
30
from bzrlib.index import (
31
 
    GraphIndex,
32
 
    GraphIndexBuilder,
33
 
    InMemoryGraphIndex,
34
31
    CombinedGraphIndex,
35
32
    GraphIndexPrefixAdapter,
36
33
    )
55
52
    )
56
53
 
57
54
from bzrlib.decorators import needs_write_lock
 
55
from bzrlib.btree_index import (
 
56
    BTreeGraphIndex,
 
57
    BTreeBuilder,
 
58
    )
 
59
from bzrlib.index import (
 
60
    GraphIndex,
 
61
    InMemoryGraphIndex,
 
62
    )
58
63
from bzrlib.repofmt.knitrepo import KnitRepository
59
64
from bzrlib.repository import (
60
65
    CommitBuilder,
216
221
        }
217
222
 
218
223
    def __init__(self, upload_transport, index_transport, pack_transport,
219
 
        upload_suffix='', file_mode=None):
 
224
        upload_suffix='', file_mode=None, index_builder_class=None,
 
225
        index_class=None):
220
226
        """Create a NewPack instance.
221
227
 
222
228
        :param upload_transport: A writable transport for the pack to be
229
235
        :param upload_suffix: An optional suffix to be given to any temporary
230
236
            files created during the pack creation. e.g '.autopack'
231
237
        :param file_mode: An optional file mode to create the new files with.
 
238
        :param index_builder_class: Required keyword parameter - the class of
 
239
            index builder to use.
 
240
        :param index_class: Required keyword parameter - the class of index
 
241
            object to use.
232
242
        """
233
243
        # The relative locations of the packs are constrained, but all are
234
244
        # passed in because the caller has them, so as to avoid object churn.
235
245
        Pack.__init__(self,
236
246
            # Revisions: parents list, no text compression.
237
 
            InMemoryGraphIndex(reference_lists=1),
 
247
            index_builder_class(reference_lists=1),
238
248
            # Inventory: We want to map compression only, but currently the
239
249
            # knit code hasn't been updated enough to understand that, so we
240
250
            # have a regular 2-list index giving parents and compression
241
251
            # source.
242
 
            InMemoryGraphIndex(reference_lists=2),
 
252
            index_builder_class(reference_lists=2),
243
253
            # Texts: compression and per file graph, for all fileids - so two
244
254
            # reference lists and two elements in the key tuple.
245
 
            InMemoryGraphIndex(reference_lists=2, key_elements=2),
 
255
            index_builder_class(reference_lists=2, key_elements=2),
246
256
            # Signatures: Just blobs to store, no compression, no parents
247
257
            # listing.
248
 
            InMemoryGraphIndex(reference_lists=0),
 
258
            index_builder_class(reference_lists=0),
249
259
            )
 
260
        # When we make readonly indices, we need this.
 
261
        self.index_class = index_class
250
262
        # where should the new pack be opened
251
263
        self.upload_transport = upload_transport
252
264
        # where are indices written out to
393
405
 
394
406
    def _replace_index_with_readonly(self, index_type):
395
407
        setattr(self, index_type + '_index',
396
 
            GraphIndex(self.index_transport,
 
408
            self.index_class(self.index_transport,
397
409
                self.index_name(index_type, self.name),
398
410
                self.index_sizes[self.index_offset(index_type)]))
399
411
 
592
604
        return NewPack(self._pack_collection._upload_transport,
593
605
            self._pack_collection._index_transport,
594
606
            self._pack_collection._pack_transport, upload_suffix=self.suffix,
595
 
            file_mode=self._pack_collection.repo.bzrdir._get_file_mode())
 
607
            file_mode=self._pack_collection.repo.bzrdir._get_file_mode(),
 
608
            index_builder_class=self._pack_collection._index_builder_class,
 
609
            index_class=self._pack_collection._index_class)
596
610
 
597
611
    def _copy_revision_texts(self):
598
612
        """Copy revision data to the new pack."""
1105
1119
    """
1106
1120
 
1107
1121
    def __init__(self, repo, transport, index_transport, upload_transport,
1108
 
                 pack_transport):
 
1122
                 pack_transport, index_builder_class, index_class):
1109
1123
        """Create a new RepositoryPackCollection.
1110
1124
 
1111
1125
        :param transport: Addresses the repository base directory 
1114
1128
        :param upload_transport: Addresses the directory into which packs are written
1115
1129
            while they're being created.
1116
1130
        :param pack_transport: Addresses the directory of existing complete packs.
 
1131
        :param index_builder_class: The index builder class to use.
 
1132
        :param index_class: The index class to use.
1117
1133
        """
1118
1134
        self.repo = repo
1119
1135
        self.transport = transport
1120
1136
        self._index_transport = index_transport
1121
1137
        self._upload_transport = upload_transport
1122
1138
        self._pack_transport = pack_transport
 
1139
        self._index_builder_class = index_builder_class
 
1140
        self._index_class = index_class
1123
1141
        self._suffix_offsets = {'.rix': 0, '.iix': 1, '.tix': 2, '.six': 3}
1124
1142
        self.packs = []
1125
1143
        # name:Pack mapping
1360
1378
        detect updates from others during our write operation.
1361
1379
        :return: An iterator of the index contents.
1362
1380
        """
1363
 
        return GraphIndex(self.transport, 'pack-names', None
 
1381
        return self._index_class(self.transport, 'pack-names', None
1364
1382
                ).iter_all_entries()
1365
1383
 
1366
1384
    def _make_index(self, name, suffix):
1367
1385
        size_offset = self._suffix_offsets[suffix]
1368
1386
        index_name = name + suffix
1369
1387
        index_size = self._names[name][size_offset]
1370
 
        return GraphIndex(
 
1388
        return self._index_class(
1371
1389
            self._index_transport, index_name, index_size)
1372
1390
 
1373
1391
    def _max_pack_count(self, total_revisions):
1536
1554
        """
1537
1555
        self.lock_names()
1538
1556
        try:
1539
 
            builder = GraphIndexBuilder()
 
1557
            builder = self._index_builder_class()
1540
1558
            # load the disk nodes across
1541
1559
            disk_nodes = set()
1542
1560
            for index, key, value in self._iter_disk_pack_index():
1608
1626
            raise errors.NotWriteLocked(self)
1609
1627
        self._new_pack = NewPack(self._upload_transport, self._index_transport,
1610
1628
            self._pack_transport, upload_suffix='.pack',
1611
 
            file_mode=self.repo.bzrdir._get_file_mode())
 
1629
            file_mode=self.repo.bzrdir._get_file_mode(),
 
1630
            index_builder_class=self._index_builder_class,
 
1631
            index_class=self._index_class)
1612
1632
        # allow writing: queue writes to a new index
1613
1633
        self.revision_index.add_writable_index(self._new_pack.revision_index,
1614
1634
            self._new_pack)
1683
1703
        self._pack_collection = RepositoryPackCollection(self, self._transport,
1684
1704
            index_transport,
1685
1705
            self._transport.clone('upload'),
1686
 
            self._transport.clone('packs'))
 
1706
            self._transport.clone('packs'),
 
1707
            _format.index_builder_class,
 
1708
            _format.index_class)
1687
1709
        self.inventories = KnitVersionedFiles(
1688
1710
            _KnitGraphIndex(self._pack_collection.inventory_index.combined_index,
1689
1711
                add_callback=self._pack_collection.inventory_index.add_callback,
1907
1929
    _serializer = None
1908
1930
    # External references are not supported in pack repositories yet.
1909
1931
    supports_external_lookups = False
 
1932
    # What index classes to use
 
1933
    index_builder_class = None
 
1934
    index_class = None
1910
1935
 
1911
1936
    def initialize(self, a_bzrdir, shared=False):
1912
1937
        """Create a pack based repository.
1918
1943
        """
1919
1944
        mutter('creating repository in %s.', a_bzrdir.transport.base)
1920
1945
        dirs = ['indices', 'obsolete_packs', 'packs', 'upload']
1921
 
        builder = GraphIndexBuilder()
 
1946
        builder = self.index_builder_class()
1922
1947
        files = [('pack-names', builder.finish())]
1923
1948
        utf8_files = [('format', self.get_format_string())]
1924
1949
        
1956
1981
    repository_class = KnitPackRepository
1957
1982
    _commit_builder_class = PackCommitBuilder
1958
1983
    _serializer = xml5.serializer_v5
 
1984
    # What index classes to use
 
1985
    index_builder_class = InMemoryGraphIndex
 
1986
    index_class = GraphIndex
1959
1987
 
1960
1988
    def _get_matching_bzrdir(self):
1961
1989
        return bzrdir.format_registry.make_bzrdir('pack-0.92')
1992
2020
    rich_root_data = True
1993
2021
    supports_tree_reference = True
1994
2022
    _serializer = xml7.serializer_v7
 
2023
    # What index classes to use
 
2024
    index_builder_class = InMemoryGraphIndex
 
2025
    index_class = GraphIndex
1995
2026
 
1996
2027
    def _get_matching_bzrdir(self):
1997
2028
        return bzrdir.format_registry.make_bzrdir(
2033
2064
    rich_root_data = True
2034
2065
    supports_tree_reference = False
2035
2066
    _serializer = xml6.serializer_v6
 
2067
    # What index classes to use
 
2068
    index_builder_class = InMemoryGraphIndex
 
2069
    index_class = GraphIndex
2036
2070
 
2037
2071
    def _get_matching_bzrdir(self):
2038
2072
        return bzrdir.format_registry.make_bzrdir(
2071
2105
    _commit_builder_class = PackCommitBuilder
2072
2106
    _serializer = xml5.serializer_v5
2073
2107
    supports_external_lookups = True
 
2108
    # What index classes to use
 
2109
    index_builder_class = InMemoryGraphIndex
 
2110
    index_class = GraphIndex
2074
2111
 
2075
2112
    def _get_matching_bzrdir(self):
2076
2113
        return bzrdir.format_registry.make_bzrdir('development1')
2107
2144
    supports_tree_reference = False # no subtrees
2108
2145
    _serializer = xml6.serializer_v6
2109
2146
    supports_external_lookups = True
 
2147
    # What index classes to use
 
2148
    index_builder_class = InMemoryGraphIndex
 
2149
    index_class = GraphIndex
2110
2150
 
2111
2151
    def _get_matching_bzrdir(self):
2112
2152
        return bzrdir.format_registry.make_bzrdir(
2150
2190
    _serializer = xml7.serializer_v7
2151
2191
 
2152
2192
    supports_external_lookups = True
 
2193
    # What index classes to use
 
2194
    index_builder_class = InMemoryGraphIndex
 
2195
    index_class = GraphIndex
2153
2196
 
2154
2197
    def _get_matching_bzrdir(self):
2155
2198
        return bzrdir.format_registry.make_bzrdir(
2187
2230
    _commit_builder_class = PackCommitBuilder
2188
2231
    _serializer = xml5.serializer_v5
2189
2232
    supports_external_lookups = True
 
2233
    # What index classes to use
 
2234
    index_builder_class = InMemoryGraphIndex
 
2235
    index_class = GraphIndex
2190
2236
 
2191
2237
    def _get_matching_bzrdir(self):
2192
2238
        return bzrdir.format_registry.make_bzrdir('development1')
2224
2270
    supports_tree_reference = True
2225
2271
    _serializer = xml7.serializer_v7
2226
2272
    supports_external_lookups = True
 
2273
    # What index classes to use
 
2274
    index_builder_class = InMemoryGraphIndex
 
2275
    index_class = GraphIndex
2227
2276
 
2228
2277
    def _get_matching_bzrdir(self):
2229
2278
        return bzrdir.format_registry.make_bzrdir(
2251
2300
        """See RepositoryFormat.get_format_description()."""
2252
2301
        return ("Development repository format, currently the same as "
2253
2302
            "pack-0.92-subtree with external reference support.\n")
 
2303
 
 
2304
 
 
2305
class RepositoryFormatPackDevelopment2(RepositoryFormatPack):
 
2306
    """A no-subtrees development repository.
 
2307
 
 
2308
    This format should be retained until the second release after bzr 1.7.
 
2309
 
 
2310
    This is pack-1.6.1 with B+Tree indices.
 
2311
    """
 
2312
 
 
2313
    repository_class = KnitPackRepository
 
2314
    _commit_builder_class = PackCommitBuilder
 
2315
    _serializer = xml5.serializer_v5
 
2316
    supports_external_lookups = True
 
2317
    # What index classes to use
 
2318
    index_builder_class = BTreeBuilder
 
2319
    index_class = BTreeGraphIndex
 
2320
 
 
2321
    def _get_matching_bzrdir(self):
 
2322
        return bzrdir.format_registry.make_bzrdir('development2')
 
2323
 
 
2324
    def _ignore_setting_bzrdir(self, format):
 
2325
        pass
 
2326
 
 
2327
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
2328
 
 
2329
    def get_format_string(self):
 
2330
        """See RepositoryFormat.get_format_string()."""
 
2331
        return "Bazaar development format 2 (needs bzr.dev from before 1.8)\n"
 
2332
 
 
2333
    def get_format_description(self):
 
2334
        """See RepositoryFormat.get_format_description()."""
 
2335
        return ("Development repository format, currently the same as "
 
2336
            "pack-1.6.1 with B+Trees.\n")
 
2337
 
 
2338
    def check_conversion_target(self, target_format):
 
2339
        pass
 
2340
 
 
2341
 
 
2342
class RepositoryFormatPackDevelopment2Subtree(RepositoryFormatPack):
 
2343
    """A subtrees development repository.
 
2344
 
 
2345
    This format should be retained until the second release after bzr 1.7.
 
2346
 
 
2347
    pack-1.6.1-subtree with B+Tree indices.
 
2348
    """
 
2349
 
 
2350
    repository_class = KnitPackRepository
 
2351
    _commit_builder_class = PackRootCommitBuilder
 
2352
    rich_root_data = True
 
2353
    supports_tree_reference = True
 
2354
    _serializer = xml7.serializer_v7
 
2355
    supports_external_lookups = True
 
2356
    # What index classes to use
 
2357
    index_builder_class = BTreeBuilder
 
2358
    index_class = BTreeGraphIndex
 
2359
 
 
2360
    def _get_matching_bzrdir(self):
 
2361
        return bzrdir.format_registry.make_bzrdir(
 
2362
            'development2-subtree')
 
2363
 
 
2364
    def _ignore_setting_bzrdir(self, format):
 
2365
        pass
 
2366
 
 
2367
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
 
2368
 
 
2369
    def check_conversion_target(self, target_format):
 
2370
        if not target_format.rich_root_data:
 
2371
            raise errors.BadConversionTarget(
 
2372
                'Does not support rich root data.', target_format)
 
2373
        if not getattr(target_format, 'supports_tree_reference', False):
 
2374
            raise errors.BadConversionTarget(
 
2375
                'Does not support nested trees', target_format)
 
2376
            
 
2377
    def get_format_string(self):
 
2378
        """See RepositoryFormat.get_format_string()."""
 
2379
        return ("Bazaar development format 2 with subtree support "
 
2380
            "(needs bzr.dev from before 1.8)\n")
 
2381
 
 
2382
    def get_format_description(self):
 
2383
        """See RepositoryFormat.get_format_description()."""
 
2384
        return ("Development repository format, currently the same as "
 
2385
            "pack-1.6.1-subtree with B+Tree indices.\n")