~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-06 20:45:48 UTC
  • mfrom: (4728.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20091006204548-bjnc3z4k256ppimz
MutableTree.has_changes() does not require a tree parameter anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    )
37
37
from bzrlib.index import (
38
38
    CombinedGraphIndex,
39
 
    GraphIndex,
40
 
    GraphIndexBuilder,
41
39
    GraphIndexPrefixAdapter,
42
 
    InMemoryGraphIndex,
43
40
    )
44
 
from bzrlib.inventory import CHKInventory
45
41
from bzrlib.knit import (
46
42
    KnitPlainFactory,
47
43
    KnitVersionedFiles,
52
48
""")
53
49
from bzrlib import (
54
50
    bzrdir,
55
 
    chk_serializer,
56
51
    errors,
57
52
    lockable_files,
58
53
    lockdir,
59
54
    revision as _mod_revision,
60
 
    symbol_versioning,
61
55
    )
62
56
 
63
57
from bzrlib.decorators import needs_write_lock
75
69
    MetaDirRepositoryFormat,
76
70
    RepositoryFormat,
77
71
    RootCommitBuilder,
 
72
    StreamSource,
78
73
    )
79
 
import bzrlib.revision as _mod_revision
80
74
from bzrlib.trace import (
81
75
    mutter,
82
76
    warning,
270
264
 
271
265
    def __init__(self, name, revision_index, inventory_index, text_index,
272
266
        signature_index, upload_transport, pack_transport, index_transport,
273
 
        pack_collection):
 
267
        pack_collection, chk_index=None):
274
268
        """Create a ResumedPack object."""
275
269
        ExistingPack.__init__(self, pack_transport, name, revision_index,
276
 
            inventory_index, text_index, signature_index)
 
270
            inventory_index, text_index, signature_index,
 
271
            chk_index=chk_index)
277
272
        self.upload_transport = upload_transport
278
273
        self.index_transport = index_transport
279
274
        self.index_sizes = [None, None, None, None]
283
278
            ('text', text_index),
284
279
            ('signature', signature_index),
285
280
            ]
 
281
        if chk_index is not None:
 
282
            indices.append(('chk', chk_index))
 
283
            self.index_sizes.append(None)
286
284
        for index_type, index in indices:
287
285
            offset = self.index_offset(index_type)
288
286
            self.index_sizes[offset] = index._size
303
301
        self.upload_transport.delete(self.file_name())
304
302
        indices = [self.revision_index, self.inventory_index, self.text_index,
305
303
            self.signature_index]
 
304
        if self.chk_index is not None:
 
305
            indices.append(self.chk_index)
306
306
        for index in indices:
307
307
            index._transport.delete(index._name)
308
308
 
309
309
    def finish(self):
310
310
        self._check_references()
311
 
        new_name = '../packs/' + self.file_name()
312
 
        self.upload_transport.rename(self.file_name(), new_name)
313
 
        for index_type in ['revision', 'inventory', 'text', 'signature']:
 
311
        index_types = ['revision', 'inventory', 'text', 'signature']
 
312
        if self.chk_index is not None:
 
313
            index_types.append('chk')
 
314
        for index_type in index_types:
314
315
            old_name = self.index_name(index_type, self.name)
315
316
            new_name = '../indices/' + old_name
316
317
            self.upload_transport.rename(old_name, new_name)
317
318
            self._replace_index_with_readonly(index_type)
 
319
        new_name = '../packs/' + self.file_name()
 
320
        self.upload_transport.rename(self.file_name(), new_name)
318
321
        self._state = 'finished'
319
322
 
320
323
    def _get_external_refs(self, index):
 
324
        """Return compression parents for this index that are not present.
 
325
 
 
326
        This returns any compression parents that are referenced by this index,
 
327
        which are not contained *in* this index. They may be present elsewhere.
 
328
        """
321
329
        return index.external_references(1)
322
330
 
323
331
 
414
422
        self._writer.begin()
415
423
        # what state is the pack in? (open, finished, aborted)
416
424
        self._state = 'open'
 
425
        # no name until we finish writing the content
 
426
        self.name = None
417
427
 
418
428
    def abort(self):
419
429
        """Cancel creating this pack."""
440
450
            self.signature_index.key_count() or
441
451
            (self.chk_index is not None and self.chk_index.key_count()))
442
452
 
 
453
    def finish_content(self):
 
454
        if self.name is not None:
 
455
            return
 
456
        self._writer.end()
 
457
        if self._buffer[1]:
 
458
            self._write_data('', flush=True)
 
459
        self.name = self._hash.hexdigest()
 
460
 
443
461
    def finish(self, suspend=False):
444
462
        """Finish the new pack.
445
463
 
451
469
         - stores the index size tuple for the pack in the index_sizes
452
470
           attribute.
453
471
        """
454
 
        self._writer.end()
455
 
        if self._buffer[1]:
456
 
            self._write_data('', flush=True)
457
 
        self.name = self._hash.hexdigest()
 
472
        self.finish_content()
458
473
        if not suspend:
459
474
            self._check_references()
460
475
        # write indices
1294
1309
        # space (we only topo sort the revisions, which is smaller).
1295
1310
        topo_order = tsort.topo_sort(ancestors)
1296
1311
        rev_order = dict(zip(topo_order, range(len(topo_order))))
1297
 
        bad_texts.sort(key=lambda key:rev_order[key[0][1]])
 
1312
        bad_texts.sort(key=lambda key:rev_order.get(key[0][1], 0))
1298
1313
        transaction = repo.get_transaction()
1299
1314
        file_id_index = GraphIndexPrefixAdapter(
1300
1315
            self.new_pack.text_index,
1354
1369
    """
1355
1370
 
1356
1371
    pack_factory = NewPack
 
1372
    resumed_pack_factory = ResumedPack
1357
1373
 
1358
1374
    def __init__(self, repo, transport, index_transport, upload_transport,
1359
1375
                 pack_transport, index_builder_class, index_class,
1445
1461
        in synchronisation with certain steps. Otherwise the names collection
1446
1462
        is not flushed.
1447
1463
 
1448
 
        :return: True if packing took place.
 
1464
        :return: Something evaluating true if packing took place.
1449
1465
        """
1450
1466
        while True:
1451
1467
            try:
1452
1468
                return self._do_autopack()
1453
 
            except errors.RetryAutopack, e:
 
1469
            except errors.RetryAutopack:
1454
1470
                # If we get a RetryAutopack exception, we should abort the
1455
1471
                # current action, and retry.
1456
1472
                pass
1460
1476
        total_revisions = self.revision_index.combined_index.key_count()
1461
1477
        total_packs = len(self._names)
1462
1478
        if self._max_pack_count(total_revisions) >= total_packs:
1463
 
            return False
 
1479
            return None
1464
1480
        # determine which packs need changing
1465
1481
        pack_distribution = self.pack_distribution(total_revisions)
1466
1482
        existing_packs = []
1488
1504
            'containing %d revisions. Packing %d files into %d affecting %d'
1489
1505
            ' revisions', self, total_packs, total_revisions, num_old_packs,
1490
1506
            num_new_packs, num_revs_affected)
1491
 
        self._execute_pack_operations(pack_operations,
 
1507
        result = self._execute_pack_operations(pack_operations,
1492
1508
                                      reload_func=self._restart_autopack)
1493
1509
        mutter('Auto-packing repository %s completed', self)
1494
 
        return True
 
1510
        return result
1495
1511
 
1496
1512
    def _execute_pack_operations(self, pack_operations, _packer_class=Packer,
1497
1513
                                 reload_func=None):
1499
1515
 
1500
1516
        :param pack_operations: A list of [revision_count, packs_to_combine].
1501
1517
        :param _packer_class: The class of packer to use (default: Packer).
1502
 
        :return: None.
 
1518
        :return: The new pack names.
1503
1519
        """
1504
1520
        for revision_count, packs in pack_operations:
1505
1521
            # we may have no-ops from the setup logic
1521
1537
                self._remove_pack_from_memory(pack)
1522
1538
        # record the newly available packs and stop advertising the old
1523
1539
        # packs
1524
 
        self._save_pack_names(clear_obsolete_packs=True)
 
1540
        result = self._save_pack_names(clear_obsolete_packs=True)
1525
1541
        # Move the old packs out of the way now they are no longer referenced.
1526
1542
        for revision_count, packs in pack_operations:
1527
1543
            self._obsolete_packs(packs)
 
1544
        return result
1528
1545
 
1529
1546
    def _flush_new_pack(self):
1530
1547
        if self._new_pack is not None:
1540
1557
 
1541
1558
    def _already_packed(self):
1542
1559
        """Is the collection already packed?"""
1543
 
        return len(self._names) < 2
 
1560
        return not (self.repo._format.pack_compresses or (len(self._names) > 1))
1544
1561
 
1545
 
    def pack(self):
 
1562
    def pack(self, hint=None):
1546
1563
        """Pack the pack collection totally."""
1547
1564
        self.ensure_loaded()
1548
1565
        total_packs = len(self._names)
1549
1566
        if self._already_packed():
1550
 
            # This is arguably wrong because we might not be optimal, but for
1551
 
            # now lets leave it in. (e.g. reconcile -> one pack. But not
1552
 
            # optimal.
1553
1567
            return
1554
1568
        total_revisions = self.revision_index.combined_index.key_count()
1555
1569
        # XXX: the following may want to be a class, to pack with a given
1556
1570
        # policy.
1557
1571
        mutter('Packing repository %s, which has %d pack files, '
1558
 
            'containing %d revisions into 1 packs.', self, total_packs,
1559
 
            total_revisions)
 
1572
            'containing %d revisions with hint %r.', self, total_packs,
 
1573
            total_revisions, hint)
1560
1574
        # determine which packs need changing
1561
 
        pack_distribution = [1]
1562
1575
        pack_operations = [[0, []]]
1563
1576
        for pack in self.all_packs():
1564
 
            pack_operations[-1][0] += pack.get_revision_count()
1565
 
            pack_operations[-1][1].append(pack)
 
1577
            if hint is None or pack.name in hint:
 
1578
                # Either no hint was provided (so we are packing everything),
 
1579
                # or this pack was included in the hint.
 
1580
                pack_operations[-1][0] += pack.get_revision_count()
 
1581
                pack_operations[-1][1].append(pack)
1566
1582
        self._execute_pack_operations(pack_operations, OptimisingPacker)
1567
1583
 
1568
1584
    def plan_autopack_combinations(self, existing_packs, pack_distribution):
1682
1698
            inv_index = self._make_index(name, '.iix', resume=True)
1683
1699
            txt_index = self._make_index(name, '.tix', resume=True)
1684
1700
            sig_index = self._make_index(name, '.six', resume=True)
1685
 
            result = ResumedPack(name, rev_index, inv_index, txt_index,
1686
 
                sig_index, self._upload_transport, self._pack_transport,
1687
 
                self._index_transport, self)
 
1701
            if self.chk_index is not None:
 
1702
                chk_index = self._make_index(name, '.cix', resume=True)
 
1703
            else:
 
1704
                chk_index = None
 
1705
            result = self.resumed_pack_factory(name, rev_index, inv_index,
 
1706
                txt_index, sig_index, self._upload_transport,
 
1707
                self._pack_transport, self._index_transport, self,
 
1708
                chk_index=chk_index)
1688
1709
        except errors.NoSuchFile, e:
1689
1710
            raise errors.UnresumableWriteGroup(self.repo, [name], str(e))
1690
1711
        self.add_pack_to_memory(result)
1811
1832
    def reset(self):
1812
1833
        """Clear all cached data."""
1813
1834
        # cached revision data
1814
 
        self.repo._revision_knit = None
1815
1835
        self.revision_index.clear()
1816
1836
        # cached signature data
1817
 
        self.repo._signature_knit = None
1818
1837
        self.signature_index.clear()
1819
1838
        # cached file text data
1820
1839
        self.text_index.clear()
1821
 
        self.repo._text_knit = None
1822
1840
        # cached inventory data
1823
1841
        self.inventory_index.clear()
1824
1842
        # cached chk data
1922
1940
 
1923
1941
        :param clear_obsolete_packs: If True, clear out the contents of the
1924
1942
            obsolete_packs directory.
 
1943
        :return: A list of the names saved that were not previously on disk.
1925
1944
        """
1926
1945
        self.lock_names()
1927
1946
        try:
1942
1961
            self._unlock_names()
1943
1962
        # synchronise the memory packs list with what we just wrote:
1944
1963
        self._syncronize_pack_names_from_disk_nodes(disk_nodes)
 
1964
        return [new_node[0][0] for new_node in new_nodes]
1945
1965
 
1946
1966
    def reload_pack_names(self):
1947
1967
        """Sync our pack listing with what is present in the repository.
2000
2020
            self._new_pack)
