~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: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
24
24
 
25
25
from bzrlib import (
26
26
    chk_map,
 
27
    cleanup,
27
28
    debug,
28
29
    graph,
29
30
    osutils,
36
37
    )
37
38
from bzrlib.index import (
38
39
    CombinedGraphIndex,
39
 
    GraphIndex,
40
 
    GraphIndexBuilder,
41
40
    GraphIndexPrefixAdapter,
42
 
    InMemoryGraphIndex,
43
41
    )
44
 
from bzrlib.inventory import CHKInventory
45
42
from bzrlib.knit import (
46
43
    KnitPlainFactory,
47
44
    KnitVersionedFiles,
52
49
""")
53
50
from bzrlib import (
54
51
    bzrdir,
55
 
    chk_serializer,
 
52
    btree_index,
56
53
    errors,
57
54
    lockable_files,
58
55
    lockdir,
59
56
    revision as _mod_revision,
60
 
    symbol_versioning,
61
57
    )
62
58
 
63
 
from bzrlib.decorators import needs_write_lock
64
 
from bzrlib.btree_index import (
65
 
    BTreeGraphIndex,
66
 
    BTreeBuilder,
67
 
    )
 
59
from bzrlib.decorators import needs_write_lock, only_raises
68
60
from bzrlib.index import (
69
61
    GraphIndex,
70
62
    InMemoryGraphIndex,
71
63
    )
 
64
from bzrlib.lock import LogicalLockResult
72
65
from bzrlib.repofmt.knitrepo import KnitRepository
73
66
from bzrlib.repository import (
74
67
    CommitBuilder,
75
68
    MetaDirRepositoryFormat,
76
69
    RepositoryFormat,
 
70
    RepositoryWriteLockResult,
77
71
    RootCommitBuilder,
 
72
    StreamSource,
78
73
    )
79
 
import bzrlib.revision as _mod_revision
80
74
from bzrlib.trace import (
81
75
    mutter,
 
76
    note,
82
77
    warning,
83
78
    )
84
79
 
230
225
        return self.index_name('text', name)
231
226
 
232
227
    def _replace_index_with_readonly(self, index_type):
233
 
        setattr(self, index_type + '_index',
234
 
            self.index_class(self.index_transport,
235
 
                self.index_name(index_type, self.name),
236
 
                self.index_sizes[self.index_offset(index_type)]))
 
228
        unlimited_cache = False
 
229
        if index_type == 'chk':
 
230
            unlimited_cache = True
 
231
        index = self.index_class(self.index_transport,
 
232
                    self.index_name(index_type, self.name),
 
233
                    self.index_sizes[self.index_offset(index_type)],
 
234
                    unlimited_cache=unlimited_cache)
 
235
        if index_type == 'chk':
 
236
            index._leaf_factory = btree_index._gcchk_factory
 
237
        setattr(self, index_type + '_index', index)
237
238
 
238
239
 
239
240
class ExistingPack(Pack):
270
271
 
271
272
    def __init__(self, name, revision_index, inventory_index, text_index,
272
273
        signature_index, upload_transport, pack_transport, index_transport,
273
 
        pack_collection):
 
274
        pack_collection, chk_index=None):
274
275
        """Create a ResumedPack object."""
275
276
        ExistingPack.__init__(self, pack_transport, name, revision_index,
276
 
            inventory_index, text_index, signature_index)
 
277
            inventory_index, text_index, signature_index,
 
278
            chk_index=chk_index)
277
279
        self.upload_transport = upload_transport
278
280
        self.index_transport = index_transport
279
281
        self.index_sizes = [None, None, None, None]
283
285
            ('text', text_index),
284
286
            ('signature', signature_index),
285
287
            ]
 
288
        if chk_index is not None:
 
289
            indices.append(('chk', chk_index))
 
290
            self.index_sizes.append(None)
286
291
        for index_type, index in indices:
287
292
            offset = self.index_offset(index_type)
288
293
            self.index_sizes[offset] = index._size
303
308
        self.upload_transport.delete(self.file_name())
304
309
        indices = [self.revision_index, self.inventory_index, self.text_index,
305
310
            self.signature_index]
 
311
        if self.chk_index is not None:
 
312
            indices.append(self.chk_index)
306
313
        for index in indices:
307
314
            index._transport.delete(index._name)
308
315
 
309
316
    def finish(self):
310
317
        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']:
 
318
        index_types = ['revision', 'inventory', 'text', 'signature']
 
319
        if self.chk_index is not None:
 
320
            index_types.append('chk')
 
321
        for index_type in index_types:
314
322
            old_name = self.index_name(index_type, self.name)
315
323
            new_name = '../indices/' + old_name
316
324
            self.upload_transport.rename(old_name, new_name)
317
325
            self._replace_index_with_readonly(index_type)
 
326
        new_name = '../packs/' + self.file_name()
 
327
        self.upload_transport.rename(self.file_name(), new_name)
318
328
        self._state = 'finished'
319
329
 
320
330
    def _get_external_refs(self, index):
 
331
        """Return compression parents for this index that are not present.
 
332
 
 
333
        This returns any compression parents that are referenced by this index,
 
334
        which are not contained *in* this index. They may be present elsewhere.
 
335
        """
321
336
        return index.external_references(1)
322
337
 
323
338
 
414
429
        self._writer.begin()
415
430
        # what state is the pack in? (open, finished, aborted)
416
431
        self._state = 'open'
 
432
        # no name until we finish writing the content
 
433
        self.name = None
417
434
 
418
435
    def abort(self):
419
436
        """Cancel creating this pack."""
440
457
            self.signature_index.key_count() or
441
458
            (self.chk_index is not None and self.chk_index.key_count()))
442
459
 
 
460
    def finish_content(self):
 
461
        if self.name is not None:
 
462
            return
 
463
        self._writer.end()
 
464
        if self._buffer[1]:
 
465
            self._write_data('', flush=True)
 
466
        self.name = self._hash.hexdigest()
 
467
 
443
468
    def finish(self, suspend=False):
444
469
        """Finish the new pack.
445
470
 
451
476
         - stores the index size tuple for the pack in the index_sizes
452
477
           attribute.
453
478
        """
454
 
        self._writer.end()
455
 
        if self._buffer[1]:
456
 
            self._write_data('', flush=True)
457
 
        self.name = self._hash.hexdigest()
 
479
        self.finish_content()
458
480
        if not suspend:
459
481
            self._check_references()
460
482
        # write indices
566
588
                                             flush_func=flush_func)
567
589
        self.add_callback = None
568
590
 
569
 
    def replace_indices(self, index_to_pack, indices):
570
 
        """Replace the current mappings with fresh ones.
571
 
 
572
 
        This should probably not be used eventually, rather incremental add and
573
 
        removal of indices. It has been added during refactoring of existing
574
 
        code.
575
 
 
576
 
        :param index_to_pack: A mapping from index objects to
577
 
            (transport, name) tuples for the pack file data.
578
 
        :param indices: A list of indices.
579
 
        """
580
 
        # refresh the revision pack map dict without replacing the instance.
581
 
        self.index_to_pack.clear()
582
 
        self.index_to_pack.update(index_to_pack)
583
 
        # XXX: API break - clearly a 'replace' method would be good?
584
 
        self.combined_index._indices[:] = indices
585
 
        # the current add nodes callback for the current writable index if
586
 
        # there is one.
587
 
        self.add_callback = None
588
 
 
589
591
    def add_index(self, index, pack):
590
592
        """Add index to the aggregate, which is an index for Pack pack.
591
593
 
598
600
        # expose it to the index map
599
601
        self.index_to_pack[index] = pack.access_tuple()
600
602
        # put it at the front of the linear index list
601
 
        self.combined_index.insert_index(0, index)
 
603
        self.combined_index.insert_index(0, index, pack.name)
602
604
 
603
605
    def add_writable_index(self, index, pack):
604
606
        """Add an index which is able to have data added to it.
624
626
        self.data_access.set_writer(None, None, (None, None))
625
627
        self.index_to_pack.clear()
626
628
        del self.combined_index._indices[:]
 
629
        del self.combined_index._index_names[:]
627
630
        self.add_callback = None
628
631
 
629
 
    def remove_index(self, index, pack):
 
632
    def remove_index(self, index):
630
633
        """Remove index from the indices used to answer queries.
631
634
 
632
635
        :param index: An index from the pack parameter.
633
 
        :param pack: A Pack instance.
634
636
        """
635
637
        del self.index_to_pack[index]
636
 
        self.combined_index._indices.remove(index)
 
638
        pos = self.combined_index._indices.index(index)
 
639
        del self.combined_index._indices[pos]
 
640
        del self.combined_index._index_names[pos]
637
641
        if (self.add_callback is not None and
638
642
            getattr(index, 'add_nodes', None) == self.add_callback):
639
643
            self.add_callback = None
1097
1101
            iterator is a tuple with:
1098
1102
            index, readv_vector, node_vector. readv_vector is a list ready to
1099
1103
            hand to the transport readv method, and node_vector is a list of
1100
 
            (key, eol_flag, references) for the the node retrieved by the
 
1104
            (key, eol_flag, references) for the node retrieved by the
1101
1105
            matching readv_vector.
1102
1106
        """
1103
1107
        # group by pack so we do one readv per pack
1294
1298
        # space (we only topo sort the revisions, which is smaller).
1295
1299
        topo_order = tsort.topo_sort(ancestors)
1296
1300
        rev_order = dict(zip(topo_order, range(len(topo_order))))
1297
 
        bad_texts.sort(key=lambda key:rev_order[key[0][1]])
 
1301
        bad_texts.sort(key=lambda key:rev_order.get(key[0][1], 0))
1298
1302
        transaction = repo.get_transaction()
1299
1303
        file_id_index = GraphIndexPrefixAdapter(
1300
1304
            self.new_pack.text_index,
1354
1358
    """
1355
1359
 
1356
1360
    pack_factory = NewPack
 
1361
    resumed_pack_factory = ResumedPack
1357
1362
 
1358
1363
    def __init__(self, repo, transport, index_transport, upload_transport,
1359
1364
                 pack_transport, index_builder_class, index_class,
1394
1399
        self.inventory_index = AggregateIndex(self.reload_pack_names, flush)
1395
1400
        self.text_index = AggregateIndex(self.reload_pack_names, flush)
1396
1401
        self.signature_index = AggregateIndex(self.reload_pack_names, flush)
 
1402
        all_indices = [self.revision_index, self.inventory_index,
 
1403
                self.text_index, self.signature_index]
1397
1404
        if use_chk_index:
1398
1405
            self.chk_index = AggregateIndex(self.reload_pack_names, flush)
 
1406
            all_indices.append(self.chk_index)
1399
1407
        else:
1400
1408
            # used to determine if we're using a chk_index elsewhere.
1401
1409
            self.chk_index = None
 
1410
        # Tell all the CombinedGraphIndex objects about each other, so they can
 
1411
        # share hints about which pack names to search first.
 
1412
        all_combined = [agg_idx.combined_index for agg_idx in all_indices]
 
1413
        for combined_idx in all_combined:
 
1414
            combined_idx.set_sibling_indices(
 
1415
                set(all_combined).difference([combined_idx]))
1402
1416
        # resumed packs
1403
1417
        self._resumed_packs = []
1404
1418
 
 
1419
    def __repr__(self):
 
1420
        return '%s(%r)' % (self.__class__.__name__, self.repo)
 
1421
 
1405
1422
    def add_pack_to_memory(self, pack):
1406
1423
        """Make a Pack object available to the repository to satisfy queries.
1407
1424
 
1445
1462
        in synchronisation with certain steps. Otherwise the names collection
1446
1463
        is not flushed.
1447
1464
 
1448
 
        :return: True if packing took place.
 
1465
        :return: Something evaluating true if packing took place.
1449
1466
        """
1450
1467
        while True:
1451
1468
            try:
1452
1469
                return self._do_autopack()
1453
 
            except errors.RetryAutopack, e:
 
1470
            except errors.RetryAutopack:
1454
1471
                # If we get a RetryAutopack exception, we should abort the
1455
1472
                # current action, and retry.
1456
1473
                pass
1460
1477
        total_revisions = self.revision_index.combined_index.key_count()
1461
1478
        total_packs = len(self._names)
1462
1479
        if self._max_pack_count(total_revisions) >= total_packs:
1463
 
            return False
 
1480
            return None
1464
1481
        # determine which packs need changing
1465
1482
        pack_distribution = self.pack_distribution(total_revisions)
1466
1483
        existing_packs = []
1488
1505
            'containing %d revisions. Packing %d files into %d affecting %d'
1489
1506
            ' revisions', self, total_packs, total_revisions, num_old_packs,
1490
1507
            num_new_packs, num_revs_affected)
1491
 
        self._execute_pack_operations(pack_operations,
 
1508
        result = self._execute_pack_operations(pack_operations,
1492
1509
                                      reload_func=self._restart_autopack)
1493
1510
        mutter('Auto-packing repository %s completed', self)
1494
 
        return True
 
1511
        return result
1495
1512
 
1496
1513
    def _execute_pack_operations(self, pack_operations, _packer_class=Packer,
1497
1514
                                 reload_func=None):
1499
1516
 
1500
1517
        :param pack_operations: A list of [revision_count, packs_to_combine].
1501
1518
        :param _packer_class: The class of packer to use (default: Packer).
1502
 
        :return: None.
 
1519
        :return: The new pack names.
1503
1520
        """
1504
1521
        for revision_count, packs in pack_operations:
1505
1522
            # we may have no-ops from the setup logic
1521
1538
                self._remove_pack_from_memory(pack)
1522
1539
        # record the newly available packs and stop advertising the old
1523
1540
        # packs
1524
 
        self._save_pack_names(clear_obsolete_packs=True)
1525
 
        # Move the old packs out of the way now they are no longer referenced.
1526
 
        for revision_count, packs in pack_operations:
1527
 
            self._obsolete_packs(packs)
 
1541
        to_be_obsoleted = []
 
1542
        for _, packs in pack_operations:
 
1543
            to_be_obsoleted.extend(packs)
 
1544
        result = self._save_pack_names(clear_obsolete_packs=True,
 
1545
                                       obsolete_packs=to_be_obsoleted)
 
1546
        return result
1528
1547
 
1529
1548
    def _flush_new_pack(self):
1530
1549
        if self._new_pack is not None:
1540
1559
 
1541
1560
    def _already_packed(self):
1542
1561
        """Is the collection already packed?"""
1543
 
        return len(self._names) < 2
 
1562
        return not (self.repo._format.pack_compresses or (len(self._names) > 1))
1544
1563
 
1545
 
    def pack(self):
 
1564
    def pack(self, hint=None, clean_obsolete_packs=False):
1546
1565
        """Pack the pack collection totally."""
1547
1566
        self.ensure_loaded()
1548
1567
        total_packs = len(self._names)
1549
1568
        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
1569
            return
1554
1570
        total_revisions = self.revision_index.combined_index.key_count()
1555
1571
        # XXX: the following may want to be a class, to pack with a given
1556
1572
        # policy.
1557
1573
        mutter('Packing repository %s, which has %d pack files, '
1558
 
            'containing %d revisions into 1 packs.', self, total_packs,
1559
 
            total_revisions)
 
1574
            'containing %d revisions with hint %r.', self, total_packs,
 
1575
            total_revisions, hint)
1560
1576
        # determine which packs need changing
1561
 
        pack_distribution = [1]
1562
1577
        pack_operations = [[0, []]]
1563
1578
        for pack in self.all_packs():
1564
 
            pack_operations[-1][0] += pack.get_revision_count()
1565
 
            pack_operations[-1][1].append(pack)
 
1579
            if hint is None or pack.name in hint:
 
1580
                # Either no hint was provided (so we are packing everything),
 
1581
                # or this pack was included in the hint.
 
1582
                pack_operations[-1][0] += pack.get_revision_count()
 
1583
                pack_operations[-1][1].append(pack)
1566
1584
        self._execute_pack_operations(pack_operations, OptimisingPacker)
1567
1585
 
 
1586
        if clean_obsolete_packs:
 
1587
            self._clear_obsolete_packs()
 
1588
 
1568
1589
    def plan_autopack_combinations(self, existing_packs, pack_distribution):
1569
1590
        """Plan a pack operation.
1570
1591
 
1658
1679
            txt_index = self._make_index(name, '.tix')
1659
1680
            sig_index = self._make_index(name, '.six')
1660
1681
            if self.chk_index is not None:
1661
 
                chk_index = self._make_index(name, '.cix')
 
1682
                chk_index = self._make_index(name, '.cix', is_chk=True)
1662
1683
            else:
1663
1684
                chk_index = None
1664
1685
            result = ExistingPack(self._pack_transport, name, rev_index,
1682
1703
            inv_index = self._make_index(name, '.iix', resume=True)
1683
1704
            txt_index = self._make_index(name, '.tix', resume=True)
1684
1705
            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)
 
1706
            if self.chk_index is not None:
 
1707
                chk_index = self._make_index(name, '.cix', resume=True,
 
1708
                                             is_chk=True)
 
1709
            else:
 
1710
                chk_index = None
 
1711
            result = self.resumed_pack_factory(name, rev_index, inv_index,
 
1712
                txt_index, sig_index, self._upload_transport,
 
1713
                self._pack_transport, self._index_transport, self,
 
1714
                chk_index=chk_index)
1688
1715
        except errors.NoSuchFile, e:
1689
1716
            raise errors.UnresumableWriteGroup(self.repo, [name], str(e))
1690
1717
        self.add_pack_to_memory(result)
1714
1741
        return self._index_class(self.transport, 'pack-names', None
1715
1742
                ).iter_all_entries()
1716
1743
 
1717
 
    def _make_index(self, name, suffix, resume=False):
 
1744
    def _make_index(self, name, suffix, resume=False, is_chk=False):
1718
1745
        size_offset = self._suffix_offsets[suffix]
1719
1746
        index_name = name + suffix
1720
1747
        if resume:
1723
1750
        else:
1724
1751
            transport = self._index_transport
1725
1752
            index_size = self._names[name][size_offset]
1726
 
        return self._index_class(transport, index_name, index_size)
 
1753
        index = self._index_class(transport, index_name, index_size,
 
1754
                                  unlimited_cache=is_chk)
 
1755
        if is_chk and self._index_class is btree_index.BTreeGraphIndex: 
 
1756
            index._leaf_factory = btree_index._gcchk_factory
 
1757
        return index
1727
1758
 
1728
1759
    def _max_pack_count(self, total_revisions):
1729
1760
        """Return the maximum number of packs to use for total revisions.
1757
1788
        :param return: None.
1758
1789
        """
1759
1790
        for pack in packs:
1760
 
            pack.pack_transport.rename(pack.file_name(),
1761
 
                '../obsolete_packs/' + pack.file_name())
 
1791
            try:
 
1792
                pack.pack_transport.rename(pack.file_name(),
 
1793
                    '../obsolete_packs/' + pack.file_name())
 
1794
            except (errors.PathError, errors.TransportError), e:
 
1795
                # TODO: Should these be warnings or mutters?
 
1796
                mutter("couldn't rename obsolete pack, skipping it:\n%s"
 
1797
                       % (e,))
1762
1798
            # TODO: Probably needs to know all possible indices for this pack
1763
1799
            # - or maybe list the directory and move all indices matching this
1764
1800
            # name whether we recognize it or not?
1766
1802
            if self.chk_index is not None:
1767
1803
                suffixes.append('.cix')
1768
1804
            for suffix in suffixes:
1769
 
                self._index_transport.rename(pack.name + suffix,
1770
 
                    '../obsolete_packs/' + pack.name + suffix)
 
1805
                try:
 
1806
                    self._index_transport.rename(pack.name + suffix,
 
1807
                        '../obsolete_packs/' + pack.name + suffix)
 
1808
                except (errors.PathError, errors.TransportError), e:
 
1809
                    mutter("couldn't rename obsolete index, skipping it:\n%s"
 
1810
                           % (e,))
1771
1811
 
1772
1812
    def pack_distribution(self, total_revisions):
1773
1813
        """Generate a list of the number of revisions to put in each pack.
1799
1839
        self._remove_pack_indices(pack)
1800
1840
        self.packs.remove(pack)
1801
1841
 
1802
 
    def _remove_pack_indices(self, pack):
1803
 
        """Remove the indices for pack from the aggregated indices."""
1804
 
        self.revision_index.remove_index(pack.revision_index, pack)
1805
 
        self.inventory_index.remove_index(pack.inventory_index, pack)
1806
 
        self.text_index.remove_index(pack.text_index, pack)
1807
 
        self.signature_index.remove_index(pack.signature_index, pack)
1808
 
        if self.chk_index is not None:
1809
 
            self.chk_index.remove_index(pack.chk_index, pack)
 
1842
    def _remove_pack_indices(self, pack, ignore_missing=False):
 
1843
        """Remove the indices for pack from the aggregated indices.
 
1844
        
 
1845
        :param ignore_missing: Suppress KeyErrors from calling remove_index.
 
1846
        """
 
1847
        for index_type in Pack.index_definitions.keys():
 
1848
            attr_name = index_type + '_index'
 
1849
            aggregate_index = getattr(self, attr_name)
 
1850
            if aggregate_index is not None:
 
1851
                pack_index = getattr(pack, attr_name)
 
1852
                try:
 
1853
                    aggregate_index.remove_index(pack_index)
 
1854
                except KeyError:
 
1855
                    if ignore_missing:
 
1856
                        continue
 
1857
                    raise
1810
1858
 
1811
1859
    def reset(self):
1812
1860
        """Clear all cached data."""
1813
1861
        # cached revision data
1814
 
        self.repo._revision_knit = None
1815
1862
        self.revision_index.clear()
1816
1863
        # cached signature data
1817
 
        self.repo._signature_knit = None
1818
1864
        self.signature_index.clear()
1819
1865
        # cached file text data
1820
1866
        self.text_index.clear()
1821
 
        self.repo._text_knit = None
1822
1867
        # cached inventory data
1823
1868
        self.inventory_index.clear()
1824
1869
        # cached chk data
1848
1893
        disk_nodes = set()
1849
1894
        for index, key, value in self._iter_disk_pack_index():
1850
1895
            disk_nodes.add((key, value))
 
1896
        orig_disk_nodes = set(disk_nodes)
1851
1897
 
1852
1898
        # do a two-way diff against our original content
1853
1899
        current_nodes = set()
1866
1912
        disk_nodes.difference_update(deleted_nodes)
1867
1913
        disk_nodes.update(new_nodes)
1868
1914
 
1869
 
        return disk_nodes, deleted_nodes, new_nodes
 
1915
        return disk_nodes, deleted_nodes, new_nodes, orig_disk_nodes
1870
1916
 
1871
1917
    def _syncronize_pack_names_from_disk_nodes(self, disk_nodes):
1872
1918
        """Given the correct set of pack files, update our saved info.
1912
1958
                added.append(name)
1913
1959
        return removed, added, modified
1914
1960
 
1915
 
    def _save_pack_names(self, clear_obsolete_packs=False):
 
1961
    def _save_pack_names(self, clear_obsolete_packs=False, obsolete_packs=None):
1916
1962
        """Save the list of packs.
1917
1963
 
1918
1964
        This will take out the mutex around the pack names list for the
1922
1968
 
1923
1969
        :param clear_obsolete_packs: If True, clear out the contents of the
1924
1970
            obsolete_packs directory.
 
1971
        :param obsolete_packs: Packs that are obsolete once the new pack-names
 
1972
            file has been written.
 
1973
        :return: A list of the names saved that were not previously on disk.
1925
1974
        """
 
1975
        already_obsolete = []
1926
1976
        self.lock_names()
1927
1977
        try:
1928
1978
            builder = self._index_builder_class()
1929
 
            disk_nodes, deleted_nodes, new_nodes = self._diff_pack_names()
 
1979
            (disk_nodes, deleted_nodes, new_nodes,
 
1980
             orig_disk_nodes) = self._diff_pack_names()
1930
1981
            # TODO: handle same-name, index-size-changes here -
1931
1982
            # e.g. use the value from disk, not ours, *unless* we're the one
1932
1983
            # changing it.
1934
1985
                builder.add_node(key, value)
1935
1986
            self.transport.put_file('pack-names', builder.finish(),
1936
1987
                mode=self.repo.bzrdir._get_file_mode())
1937
 
            # move the baseline forward
1938
1988
            self._packs_at_load = disk_nodes
1939
1989
            if clear_obsolete_packs:
1940
 
                self._clear_obsolete_packs()
 
1990
                to_preserve = None
 
1991
                if obsolete_packs:
 
1992
                    to_preserve = set([o.name for o in obsolete_packs])
 
1993
                already_obsolete = self._clear_obsolete_packs(to_preserve)
1941
1994
        finally:
1942
1995
            self._unlock_names()
1943
1996
        # synchronise the memory packs list with what we just wrote:
1944
1997
        self._syncronize_pack_names_from_disk_nodes(disk_nodes)
 
1998
        if obsolete_packs:
 
1999
            # TODO: We could add one more condition here. "if o.name not in
 
2000
            #       orig_disk_nodes and o != the new_pack we haven't written to
 
2001
            #       disk yet. However, the new pack object is not easily
 
2002
            #       accessible here (it would have to be passed through the
 
2003
            #       autopacking code, etc.)
 
2004
            obsolete_packs = [o for o in obsolete_packs
 
2005
                              if o.name not in already_obsolete]
 
2006
            self._obsolete_packs(obsolete_packs)
 
2007
        return [new_node[0][0] for new_node in new_nodes]
1945
2008
 
1946
2009
    def reload_pack_names(self):
1947
2010
        """Sync our pack listing with what is present in the repository.
1961
2024
        if first_read:
1962
2025
            return True
1963
2026
        # out the new value.
1964
 
        disk_nodes, _, _ = self._diff_pack_names()
1965
 
        self._packs_at_load = disk_nodes
 
2027
        (disk_nodes, deleted_nodes, new_nodes,
 
2028
         orig_disk_nodes) = self._diff_pack_names()
 
2029
        # _packs_at_load is meant to be the explicit list of names in
 
2030
        # 'pack-names' at then start. As such, it should not contain any
 
2031
        # pending names that haven't been written out yet.
 
2032
        self._packs_at_load = orig_disk_nodes
1966
2033
        (removed, added,
1967
2034
         modified) = self._syncronize_pack_names_from_disk_nodes(disk_nodes)
1968
2035
        if removed or added or modified:
1977
2044
            raise
1978
2045
        raise errors.RetryAutopack(self.repo, False, sys.exc_info())
1979
2046
 
1980
 
    def _clear_obsolete_packs(self):
 
2047
    def _clear_obsolete_packs(self, preserve=None):
1981
2048
        """Delete everything from the obsolete-packs directory.
 
2049
 
 
2050
        :return: A list of pack identifiers (the filename without '.pack') that
 
2051
            were found in obsolete_packs.
1982
2052
        """
 
2053
        found = []
1983
2054
        obsolete_pack_transport = self.transport.clone('obsolete_packs')
 
2055
        if preserve is None:
 
2056
            preserve = set()
1984
2057
        for filename in obsolete_pack_transport.list_dir('.'):
 
2058
            name, ext = osutils.splitext(filename)
 
2059
            if ext == '.pack':
 
2060
                found.append(name)
 
2061
            if name in preserve:
 
2062
                continue
1985
2063
            try:
1986
2064
                obsolete_pack_transport.delete(filename)
1987
2065
            except (errors.PathError, errors.TransportError), e:
1988
 
                warning("couldn't delete obsolete pack, skipping it:\n%s" % (e,))
 
2066
                warning("couldn't delete obsolete pack, skipping it:\n%s"
 
2067
                        % (e,))
 
2068
        return found
1989
2069
 
1990
2070
    def _start_write_group(self):
1991
2071
        # Do not permit preparation for writing if we're not in a 'write lock'.
2000
2080
            self._new_pack)
