~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: Martin
  • Date: 2010-05-16 15:18:43 UTC
  • mfrom: (5235 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5239.
  • Revision ID: gzlist@googlemail.com-20100516151843-lu53u7caehm3ie3i
Merge bzr.dev to resolve conflicts in NEWS and _chk_map_pyx

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