2001
2021
        self.text_index.add_writable_index(self._new_pack.text_index,
2002
2022
            self._new_pack)
 
2023
        self._new_pack.text_index.set_optimize(combine_backing_indices=False)
2003
2024
        self.signature_index.add_writable_index(self._new_pack.signature_index,
2004
2025
            self._new_pack)
2005
2026
        if self.chk_index is not None:
2006
2027
            self.chk_index.add_writable_index(self._new_pack.chk_index,
2007
2028
                self._new_pack)
2008
2029
            self.repo.chk_bytes._index._add_callback = self.chk_index.add_callback
 
2030
            self._new_pack.chk_index.set_optimize(combine_backing_indices=False)
2009
2031
 
2010
2032
        self.repo.inventories._index._add_callback = self.inventory_index.add_callback
2011
2033
        self.repo.revisions._index._add_callback = self.revision_index.add_callback
2035
2057
                except KeyError:
2036
2058
                    pass
2037
2059
        del self._resumed_packs[:]
2038
 
        self.repo._text_knit = None
2039
2060
 
2040
2061
    def _remove_resumed_pack_indices(self):
2041
2062
        for resumed_pack in self._resumed_packs:
2042
2063
            self._remove_pack_indices(resumed_pack)
2043
2064
        del self._resumed_packs[:]