2001
2081
        self.text_index.add_writable_index(self._new_pack.text_index,
2002
2082
            self._new_pack)
 
2083
        self._new_pack.text_index.set_optimize(combine_backing_indices=False)
2003
2084
        self.signature_index.add_writable_index(self._new_pack.signature_index,
2004
2085
            self._new_pack)
2005
2086
        if self.chk_index is not None:
2006
2087
            self.chk_index.add_writable_index(self._new_pack.chk_index,
2007
2088
                self._new_pack)
2008
2089
            self.repo.chk_bytes._index._add_callback = self.chk_index.add_callback
 
2090
            self._new_pack.chk_index.set_optimize(combine_backing_indices=False)
2009
2091
 
2010
2092
        self.repo.inventories._index._add_callback = self.inventory_index.add_callback
2011
2093
        self.repo.revisions._index._add_callback = self.revision_index.add_callback
2016
2098
        # FIXME: just drop the transient index.
2017
2099
        # forget what names there are
2018
2100
        if self._new_pack is not None:
2019
 
            try:
2020
 
                self._new_pack.abort()
2021
 
            finally:
2022
 
                # XXX: If we aborted while in the middle of finishing the write
2023
 
                # group, _remove_pack_indices can fail because the indexes are
2024
 
                # already gone.  If they're not there we shouldn't fail in this
2025
 
                # case.  -- mbp 20081113
2026
 
                self._remove_pack_indices(self._new_pack)
2027
 
                self._new_pack = None
 
2101
            operation = cleanup.OperationWithCleanups(self._new_pack.abort)
 
2102
            operation.add_cleanup(setattr, self, '_new_pack', None)
 
2103
            # If we aborted while in the middle of finishing the write
 
2104
            # group, _remove_pack_indices could fail because the indexes are
 
2105
            # already gone.  But they're not there we shouldn't fail in this
 
2106
            # case, so we pass ignore_missing=True.
 
2107
            operation.add_cleanup(self._remove_pack_indices, self._new_pack,
 
2108
                ignore_missing=True)
 
2109
            operation.run_simple()
2028
2110
        for resumed_pack in self._resumed_packs:
2029
 
            try:
2030
 
                resumed_pack.abort()
2031
 
            finally:
2032
 
                # See comment in previous finally block.
2033
 
                try:
2034
 
                    self._remove_pack_indices(resumed_pack)
2035
 
                except KeyError:
2036
 
                    pass
 
2111
            operation = cleanup.OperationWithCleanups(resumed_pack.abort)
 
2112
            # See comment in previous finally block.
 
2113
            operation.add_cleanup(self._remove_pack_indices, resumed_pack,
 
2114
                ignore_missing=True)
 