2044
2065
 
 
2066
    def _check_new_inventories(self):
 
2067
        """Detect missing inventories in this write group.
 
2068
 
 
2069
        :returns: list of strs, summarising any problems found.  If the list is
 
2070
            empty no problems were found.
 
2071
        """
 
2072
        # The base implementation does no checks.  GCRepositoryPackCollection
 
2073
        # overrides this.
 
2074
        return []
 
2075
        
2045
2076
    def _commit_write_group(self):
2046
2077
        all_missing = set()
2047
2078
        for prefix, versioned_file in (
2056
2087
            raise errors.BzrCheckError(
2057
2088
                "Repository %s has missing compression parent(s) %r "
2058
2089
                 % (self.repo, sorted(all_missing)))
 
2090
        problems = self._check_new_inventories()
 
2091
        if problems:
 
2092
            problems_summary = '\n'.join(problems)
 
2093
            raise errors.BzrCheckError(
 
2094
                "Cannot add revision(s) to repository: " + problems_summary)
2059
2095
        self._remove_pack_indices(self._new_pack)
2060
 
        should_autopack = False
 
2096
        any_new_content = False
2061
2097
        if self._new_pack.data_inserted():
2062
2098
            # get all the data to disk and read to use
2063
2099
            self._new_pack.finish()
2064
2100
            self.allocate(self._new_pack)
2065
2101
            self._new_pack = None
2066
 
            should_autopack = True
 
2102
            any_new_content = True
2067
2103
        else:
2068
2104
            self._new_pack.abort()
2069
2105
            self._new_pack = None
2074
2110
            self._remove_pack_from_memory(resumed_pack)
2075
2111
            resumed_pack.finish()
2076
2112
            self.allocate(resumed_pack)
2077
 
            should_autopack = True
 
2113
            any_new_content = True
2078
2114
        del self._resumed_packs[:]
2079
 
        if should_autopack:
2080
 
            if not self.autopack():
 
2115
        if any_new_content:
 
2116
            result = self.autopack()
 
2117
            if not result:
2081
2118
                # when autopack takes no steps, the names list is still
2082
2119
                # unsaved.
2083
 
                self._save_pack_names()
2084
 
        self.repo._text_knit = None
 
2120
                return self._save_pack_names()
 
2121
            return result
 
2122
        return []
2085
2123
 
2086
2124
    def _suspend_write_group(self):
2087
2125
        tokens = [pack.name for pack in self._resumed_packs]
2095
2133
            self._new_pack.abort()
2096
2134
            self._new_pack = None
2097
2135
        self._remove_resumed_pack_indices()
2098
 
        self.repo._text_knit = None
2099
2136
        return tokens
2100
2137
 
2101
2138
    def _resume_write_group(self, tokens):
2150
2187
        self.revisions = KnitVersionedFiles(
2151
2188
            _KnitGraphIndex(self._pack_collection.revision_index.combined_index,
2152
2189
                add_callback=self._pack_collection.revision_index.add_callback,
2153
 
                deltas=False, parents=True, is_locked=self.is_locked),
 
2190
                deltas=False, parents=True, is_locked=self.is_locked,
 
2191
                track_external_parent_refs=True),
2154
2192
            data_access=self._pack_collection.revision_index.data_access,
2155
2193
            max_delta_chain=0)
2156
2194
        self.signatures = KnitVersionedFiles(
2201
2239
                    % (self._format, self.bzrdir.transport.base))
2202
2240
 
2203
2241
    def _abort_write_group(self):
 
2242
        self.revisions._index._key_dependencies.clear()
2204
2243
        self._pack_collection._abort_write_group()
2205
2244
 
2206
 
    def _find_inconsistent_revision_parents(self):
2207
 
        """Find revisions with incorrectly cached parents.
2208
 
 
2209
 
        :returns: an iterator yielding tuples of (revison-id, parents-in-index,
2210
 
            parents-in-revision).
2211
 
        """
2212
 
        if not self.is_locked():
2213
 
            raise errors.ObjectNotLocked(self)
2214
 
        pb = ui.ui_factory.nested_progress_bar()
2215
 
        result = []
2216
 
        try:
2217
 
            revision_nodes = self._pack_collection.revision_index \
2218
 
                .combined_index.iter_all_entries()
2219
 
            index_positions = []
2220
 
            # Get the cached index values for all revisions, and also the
2221
 
            # location in each index of the revision text so we can perform
2222
 
            # linear IO.
2223
 
            for index, key, value, refs in revision_nodes:
2224
 
                node = (index, key, value, refs)
2225
 
                index_memo = self.revisions._index._node_to_position(node)
2226
 
                assert index_memo[0] == index
2227
 
                index_positions.append((index_memo, key[0],
2228
 
                                       tuple(parent[0] for parent in refs[0])))
2229
 
                pb.update("Reading revision index", 0, 0)
2230
 
            index_positions.sort()
2231
 
            batch_size = 1000
2232
 
            pb.update("Checking cached revision graph", 0,
2233
 
                      len(index_positions))
2234
 
            for offset in xrange(0, len(index_positions), 1000):
2235
 
                pb.update("Checking cached revision graph", offset)
2236
 
                to_query = index_positions[offset:offset + batch_size]
2237
 
                if not to_query:
2238
 
                    break
2239
 
                rev_ids = [item[1] for item in to_query]
2240
 
                revs = self.get_revisions(rev_ids)
2241
 
                for revision, item in zip(revs, to_query):
2242
 
                    index_parents = item[2]
2243
 
                    rev_parents = tuple(revision.parent_ids)
2244
 
                    if index_parents != rev_parents:
2245
 
                        result.append((revision.revision_id, index_parents,
2246
 
                                       rev_parents))
2247
 
        finally:
2248
 
            pb.finished()
2249
 
        return result
 
2245
    def _get_source(self, to_format):
 
2246
        if to_format.network_name() == self._format.network_name():
 
2247
            return KnitPackStreamSource(self, to_format)
 
2248
        return super(KnitPackRepository, self)._get_source(to_format)
2250
2249
 
2251
2250
    def _make_parents_provider(self):
2252
2251
        return graph.CachingParentsProvider(self)
2260
2259
        self._pack_collection._start_write_group()