2115
            operation.run_simple()
2037
2116
        del self._resumed_packs[:]
2038
 
        self.repo._text_knit = None
2039
2117
 
2040
2118
    def _remove_resumed_pack_indices(self):
2041
2119
        for resumed_pack in self._resumed_packs:
2042
2120
            self._remove_pack_indices(resumed_pack)
2043
2121
        del self._resumed_packs[:]
2044
2122
 
 
2123
    def _check_new_inventories(self):
 
2124
        """Detect missing inventories in this write group.
 
2125
 
 
2126
        :returns: list of strs, summarising any problems found.  If the list is
 
2127
            empty no problems were found.
 
2128
        """
 
2129
        # The base implementation does no checks.  GCRepositoryPackCollection
 
2130
        # overrides this.
 
2131
        return []
 
2132
        
2045
2133
    def _commit_write_group(self):
2046
2134
        all_missing = set()
2047
2135
        for prefix, versioned_file in (
2056
2144
            raise errors.BzrCheckError(
2057
2145
                "Repository %s has missing compression parent(s) %r "
2058
2146
                 % (self.repo, sorted(all_missing)))
 
2147
        problems = self._check_new_inventories()
 
2148
        if problems:
 
2149
            problems_summary = '\n'.join(problems)
 
2150
            raise errors.BzrCheckError(
 
2151
                "Cannot add revision(s) to repository: " + problems_summary)
2059
2152
        self._remove_pack_indices(self._new_pack)
2060
 
        should_autopack = False
 
2153
        any_new_content = False
2061
2154
        if self._new_pack.data_inserted():
2062
2155
            # get all the data to disk and read to use
2063
2156
            self._new_pack.finish()
2064
2157
            self.allocate(self._new_pack)
2065
2158
            self._new_pack = None
2066
 
            should_autopack = True
 
2159
            any_new_content = True
2067
2160
        else:
2068
2161
            self._new_pack.abort()
2069
2162
            self._new_pack = None
2074
2167
            self._remove_pack_from_memory(resumed_pack)
2075
2168
            resumed_pack.finish()
2076
2169
            self.allocate(resumed_pack)
2077
 
            should_autopack = True
 
2170
            any_new_content = True
2078
2171
        del self._resumed_packs[:]
2079
 
        if should_autopack:
2080
 
            if not self.autopack():
 
2172
        if any_new_content:
 
2173
            result = self.autopack()
 
2174
            if not result:
2081
2175
                # when autopack takes no steps, the names list is still
2082
2176
                # unsaved.
2083
 
                self._save_pack_names()
2084
 
        self.repo._text_knit = None
 
2177
                return self._save_pack_names()
 
2178
            return result
 
2179
        return []
2085
2180
 
2086
2181
    def _suspend_write_group(self):
2087
2182
        tokens = [pack.name for pack in self._resumed_packs]
2095
2190
            self._new_pack.abort()
2096
2191
            self._new_pack = None
2097
2192
        self._remove_resumed_pack_indices()
2098
 
        self.repo._text_knit = None
2099
2193
        return tokens
2100
2194
 
2101
2195
    def _resume_write_group(self, tokens):
2150
2244
        self.revisions = KnitVersionedFiles(
2151
2245
            _KnitGraphIndex(self._pack_collection.revision_index.combined_index,
2152
2246
                add_callback=self._pack_collection.revision_index.add_callback,
2153
 
                deltas=False, parents=True, is_locked=self.is_locked),
 
2247
                deltas=False, parents=True, is_locked=self.is_locked,
 
2248
                track_external_parent_refs=True),
2154
2249
            data_access=self._pack_collection.revision_index.data_access,
2155
2250
            max_delta_chain=0)
2156
2251
        self.signatures = KnitVersionedFiles(
2189
2284
        self._reconcile_fixes_text_parents = True
2190
2285
        self._reconcile_backsup_inventory = False
2191
2286
 
2192
 
    def _warn_if_deprecated(self):
 
2287
    def _warn_if_deprecated(self, branch=None):
2193
2288
        # This class isn't deprecated, but one sub-format is
2194
2289
        if isinstance(self._format, RepositoryFormatKnitPack5RichRootBroken):
2195
 
            from bzrlib import repository
2196
 
            if repository._deprecation_warning_done:
2197
 
                return
2198
 
            repository._deprecation_warning_done = True
2199
 
            warning("Format %s for %s is deprecated - please use"
2200
 
                    " 'bzr upgrade --1.6.1-rich-root'"
2201
 
                    % (self._format, self.bzrdir.transport.base))
 
2290
            super(KnitPackRepository, self)._warn_if_deprecated(branch)
2202
2291
 
2203
2292
    def _abort_write_group(self):
 
2293
        self.revisions._index._key_dependencies.clear()
2204
2294
        self._pack_collection._abort_write_group()
2205
2295
 
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
 
2296
    def _get_source(self, to_format):
 
2297
        if to_format.network_name() == self._format.network_name():
 
2298
            return KnitPackStreamSource(self, to_format)
 
2299
        return super(KnitPackRepository, self)._get_source(to_format)
2250
2300
 
2251
2301
    def _make_parents_provider(self):
2252
2302
        return graph.CachingParentsProvider(self)
2260
2310
        self._pack_collection._start_write_group()
2261
2311
 
2262
2312
    def _commit_write_group(self):
2263
 
        return self._pack_collection._commit_write_group()
 
2313
        hint = self._pack_collection._commit_write_group()
 
2314
        self.revisions._index._key_dependencies.clear()
 
2315
        return hint
2264
2316
 
2265
2317
    def suspend_write_group(self):
2266
2318
        # XXX check self._write_group is self.get_transaction()?
2267
2319
        tokens = self._pack_collection._suspend_write_group()
 
2320
        self.revisions._index._key_dependencies.clear()
2268
2321
        self._write_group = None
2269
2322
        return tokens
2270
2323
 
2271
2324
    def _resume_write_group(self, tokens):
2272
2325
        self._start_write_group()
2273
 
        self._pack_collection._resume_write_group(tokens)
 
2326
        try:
 
2327
            self._pack_collection._resume_write_group(tokens)
 
2328
        except errors.UnresumableWriteGroup:
 
2329
            self._abort_write_group()
 
2330
            raise
 
2331
        for pack in self._pack_collection._resumed_packs:
 
2332
            self.revisions._index.scan_unvalidated_index(pack.revision_index)
2274
2333
 
2275
2334
    def get_transaction(self):
2276
2335
        if self._write_lock_count:
2285
2344
        return self._write_lock_count
2286
2345
 
2287
2346
    def lock_write(self, token=None):
 
2347
        """Lock the repository for writes.
 
2348
 
 
2349
        :return: A bzrlib.repository.RepositoryWriteLockResult.
 
2350
        """
2288
2351
        locked = self.is_locked()
2289
2352
        if not self._write_lock_count and locked:
2290
2353
            raise errors.ReadOnlyError(self)
2291
2354
        self._write_lock_count += 1
2292
2355
        if self._write_lock_count == 1:
2293
2356
            self._transaction = transactions.WriteTransaction()
 
2357
        if not locked:
 
2358
            if 'relock' in debug.debug_flags and self._prev_lock == 'w':
 
2359
                note('%r was write locked again', self)
 
2360
            self._prev_lock = 'w'
2294
2361
            for repo in self._fallback_repositories:
2295
2362
                # Writes don't affect fallback repos
2296
2363
                repo.lock_read()
2297
 
        if not locked:
2298
2364
            self._refresh_data()
 
2365
        return RepositoryWriteLockResult(self.unlock, None)
2299
2366
 
2300
2367
    def lock_read(self):
 
2368
        """Lock the repository for reads.
 
2369
 
 
2370
        :return: A bzrlib.lock.LogicalLockResult.
 
2371
        """
2301
2372
        locked = self.is_locked()
2302
2373
        if self._write_lock_count:
2303
2374
            self._write_lock_count += 1
2304
2375
        else:
2305
2376
            self.control_files.lock_read()
 
2377
        if not locked:
 
2378
            if 'relock' in debug.debug_flags and self._prev_lock == 'r':
 
2379
                note('%r was read locked again', self)
 
2380
            self._prev_lock = 'r'
2306
2381
            for repo in self._fallback_repositories:
2307
 
                # Writes don't affect fallback repos
2308
2382
                repo.lock_read()
2309
 
        if not locked:
2310
2383
            self._refresh_data()
 
2384
        return LogicalLockResult(self.unlock)
2311
2385
 
2312
2386
    def leave_lock_in_place(self):
2313
2387
        # not supported - raise an error
2318
2392
        raise NotImplementedError(self.dont_leave_lock_in_place)
2319
2393
 
2320
2394
    @needs_write_lock
2321
 
    def pack(self):
 
2395
    def pack(self, hint=None, clean_obsolete_packs=False):
2322
2396
        """Compress the data within the repository.
2323
2397
 
2324
2398
        This will pack all the data to a single pack. In future it may
2325
2399
        recompress deltas or do other such expensive operations.
2326
2400
        """
2327
 
        self._pack_collection.pack()
 
2401
        self._pack_collection.pack(hint=hint, clean_obsolete_packs=clean_obsolete_packs)
2328
2402
 
2329
2403
    @needs_write_lock
2330
2404
    def reconcile(self, other=None, thorough=False):
2338
2412
        packer = ReconcilePacker(collection, packs, extension, revs)
2339
2413
        return packer.pack(pb)
2340
2414
 
 
2415
    @only_raises(errors.LockNotHeld, errors.LockBroken)
2341
2416
    def unlock(self):
2342
2417
        if self._write_lock_count == 1 and self._write_group is not None:
2343
2418
            self.abort_write_group()
2352
2427
                transaction = self._transaction
2353
2428
                self._transaction = None
2354
2429
                transaction.finish()
2355
 
                for repo in self._fallback_repositories:
2356
 
                    repo.unlock()
2357
2430
        else:
2358
2431
            self.control_files.unlock()
 
2432
 
 
2433
        if not self.is_locked():
2359
2434
            for repo in self._fallback_repositories:
2360
2435
                repo.unlock()
2361
2436
 
2362
2437
 
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)
 