2261
2260
 
2262
2261
    def _commit_write_group(self):
2263
 
        return self._pack_collection._commit_write_group()
 
2262
        hint = self._pack_collection._commit_write_group()
 
2263
        self.revisions._index._key_dependencies.clear()
 
2264
        return hint
2264
2265
 
2265
2266
    def suspend_write_group(self):
2266
2267
        # XXX check self._write_group is self.get_transaction()?
2267
2268
        tokens = self._pack_collection._suspend_write_group()
 
2269
        self.revisions._index._key_dependencies.clear()
2268
2270
        self._write_group = None
2269
2271
        return tokens
2270
2272
 
2271
2273
    def _resume_write_group(self, tokens):
2272
2274
        self._start_write_group()
2273
 
        self._pack_collection._resume_write_group(tokens)
 
2275
        try:
 
2276
            self._pack_collection._resume_write_group(tokens)
 
2277
        except errors.UnresumableWriteGroup:
 
2278
            self._abort_write_group()
 
2279
            raise
 
2280
        for pack in self._pack_collection._resumed_packs:
 
2281
            self.revisions._index.scan_unvalidated_index(pack.revision_index)
2274
2282
 
2275
2283
    def get_transaction(self):
2276
2284
        if self._write_lock_count:
2291
2299
        self._write_lock_count += 1
2292
2300
        if self._write_lock_count == 1:
2293
2301
            self._transaction = transactions.WriteTransaction()
 
2302
        if not locked:
2294
2303
            for repo in self._fallback_repositories:
2295
2304
                # Writes don't affect fallback repos
2296
2305
                repo.lock_read()
2297
 
        if not locked:
2298
2306
            self._refresh_data()
2299
2307
 
2300
2308
    def lock_read(self):
2303
2311
            self._write_lock_count += 1
2304
2312
        else:
2305
2313
            self.control_files.lock_read()
 
2314
        if not locked:
2306
2315
            for repo in self._fallback_repositories:
2307
 
                # Writes don't affect fallback repos
2308
2316
                repo.lock_read()
2309
 
        if not locked:
2310
2317
            self._refresh_data()
2311
2318
 
2312
2319
    def leave_lock_in_place(self):
2318
2325
        raise NotImplementedError(self.dont_leave_lock_in_place)
2319
2326
 
2320
2327
    @needs_write_lock
2321
 
    def pack(self):
 
2328
    def pack(self, hint=None):
2322
2329
        """Compress the data within the repository.
2323
2330
 
2324
2331
        This will pack all the data to a single pack. In future it may
2325
2332
        recompress deltas or do other such expensive operations.
2326
2333
        """
2327
 
        self._pack_collection.pack()
 
2334
        self._pack_collection.pack(hint=hint)
2328
2335
 
2329
2336
    @needs_write_lock
2330
2337
    def reconcile(self, other=None, thorough=False):
2352
2359
                transaction = self._transaction
2353
2360
                self._transaction = None
2354
2361
                transaction.finish()
2355
 
                for repo in self._fallback_repositories:
2356
 
                    repo.unlock()
2357
2362
        else:
2358
2363
            self.control_files.unlock()
 
2364
 
 
2365
        if not self.is_locked():
2359
2366
            for repo in self._fallback_repositories:
2360
2367
                repo.unlock()
2361
2368
 
2362
2369
 
2363
 
class CHKInventoryRepository(KnitPackRepository):
2364
 
    """subclass of KnitPackRepository that uses CHK based inventories."""
2365
 
 
2366
 
    def _add_inventory_checked(self, revision_id, inv, parents):
2367
 
        """Add inv to the repository after checking the inputs.
2368
 
 
2369
 
        This function can be overridden to allow different inventory styles.
2370
 
 
2371
 
        :seealso: add_inventory, for the contract.
2372
 
        """
2373
 
        # make inventory
2374
 
        serializer = self._format._serializer
2375
 
        result = CHKInventory.from_inventory(self.chk_bytes, inv,
2376
 
            maximum_size=serializer.maximum_size,
2377
 
            search_key_name=serializer.search_key_name)
2378
 
        inv_lines = result.to_lines()
2379
 
        return self._inventory_add_lines(revision_id, parents,
2380
 
            inv_lines, check_content=False)
2381
 
 
2382
 
    def add_inventory_by_delta(self, basis_revision_id, delta, new_revision_id,
2383
 
                               parents, basis_inv=None, propagate_caches=False):
2384
 
        """Add a new inventory expressed as a delta against another revision.
2385
 
 
2386
 
        :param basis_revision_id: The inventory id the delta was created
2387
 
            against.
2388
 
        :param delta: The inventory delta (see Inventory.apply_delta for
2389
 
            details).
2390
 
        :param new_revision_id: The revision id that the inventory is being
2391
 
            added for.
2392
 
        :param parents: The revision ids of the parents that revision_id is
2393
 
            known to have and are in the repository already. These are supplied
2394
 
            for repositories that depend on the inventory graph for revision
2395
 
            graph access, as well as for those that pun ancestry with delta
2396
 
            compression.
2397
 
        :param basis_inv: The basis inventory if it is already known,
2398
 
            otherwise None.
2399
 
        :param propagate_caches: If True, the caches for this inventory are
2400
 
          copied to and updated for the result if possible.
2401
 
 
2402
 
        :returns: (validator, new_inv)
2403
 
            The validator(which is a sha1 digest, though what is sha'd is
2404
 
            repository format specific) of the serialized inventory, and the
2405
 
            resulting inventory.
2406
 
        """
2407
 
        if basis_revision_id == _mod_revision.NULL_REVISION:
2408
 
            return KnitPackRepository.add_inventory_by_delta(self,
2409
 
                basis_revision_id, delta, new_revision_id, parents)
2410
 
        if not self.is_in_write_group():
2411
 
            raise AssertionError("%r not in write group" % (self,))
2412
 
        _mod_revision.check_not_reserved_id(new_revision_id)
2413
 
        basis_tree = self.revision_tree(basis_revision_id)
2414
 
        basis_tree.lock_read()
2415
 
        try:
2416
 
            if basis_inv is None:
2417
 
                basis_inv = basis_tree.inventory
2418
 
            result = basis_inv.create_by_apply_delta(delta, new_revision_id,
2419
 
                propagate_caches=propagate_caches)
2420
 
            inv_lines = result.to_lines()
2421
 
            return self._inventory_add_lines(new_revision_id, parents,
2422
 
                inv_lines, check_content=False), result
2423
 
        finally:
2424
 
            basis_tree.unlock()
2425
 
 
2426
 
    def _iter_inventories(self, revision_ids):
2427
 
        """Iterate over many inventory objects."""
2428
 
        keys = [(revision_id,) for revision_id in revision_ids]
2429
 
        stream = self.inventories.get_record_stream(keys, 'unordered', True)