2438
class KnitPackStreamSource(StreamSource):
 
2439
    """A StreamSource used to transfer data between same-format KnitPack repos.
 
2440
 
 
2441
    This source assumes:
 
2442
        1) Same serialization format for all objects
 
2443
        2) Same root information
 
2444
        3) XML format inventories
 
2445
        4) Atomic inserts (so we can stream inventory texts before text
 
2446
           content)
 
2447
        5) No chk_bytes
 
2448
    """
 
2449
 
 
2450
    def __init__(self, from_repository, to_format):
 
2451
        super(KnitPackStreamSource, self).__init__(from_repository, to_format)
 
2452
        self._text_keys = None
 
2453
        self._text_fetch_order = 'unordered'
 
2454
 
 
2455
    def _get_filtered_inv_stream(self, revision_ids):
 
2456
        from_repo = self.from_repository
 
2457
        parent_ids = from_repo._find_parent_ids_of_revisions(revision_ids)
 
2458
        parent_keys = [(p,) for p in parent_ids]
 
2459
        find_text_keys = from_repo._find_text_key_references_from_xml_inventory_lines
 
2460
        parent_text_keys = set(find_text_keys(
 
2461
            from_repo._inventory_xml_lines_for_keys(parent_keys)))
 
2462
        content_text_keys = set()
 