2430
 
        texts = {}
2431
 
        for record in stream:
2432
 
            if record.storage_kind != 'absent':
2433
 
                texts[record.key] = record.get_bytes_as('fulltext')
2434
 
            else:
2435
 
                raise errors.NoSuchRevision(self, record.key)
2436
 
        for key in keys:
2437
 
            yield CHKInventory.deserialise(self.chk_bytes, texts[key], key)
2438
 
 
2439
 
    def _iter_inventory_xmls(self, revision_ids):
2440
 
        # Without a native 'xml' inventory, this method doesn't make sense, so
2441
 
        # make it raise to trap naughty direct users.
2442
 
        raise NotImplementedError(self._iter_inventory_xmls)
2443
 
 
2444
 
    def _find_revision_outside_set(self, revision_ids):
2445
 
        revision_set = frozenset(revision_ids)
2446
 
        for revid in revision_ids:
2447
 
            parent_ids = self.get_parent_map([revid]).get(revid, ())
2448
 
            for parent in parent_ids:
2449
 
                if parent in revision_set:
2450
 
                    # Parent is not outside the set
2451
 
                    continue
2452
 
                if parent not in self.get_parent_map([parent]):
2453
 
                    # Parent is a ghost
2454
 
                    continue
2455
 
                return parent
2456
 
        return _mod_revision.NULL_REVISION
2457
 
 
2458
 
    def _find_file_keys_to_fetch(self, revision_ids, pb):
2459
 
        rich_root = self.supports_rich_root()
2460
 
        revision_outside_set = self._find_revision_outside_set(revision_ids)
2461
 
        if revision_outside_set == _mod_revision.NULL_REVISION:
2462
 
            uninteresting_root_keys = set()
2463
 
        else:
2464
 
            uninteresting_inv = self.get_inventory(revision_outside_set)
2465
 
            uninteresting_root_keys = set([uninteresting_inv.id_to_entry.key()])
2466
 
        interesting_root_keys = set()
2467
 
        for idx, inv in enumerate(self.iter_inventories(revision_ids)):
2468
 
            interesting_root_keys.add(inv.id_to_entry.key())
2469
 
        revision_ids = frozenset(revision_ids)
2470
 
        file_id_revisions = {}
2471
 
        bytes_to_info = CHKInventory._bytes_to_utf8name_key
2472
 
        for records, items in chk_map.iter_interesting_nodes(self.chk_bytes,
2473
 
                    interesting_root_keys, uninteresting_root_keys,
2474
 
                    pb=pb):
2475
 
            # This is cheating a bit to use the last grabbed 'inv', but it
2476
 
            # works
2477
 
            for name, bytes in items:
2478
 
                (name_utf8, file_id, revision_id) = bytes_to_info(bytes)
2479
 
                if not rich_root and name_utf8 == '':
2480
 
                    continue
2481
 
                if revision_id in revision_ids:
2482
 
                    # Would we rather build this up into file_id => revision
2483
 
                    # maps?
2484
 
                    try:
2485
 
                        file_id_revisions[file_id].add(revision_id)
2486
 
                    except KeyError:
2487
 
                        file_id_revisions[file_id] = set([revision_id])
2488
 
        for file_id, revisions in file_id_revisions.iteritems():
2489
 
            yield ('file', file_id, revisions)
2490
 
 
2491
 
    def fileids_altered_by_revision_ids(self, revision_ids, _inv_weave=None):
2492
 
        """Find the file ids and versions affected by revisions.
2493
 
 
2494
 
        :param revisions: an iterable containing revision ids.
2495
 
        :param _inv_weave: The inventory weave from this repository or None.
2496
 
            If None, the inventory weave will be opened automatically.
2497
 
        :return: a dictionary mapping altered file-ids to an iterable of
2498
 
            revision_ids. Each altered file-ids has the exact revision_ids that
2499
 
            altered it listed explicitly.
2500
 
        """
2501
 
        rich_roots = self.supports_rich_root()
2502
 
        result = {}
2503
 
        pb = ui.ui_factory.nested_progress_bar()
2504
 
        try:
2505
 
            total = len(revision_ids)
2506
 
            for pos, inv in enumerate(self.iter_inventories(revision_ids)):
2507
 
                pb.update("Finding text references", pos, total)
2508
 
                for entry in inv.iter_just_entries():
2509
 
                    if entry.revision != inv.revision_id:
2510
 
                        continue
2511
 
                    if not rich_roots and entry.file_id == inv.root_id:
2512
 
                        continue
2513
 
                    alterations = result.setdefault(entry.file_id, set([]))
2514
 
                    alterations.add(entry.revision)
2515
 
            return result
2516
 
        finally:
2517
 
            pb.finished()
2518
 
 
2519
 
    def find_text_key_references(self):
2520
 
        """Find the text key references within the repository.
2521
 
 
2522
 
        :return: A dictionary mapping text keys ((fileid, revision_id) tuples)
2523
 
            to whether they were referred to by the inventory of the
2524
 
            revision_id that they contain. The inventory texts from all present
2525
 
            revision ids are assessed to generate this report.
2526
 
        """
2527
 
        # XXX: Slow version but correct: rewrite as a series of delta
2528
 
        # examinations/direct tree traversal. Note that that will require care
2529
 
        # as a common node is reachable both from the inventory that added it,
2530
 
        # and others afterwards.
2531
 
        revision_keys = self.revisions.keys()
2532
 
        result = {}
2533
 
        rich_roots = self.supports_rich_root()
2534
 
        pb = ui.ui_factory.nested_progress_bar()
2535
 
        try:
2536
 
            all_revs = self.all_revision_ids()
2537
 
            total = len(all_revs)
2538
 
            for pos, inv in enumerate(self.iter_inventories(all_revs)):
2539
 
                pb.update("Finding text references", pos, total)
2540
 
                for _, entry in inv.iter_entries():
2541
 
                    if not rich_roots and entry.file_id == inv.root_id:
2542
 
                        continue
2543
 
                    key = (entry.file_id, entry.revision)
2544
 
                    result.setdefault(key, False)
2545
 
                    if entry.revision == inv.revision_id:
2546
 
                        result[key] = True
2547
 
            return result
2548
 
        finally:
2549
 
            pb.finished()
2550
 
 
2551
 
    def _reconcile_pack(self, collection, packs, extension, revs, pb):
2552
 
        packer = CHKReconcilePacker(collection, packs, extension, revs)
2553
 
        return packer.pack(pb)
2554
 
 
2555
 
 
2556
 
class CHKReconcilePacker(ReconcilePacker):
2557
 
    """Subclass of ReconcilePacker for handling chk inventories."""
2558
 
 
2559
 
    def _process_inventory_lines(self, inv_lines):
2560
 
        """Generate a text key reference map rather for reconciling with."""
2561
 
        repo = self._pack_collection.repo
2562
 
        # XXX: This double-reads the inventories; but it works.
2563
 
        refs = repo.find_text_key_references()
2564
 
        self._text_refs = refs
2565
 
        # during reconcile we:
2566
 
        #  - convert unreferenced texts to full texts
2567
 
        #  - correct texts which reference a text not copied to be full texts
2568
 
        #  - copy all others as-is but with corrected parents.
2569
 
        #  - so at this point we don't know enough to decide what becomes a full
2570
 
        #    text.
2571
 
        self._text_filter = None
2572
 
        # Copy the selected inventory roots, extracting the CHK references
2573
 
        # needed.
2574
 
        pending_refs = set()
2575
 
        for line, revid in inv_lines:
2576
 
            if line.startswith('id_to_entry: '):
2577
 
                pending_refs.add((line[13:],))
2578
 
        while pending_refs:
2579
 
            pending_refs = self._copy_chks(pending_refs)
 
2370
class KnitPackStreamSource(StreamSource):
 
2371
    """A StreamSource used to transfer data between same-format KnitPack repos.
 
2372
 
 
2373
    This source assumes:
 
2374
        1) Same serialization format for all objects
 
2375
        2) Same root information
 
2376
        3) XML format inventories
 
2377
        4) Atomic inserts (so we can stream inventory texts before text
 
2378
           content)
 
2379
        5) No chk_bytes
 
2380
    """
 
2381
 
 
2382
    def __init__(self, from_repository, to_format):
 
2383
        super(KnitPackStreamSource, self).__init__(from_repository, to_format)
 
2384
        self._text_keys = None
 
2385
        self._text_fetch_order = 'unordered'
 
2386
 
 
2387
    def _get_filtered_inv_stream(self, revision_ids):
 
2388
        from_repo = self.from_repository
 
2389
        parent_ids = from_repo._find_parent_ids_of_revisions(revision_ids)
 
2390
        parent_keys = [(p,) for p in parent_ids]
 
2391
        find_text_keys = from_repo._find_text_key_references_from_xml_inventory_lines
 
2392
        parent_text_keys = set(find_text_keys(
 
2393
            from_repo._inventory_xml_lines_for_keys(parent_keys)))
 
2394
        content_text_keys = set()
 
2395
        knit = KnitVersionedFiles(None, None)
 
2396
        factory = KnitPlainFactory()
 
2397
        def find_text_keys_from_content(record):
 
2398
            if record.storage_kind not in ('knit-delta-gz', 'knit-ft-gz'):
 
2399
                raise ValueError("Unknown content storage kind for"
 
2400
                    " inventory text: %s" % (record.storage_kind,))
 
2401
            # It's a knit record, it has a _raw_record field (even if it was
 
2402
            # reconstituted from a network stream).
 
2403
            raw_data = record._raw_record
 
2404
            # read the entire thing
 
2405
            revision_id = record.key[-1]
 
2406
            content, _ = knit._parse_record(revision_id, raw_data)
 
2407
            if record.storage_kind == 'knit-delta-gz':
 
2408
                line_iterator = factory.get_linedelta_content(content)
 
2409
            elif record.storage_kind == 'knit-ft-gz':
 
2410
                line_iterator = factory.get_fulltext_content(content)
 
2411
            content_text_keys.update(find_text_keys(
 
2412
                [(line, revision_id) for line in line_iterator]))
 
2413
        revision_keys = [(r,) for r in revision_ids]
 
2414
        def _filtered_inv_stream():
 
2415
            source_vf = from_repo.inventories
 
2416
            stream = source_vf.get_record_stream(revision_keys,
 
2417
                                                 'unordered', False)
 
2418
            for record in stream:
 
2419
                if record.storage_kind == 'absent':
 
2420
                    raise errors.NoSuchRevision(from_repo, record.key)
 
2421
                find_text_keys_from_content(record)
 
2422
                yield record
 
2423
            self._text_keys = content_text_keys - parent_text_keys
 
2424
        return ('inventories', _filtered_inv_stream())
 
2425
 
 
2426
    def _get_text_stream(self):
 
2427
        # Note: We know we don't have to handle adding root keys, because both
 
2428
        # the source and target are the identical network name.
 
2429
        text_stream = self.from_repository.texts.get_record_stream(
 
2430
                        self._text_keys, self._text_fetch_order, False)
 
2431
        return ('texts', text_stream)
 
2432
 
 
2433
    def get_stream(self, search):
 
2434
        revision_ids = search.get_keys()
 
2435
        for stream_info in self._fetch_revision_texts(revision_ids):
 
2436
            yield stream_info
 
2437
        self._revision_keys = [(rev_id,) for rev_id in revision_ids]
 
2438
        yield self._get_filtered_inv_stream(revision_ids)
 
2439
        yield self._get_text_stream()
 
2440
 
2580
2441
 
2581
2442
 
2582
2443
class RepositoryFormatPack(MetaDirRepositoryFormat):
2686
2547
        """See RepositoryFormat.get_format_description()."""
2687
2548
        return "Packs containing knits without subtree support"
2688
2549
 
2689
 
    def check_conversion_target(self, target_format):
2690
 
        pass
2691
 
 
2692
2550
 
2693
2551
class RepositoryFormatKnitPack3(RepositoryFormatPack):
2694
2552
    """A subtrees parameterized Pack repository.
2720
2578
 
2721
2579
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
2722
2580
 
2723
 
    def check_conversion_target(self, target_format):
2724
 
        if not target_format.rich_root_data:
2725
 
            raise errors.BadConversionTarget(
2726
 
                'Does not support rich root data.', target_format)
2727
 
        if not getattr(target_format, 'supports_tree_reference', False):
2728
 
            raise errors.BadConversionTarget(
2729
 
                'Does not support nested trees', target_format)
2730
 
 
2731
2581
    def get_format_string(self):
2732
2582
        """See RepositoryFormat.get_format_string()."""
2733
2583
        return "Bazaar pack repository format 1 with subtree support (needs bzr 0.92)\n"
2766
2616
 
2767
2617
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
2768
2618
 
2769
 
    def check_conversion_target(self, target_format):
2770
 
        if not target_format.rich_root_data:
2771
 
            raise errors.BadConversionTarget(
2772
 
                'Does not support rich root data.', target_format)
2773
 
 
2774
2619
    def get_format_string(self):
2775
2620
        """See RepositoryFormat.get_format_string()."""
2776
2621
        return ("Bazaar pack repository format 1 with rich root"
2817
2662
        """See RepositoryFormat.get_format_description()."""
2818
2663
        return "Packs 5 (adds stacking support, requires bzr 1.6)"
2819
2664
 
2820
 
    def check_conversion_target(self, target_format):
2821
 
        pass
2822
 
 
2823
2665
 
2824
2666
class RepositoryFormatKnitPack5RichRoot(RepositoryFormatPack):
2825
2667
    """A repository with rich roots and stacking.