2463
        knit = KnitVersionedFiles(None, None)
 
2464
        factory = KnitPlainFactory()
 
2465
        def find_text_keys_from_content(record):
 
2466
            if record.storage_kind not in ('knit-delta-gz', 'knit-ft-gz'):
 
2467
                raise ValueError("Unknown content storage kind for"
 
2468
                    " inventory text: %s" % (record.storage_kind,))
 
2469
            # It's a knit record, it has a _raw_record field (even if it was
 
2470
            # reconstituted from a network stream).
 
2471
            raw_data = record._raw_record
 
2472
            # read the entire thing
 
2473
            revision_id = record.key[-1]
 
2474
            content, _ = knit._parse_record(revision_id, raw_data)
 
2475
            if record.storage_kind == 'knit-delta-gz':
 
2476
                line_iterator = factory.get_linedelta_content(content)
 
2477
            elif record.storage_kind == 'knit-ft-gz':
 
2478
                line_iterator = factory.get_fulltext_content(content)
 
2479
            content_text_keys.update(find_text_keys(
 
2480
                [(line, revision_id) for line in line_iterator]))
 
2481
        revision_keys = [(r,) for r in revision_ids]
 
2482
        def _filtered_inv_stream():
 
2483
            source_vf = from_repo.inventories
 
2484
            stream = source_vf.get_record_stream(revision_keys,
 
2485
                                                 'unordered', False)
 
2486
            for record in stream:
 
2487
                if record.storage_kind == 'absent':
 
2488
                    raise errors.NoSuchRevision(from_repo, record.key)
 
2489
                find_text_keys_from_content(record)
 
2490
                yield record
 
2491
            self._text_keys = content_text_keys - parent_text_keys
 
2492
        return ('inventories', _filtered_inv_stream())
 
2493
 
 
2494
    def _get_text_stream(self):
 
2495
        # Note: We know we don't have to handle adding root keys, because both
 
2496
        # the source and target are the identical network name.
 
2497
        text_stream = self.from_repository.texts.get_record_stream(
 
2498
                        self._text_keys, self._text_fetch_order, False)
 
2499
        return ('texts', text_stream)
 
2500
 
 
2501
    def get_stream(self, search):
 
2502
        revision_ids = search.get_keys()
 
2503
        for stream_info in self._fetch_revision_texts(revision_ids):
 
2504
            yield stream_info
 
2505
        self._revision_keys = [(rev_id,) for rev_id in revision_ids]
 
2506
        yield self._get_filtered_inv_stream(revision_ids)
 
2507
        yield self._get_text_stream()
 
2508
 
2580
2509
 
2581
2510
 