2852
2694
 
2853
2695
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
2854
2696
 
2855
 
    def check_conversion_target(self, target_format):
2856
 
        if not target_format.rich_root_data:
2857
 
            raise errors.BadConversionTarget(
2858
 
                'Does not support rich root data.', target_format)
2859
 
 
2860
2697
    def get_format_string(self):
2861
2698
        """See RepositoryFormat.get_format_string()."""
2862
2699
        return "Bazaar RepositoryFormatKnitPack5RichRoot (bzr 1.6.1)\n"
2903
2740
 
2904
2741
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
2905
2742
 
2906
 
    def check_conversion_target(self, target_format):
2907
 
        if not target_format.rich_root_data:
2908
 
            raise errors.BadConversionTarget(
2909
 
                'Does not support rich root data.', target_format)
2910
 
 
2911
2743
    def get_format_string(self):
2912
2744
        """See RepositoryFormat.get_format_string()."""
2913
2745
        return "Bazaar RepositoryFormatKnitPack5RichRoot (bzr 1.6)\n"
2951
2783
        """See RepositoryFormat.get_format_description()."""
2952
2784
        return "Packs 6 (uses btree indexes, requires bzr 1.9)"
2953
2785
 
2954
 
    def check_conversion_target(self, target_format):
2955
 
        pass
2956
 
 
2957
2786
 
2958
2787
class RepositoryFormatKnitPack6RichRoot(RepositoryFormatPack):
2959
2788
    """A repository with rich roots, no subtrees, stacking and btree indexes.
2983
2812
 
2984
2813
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
2985
2814
 
2986
 
    def check_conversion_target(self, target_format):
2987
 
        if not target_format.rich_root_data:
2988
 
            raise errors.BadConversionTarget(
2989
 
                'Does not support rich root data.', target_format)
2990
 
 
2991
2815
    def get_format_string(self):
2992
2816
        """See RepositoryFormat.get_format_string()."""
2993
2817
        return "Bazaar RepositoryFormatKnitPack6RichRoot (bzr 1.9)\n"
2996
2820
        return "Packs 6 rich-root (uses btree indexes, requires bzr 1.9)"
2997
2821
 
2998
2822
 
2999
 
class RepositoryFormatPackDevelopment2(RepositoryFormatPack):
3000
 
    """A no-subtrees development repository.
3001
 
 
3002
 
    This format should be retained until the second release after bzr 1.7.
3003
 
 
3004
 
    This is pack-1.6.1 with B+Tree indices.
3005
 
    """
3006
 
 
3007
 
    repository_class = KnitPackRepository
3008
 
    _commit_builder_class = PackCommitBuilder
3009
 
    supports_external_lookups = True
3010
 
    # What index classes to use
3011
 
    index_builder_class = BTreeBuilder
3012
 
    index_class = BTreeGraphIndex
3013
 
    # Set to true to get the fast-commit code path tested until a really fast
3014
 
    # format lands in trunk. Not actually fast in this format.
3015
 
    fast_deltas = True
3016
 
 
3017
 
    @property
3018
 
    def _serializer(self):
3019
 
        return xml5.serializer_v5
3020
 
 
3021
 
    def _get_matching_bzrdir(self):
3022
 
        return bzrdir.format_registry.make_bzrdir('development2')
3023
 
 
3024
 
    def _ignore_setting_bzrdir(self, format):
3025
 
        pass
3026
 
 
3027
 
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
3028
 
 
3029
 
    def get_format_string(self):
3030
 
        """See RepositoryFormat.get_format_string()."""
3031
 
        return "Bazaar development format 2 (needs bzr.dev from before 1.8)\n"
3032
 
 
3033
 
    def get_format_description(self):
3034
 
        """See RepositoryFormat.get_format_description()."""
3035
 
        return ("Development repository format, currently the same as "
3036
 
            "1.6.1 with B+Trees.\n")
3037
 
 
3038
 
    def check_conversion_target(self, target_format):
3039
 
        pass
3040
 
 
3041
 
 
3042
2823
class RepositoryFormatPackDevelopment2Subtree(RepositoryFormatPack):
3043
2824
    """A subtrees development repository.
3044
2825
 
3045
2826
    This format should be retained until the second release after bzr 1.7.
3046
2827
 
3047
2828
    1.6.1-subtree[as it might have been] with B+Tree indices.
 
2829
 
 
2830
    This is [now] retained until we have a CHK based subtree format in
 
2831
    development.
3048
2832
    """
3049
2833
 
3050
2834
    repository_class = KnitPackRepository
3062
2846
 
3063
2847
    def _get_matching_bzrdir(self):
3064
2848
        return bzrdir.format_registry.make_bzrdir(
3065
 
            'development2-subtree')
 
2849
            'development-subtree')
3066
2850
 
3067
2851
    def _ignore_setting_bzrdir(self, format):
3068
2852
        pass
3069
2853
 
3070
2854
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
3071
2855
 
3072
 
    def check_conversion_target(self, target_format):
3073
 
        if not target_format.rich_root_data:
3074
 
            raise errors.BadConversionTarget(
3075
 
                'Does not support rich root data.', target_format)
3076
 
        if not getattr(target_format, 'supports_tree_reference', False):
3077
 
            raise errors.BadConversionTarget(
3078
 
                'Does not support nested trees', target_format)
3079
 
 
3080
2856
    def get_format_string(self):
3081
2857
        """See RepositoryFormat.get_format_string()."""
3082
2858
        return ("Bazaar development format 2 with subtree support "
3087
2863
        return ("Development repository format, currently the same as "
3088
2864
            "1.6.1-subtree with B+Tree indices.\n")
3089
2865
 
3090
 
 
3091
 
class RepositoryFormatPackDevelopment5(RepositoryFormatPack):
3092
 
    """A no-subtrees development repository.
3093
 
 
3094
 
    This format should be retained until the second release after bzr 1.13.
3095
 
 
3096
 
    This is pack-1.9 with CHKMap based inventories.
3097
 
    """
3098
 
 
3099
 
    repository_class = CHKInventoryRepository
3100
 
    _commit_builder_class = PackCommitBuilder
3101
 
    _serializer = chk_serializer.chk_serializer_parent_id
3102
 
    supports_external_lookups = True
3103
 
    # What index classes to use
3104
 
    index_builder_class = BTreeBuilder
3105
 
    index_class = BTreeGraphIndex
3106
 
    supports_chks = True
3107
 
    _commit_inv_deltas = True
3108
 
 
3109
 
    def _get_matching_bzrdir(self):
3110
 
        return bzrdir.format_registry.make_bzrdir('development5')
3111
 
 
3112
 
    def _ignore_setting_bzrdir(self, format):
3113
 
        pass
3114
 
 
3115
 
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
3116
 
 
3117
 
    def get_format_string(self):
3118
 
        """See RepositoryFormat.get_format_string()."""
3119
 
        # This will need to be updated (at least replacing 1.13 with the target
3120
 
        # bzr release) once we merge brisbane-core into bzr.dev, I've used
3121
 
        # 'merge-bbc-dev4-to-bzr.dev' into comments at relevant places to make
3122
 
        # them easily greppable.  -- vila 2009016
3123
 
        return "Bazaar development format 5 (needs bzr.dev from before 1.13)\n"
3124
 
 
3125
 
    def get_format_description(self):
3126
 
        """See RepositoryFormat.get_format_description()."""
3127
 
        return ("Development repository format, currently the same as"
3128
 
                " 1.9 with B+Trees and chk support.\n")
3129
 
 
3130
 
    def check_conversion_target(self, target_format):
3131
 
        pass
3132
 
 
3133
 
 
3134
 
class RepositoryFormatPackDevelopment5Subtree(RepositoryFormatPack):
3135
 
    # merge-bbc-dev4-to-bzr.dev
3136
 
    """A subtrees development repository.
3137
 
 
3138
 
    This format should be retained until the second release after bzr 1.13.
3139
 
 
3140
 
    1.9-subtree[as it might have been] with CHKMap based inventories.
3141
 
    """
3142
 
 
3143
 
    repository_class = CHKInventoryRepository
3144
 
    _commit_builder_class = PackRootCommitBuilder
3145
 
    rich_root_data = True
3146
 
    supports_tree_reference = True
3147
 
    _serializer = chk_serializer.chk_serializer_subtree_parent_id
3148
 
    supports_external_lookups = True
3149
 
    # What index classes to use
3150
 
    index_builder_class = BTreeBuilder
3151
 
    index_class = BTreeGraphIndex
3152
 
    supports_chks = True
3153
 
    _commit_inv_deltas = True
3154
 
 
3155
 
    def _get_matching_bzrdir(self):
3156
 
        return bzrdir.format_registry.make_bzrdir(
3157
 
            'development5-subtree')
3158
 
 
3159
 
    def _ignore_setting_bzrdir(self, format):
3160
 
        pass
3161
 
 
3162
 
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
3163
 
 
3164
 
    def check_conversion_target(self, target_format):
3165
 
        if not target_format.rich_root_data:
3166
 
            raise errors.BadConversionTarget(
3167
 
                'Does not support rich root data.', target_format)
3168
 
        if not getattr(target_format, 'supports_tree_reference', False):
3169
 
            raise errors.BadConversionTarget(
3170
 
                'Does not support nested trees', target_format)
3171
 
 
3172
 
    def get_format_string(self):
3173
 
        """See RepositoryFormat.get_format_string()."""
3174
 
        # merge-bbc-dev4-to-bzr.dev
3175
 
        return ("Bazaar development format 5 with subtree support"
3176
 
                " (needs bzr.dev from before 1.13)\n")
3177
 
 
3178
 
    def get_format_description(self):
3179
 
        """See RepositoryFormat.get_format_description()."""
3180
 
        return ("Development repository format, currently the same as"
3181
 
                " 1.9-subtree with B+Tree and chk support.\n")
3182
 
 
3183
 
 
3184
 
class RepositoryFormatPackDevelopment5Hash16(RepositoryFormatPack):
3185
 
    """A no-subtrees development repository.
3186
 
 
3187
 
    This format should be retained until the second release after bzr 1.13.
3188
 
 
3189
 
    This is pack-1.9 with CHKMap based inventories with 16-way hash tries.
3190
 
    """
3191
 
 
3192
 
    repository_class = CHKInventoryRepository
3193
 
    _commit_builder_class = PackCommitBuilder
3194
 
    _serializer = chk_serializer.chk_serializer_16_parent_id
3195
 
    supports_external_lookups = True
3196
 
    # What index classes to use
3197
 
    index_builder_class = BTreeBuilder
3198
 
    index_class = BTreeGraphIndex
3199
 
    supports_chks = True
3200
 
    _commit_inv_deltas = True
3201
 
 
3202
 
    def _get_matching_bzrdir(self):
3203
 
        return bzrdir.format_registry.make_bzrdir('development5-hash16')
3204
 
 
3205
 
    def _ignore_setting_bzrdir(self, format):
3206
 
        pass
3207
 
 
3208
 
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
3209
 
 
3210
 
    def get_format_string(self):
3211
 
        """See RepositoryFormat.get_format_string()."""
3212
 
        return ("Bazaar development format 5 hash 16"
3213
 
                " (needs bzr.dev from before 1.13)\n")
3214
 
 
3215
 
    def get_format_description(self):
3216
 
        """See RepositoryFormat.get_format_description()."""
3217
 
        return ("Development repository format, currently the same as"
3218
 
                " 1.9 with B+Trees and chk support and 16-way hash tries\n")
3219
 
 
3220
 
    def check_conversion_target(self, target_format):
3221
 
        pass
3222
 
 
3223
 
 
3224
 
class RepositoryFormatPackDevelopment5Hash255(RepositoryFormatPack):
3225
 
    """A no-subtrees development repository.
3226
 
 
3227
 
    This format should be retained until the second release after bzr 1.13.
3228
 
 
3229
 
    This is pack-1.9 with CHKMap based inventories with 255-way hash tries.
3230
 
    """
3231
 
 
3232
 
    repository_class = CHKInventoryRepository
3233
 
    _commit_builder_class = PackCommitBuilder
3234
 
    _serializer = chk_serializer.chk_serializer_255_parent_id
3235
 
    supports_external_lookups = True
3236
 
    # What index classes to use
3237
 
    index_builder_class = BTreeBuilder
3238
 
    index_class = BTreeGraphIndex
3239
 
    supports_chks = True
3240
 
    _commit_inv_deltas = True
3241
 
 
3242
 
    def _get_matching_bzrdir(self):
3243
 
        return bzrdir.format_registry.make_bzrdir('development5-hash255')
3244
 
 
3245
 
    def _ignore_setting_bzrdir(self, format):
3246
 
        pass
3247
 
 
3248
 
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
3249
 
 
3250
 
    def get_format_string(self):
3251
 
        """See RepositoryFormat.get_format_string()."""
3252
 
        return ("Bazaar development format 5 hash 255"
3253
 
                " (needs bzr.dev from before 1.13)\n")
3254
 
 
3255
 
    def get_format_description(self):
3256
 
        """See RepositoryFormat.get_format_description()."""
3257
 
        return ("Development repository format, currently the same as"
3258
 
                " 1.9 with B+Trees and chk support and 255-way hash tries\n")
3259
 
 
3260
 
    def check_conversion_target(self, target_format):
3261
 
        pass