2582
2511
class RepositoryFormatPack(MetaDirRepositoryFormat):
2631
2560
        utf8_files = [('format', self.get_format_string())]
2632
2561
 
2633
2562
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
2634
 
        return self.open(a_bzrdir=a_bzrdir, _found=True)
 
2563
        repository = self.open(a_bzrdir=a_bzrdir, _found=True)
 
2564
        self._run_post_repo_init_hooks(repository, a_bzrdir, shared)
 
2565
        return repository
2635
2566
 
2636
2567
    def open(self, a_bzrdir, _found=False, _override_transport=None):
2637
2568
        """See RepositoryFormat.open().
2686
2617
        """See RepositoryFormat.get_format_description()."""
2687
2618
        return "Packs containing knits without subtree support"
2688
2619
 
2689
 
    def check_conversion_target(self, target_format):
2690
 
        pass
2691
 
 
2692
2620
 
2693
2621
class RepositoryFormatKnitPack3(RepositoryFormatPack):
2694
2622
    """A subtrees parameterized Pack repository.
2703
2631
    repository_class = KnitPackRepository
2704
2632
    _commit_builder_class = PackRootCommitBuilder
2705
2633
    rich_root_data = True
 
2634
    experimental = True
2706
2635
    supports_tree_reference = True
2707
2636
    @property
2708
2637
    def _serializer(self):
2720
2649
 
2721
2650
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
2722
2651
 
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
2652
    def get_format_string(self):
2732
2653
        """See RepositoryFormat.get_format_string()."""
2733
2654
        return "Bazaar pack repository format 1 with subtree support (needs bzr 0.92)\n"
2766
2687
 
2767
2688
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
2768
2689
 
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
2690
    def get_format_string(self):
2775
2691
        """See RepositoryFormat.get_format_string()."""
2776
2692
        return ("Bazaar pack repository format 1 with rich root"
2817
2733
        """See RepositoryFormat.get_format_description()."""
2818
2734
        return "Packs 5 (adds stacking support, requires bzr 1.6)"
2819
2735
 
2820
 
    def check_conversion_target(self, target_format):
2821
 
        pass
2822
 
 
2823
2736
 
2824
2737
class RepositoryFormatKnitPack5RichRoot(RepositoryFormatPack):
2825
2738
    """A repository with rich roots and stacking.
2852
2765
 
2853
2766
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
2854
2767
 
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
2768
    def get_format_string(self):
2861
2769
        """See RepositoryFormat.get_format_string()."""
2862
2770
        return "Bazaar RepositoryFormatKnitPack5RichRoot (bzr 1.6.1)\n"
2903
2811
 
2904
2812
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
2905
2813
 
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
2814
    def get_format_string(self):
2912
2815
        """See RepositoryFormat.get_format_string()."""
2913
2816
        return "Bazaar RepositoryFormatKnitPack5RichRoot (bzr 1.6)\n"
2928
2831
    _commit_builder_class = PackCommitBuilder
2929
2832
    supports_external_lookups = True
2930
2833
    # What index classes to use
2931
 
    index_builder_class = BTreeBuilder
2932
 
    index_class = BTreeGraphIndex
 
2834
    index_builder_class = btree_index.BTreeBuilder
 
2835
    index_class = btree_index.BTreeGraphIndex
2933
2836
 
2934
2837
    @property
2935
2838
    def _serializer(self):
2951
2854
        """See RepositoryFormat.get_format_description()."""
2952
2855
        return "Packs 6 (uses btree indexes, requires bzr 1.9)"
2953
2856
 
2954
 
    def check_conversion_target(self, target_format):
2955
 
        pass
2956
 
 
2957
2857
 
2958
2858
class RepositoryFormatKnitPack6RichRoot(RepositoryFormatPack):
2959
2859
    """A repository with rich roots, no subtrees, stacking and btree indexes.
2967
2867
    supports_tree_reference = False # no subtrees
2968
2868
    supports_external_lookups = True
2969
2869
    # What index classes to use
2970
 
    index_builder_class = BTreeBuilder
2971
 
    index_class = BTreeGraphIndex
 
2870
    index_builder_class = btree_index.BTreeBuilder
 
2871
    index_class = btree_index.BTreeGraphIndex
2972
2872
 
2973
2873
    @property
2974
2874
    def _serializer(self):
2983
2883
 
2984
2884
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
2985
2885
 
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
2886
    def get_format_string(self):
2992
2887
        """See RepositoryFormat.get_format_string()."""
2993
2888
        return "Bazaar RepositoryFormatKnitPack6RichRoot (bzr 1.9)\n"
2996
2891
        return "Packs 6 rich-root (uses btree indexes, requires bzr 1.9)"
2997
2892
 
2998
2893
 
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
2894
class RepositoryFormatPackDevelopment2Subtree(RepositoryFormatPack):
3043
2895
    """A subtrees development repository.
3044
2896
 
3045
2897
    This format should be retained until the second release after bzr 1.7.
3046
2898
 
3047
2899
    1.6.1-subtree[as it might have been] with B+Tree indices.
 
2900
 
 
2901
    This is [now] retained until we have a CHK based subtree format in
 
2902
    development.
3048
2903
    """
3049
2904
 
3050
2905
    repository_class = KnitPackRepository
3051
2906
    _commit_builder_class = PackRootCommitBuilder
3052
2907
    rich_root_data = True
 
2908
    experimental = True
3053
2909
    supports_tree_reference = True
3054
2910
    supports_external_lookups = True
3055
2911
    # What index classes to use
3056
 
    index_builder_class = BTreeBuilder
3057
 
    index_class = BTreeGraphIndex
 
2912
    index_builder_class = btree_index.BTreeBuilder
 
2913
    index_class = btree_index.BTreeGraphIndex
3058
2914
 
3059
2915
    @property
3060
2916
    def _serializer(self):
3062
2918
 
3063
2919
    def _get_matching_bzrdir(self):
3064
2920
        return bzrdir.format_registry.make_bzrdir(
3065
 
            'development2-subtree')
 
2921
            'development-subtree')
3066
2922
 
3067
2923
    def _ignore_setting_bzrdir(self, format):
3068
2924
        pass
3069
2925
 
3070
2926
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
3071
2927
 
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
2928
    def get_format_string(self):
3081
2929
        """See RepositoryFormat.get_format_string()."""
3082
2930
        return ("Bazaar development format 2 with subtree support "
3087
2935
        return ("Development repository format, currently the same as "
3088
2936
            "1.6.1-subtree with B+Tree indices.\n")
3089
2937
 
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