1681
1647
self.repo._text_knit = None
1684
class KnitPackRevisionStore(KnitRevisionStore):
1685
"""An object to adapt access from RevisionStore's to use KnitPacks.
1687
This class works by replacing the original RevisionStore.
1688
We need to do this because the KnitPackRevisionStore is less
1689
isolated in its layering - it uses services from the repo.
1692
def __init__(self, repo, transport, revisionstore):
1693
"""Create a KnitPackRevisionStore on repo with revisionstore.
1695
This will store its state in the Repository, use the
1696
indices to provide a KnitGraphIndex,
1697
and at the end of transactions write new indices.
1699
KnitRevisionStore.__init__(self, revisionstore.versioned_file_store)
1701
self._serializer = revisionstore._serializer
1702
self.transport = transport
1704
def get_revision_file(self, transaction):
1705
"""Get the revision versioned file object."""
1706
if getattr(self.repo, '_revision_knit', None) is not None:
1707
return self.repo._revision_knit
1708
self.repo._pack_collection.ensure_loaded()
1709
add_callback = self.repo._pack_collection.revision_index.add_callback
1710
# setup knit specific objects
1711
knit_index = KnitGraphIndex(
1712
self.repo._pack_collection.revision_index.combined_index,
1713
add_callback=add_callback)
1714
self.repo._revision_knit = knit.KnitVersionedFile(
1715
'revisions', self.transport.clone('..'),
1716
self.repo.control_files._file_mode,
1718
index=knit_index, delta=False, factory=knit.KnitPlainFactory(),
1719
access_method=self.repo._pack_collection.revision_index.knit_access)
1720
return self.repo._revision_knit
1722
def get_signature_file(self, transaction):
1723
"""Get the signature versioned file object."""
1724
if getattr(self.repo, '_signature_knit', None) is not None:
1725
return self.repo._signature_knit
1726
self.repo._pack_collection.ensure_loaded()
1727
add_callback = self.repo._pack_collection.signature_index.add_callback
1728
# setup knit specific objects
1729
knit_index = KnitGraphIndex(
1730
self.repo._pack_collection.signature_index.combined_index,
1731
add_callback=add_callback, parents=False)
1732
self.repo._signature_knit = knit.KnitVersionedFile(
1733
'signatures', self.transport.clone('..'),
1734
self.repo.control_files._file_mode,
1736
index=knit_index, delta=False, factory=knit.KnitPlainFactory(),
1737
access_method=self.repo._pack_collection.signature_index.knit_access)
1738
return self.repo._signature_knit
1741
class KnitPackTextStore(VersionedFileStore):
1742
"""Presents a TextStore abstraction on top of packs.
1744
This class works by replacing the original VersionedFileStore.
1745
We need to do this because the KnitPackRevisionStore is less
1746
isolated in its layering - it uses services from the repo and shares them
1747
with all the data written in a single write group.
1750
def __init__(self, repo, transport, weavestore):
1751
"""Create a KnitPackTextStore on repo with weavestore.
1753
This will store its state in the Repository, use the
1754
indices FileNames to provide a KnitGraphIndex,
1755
and at the end of transactions write new indices.
1757
# don't call base class constructor - it's not suitable.
1758
# no transient data stored in the transaction
1760
self._precious = False
1762
self.transport = transport
1763
self.weavestore = weavestore
1764
# XXX for check() which isn't updated yet
1765
self._transport = weavestore._transport
1767
def get_weave_or_empty(self, file_id, transaction):
1768
"""Get a 'Knit' backed by the .tix indices.
1770
The transaction parameter is ignored.
1772
self.repo._pack_collection.ensure_loaded()
1773
add_callback = self.repo._pack_collection.text_index.add_callback
1774
# setup knit specific objects
1775
file_id_index = GraphIndexPrefixAdapter(
1776
self.repo._pack_collection.text_index.combined_index,
1777
(file_id, ), 1, add_nodes_callback=add_callback)
1778
knit_index = KnitGraphIndex(file_id_index,
1779
add_callback=file_id_index.add_nodes,
1780
deltas=True, parents=True)
1781
return knit.KnitVersionedFile('text:' + file_id,
1782
self.transport.clone('..'),
1785
access_method=self.repo._pack_collection.text_index.knit_access,
1786
factory=knit.KnitPlainFactory())
1788
get_weave = get_weave_or_empty
1791
"""Generate a list of the fileids inserted, for use by check."""
1792
self.repo._pack_collection.ensure_loaded()
1794
for index, key, value, refs in \
1795
self.repo._pack_collection.text_index.combined_index.iter_all_entries():
1800
class InventoryKnitThunk(object):
1801
"""An object to manage thunking get_inventory_weave to pack based knits."""
1803
def __init__(self, repo, transport):
1804
"""Create an InventoryKnitThunk for repo at transport.
1806
This will store its state in the Repository, use the
1807
indices FileNames to provide a KnitGraphIndex,
1808
and at the end of transactions write a new index..
1811
self.transport = transport
1813
def get_weave(self):
1814
"""Get a 'Knit' that contains inventory data."""
1815
self.repo._pack_collection.ensure_loaded()
1816
add_callback = self.repo._pack_collection.inventory_index.add_callback
1817
# setup knit specific objects
1818
knit_index = KnitGraphIndex(
1819
self.repo._pack_collection.inventory_index.combined_index,
1820
add_callback=add_callback, deltas=True, parents=True)
1821
return knit.KnitVersionedFile(
1822
'inventory', self.transport.clone('..'),
1823
self.repo.control_files._file_mode,
1825
index=knit_index, delta=True, factory=knit.KnitPlainFactory(),
1826
access_method=self.repo._pack_collection.inventory_index.knit_access)
1829
1650
class KnitPackRepository(KnitRepository):
1830
1651
"""Experimental graph-knit using repository."""
1832
def __init__(self, _format, a_bzrdir, control_files, _revision_store,
1833
control_store, text_store, _commit_builder_class, _serializer):
1834
KnitRepository.__init__(self, _format, a_bzrdir, control_files,
1835
_revision_store, control_store, text_store, _commit_builder_class,
1653
def __init__(self, _format, a_bzrdir, control_files, _commit_builder_class,
1837
1655
index_transport = control_files._transport.clone('indices')
1838
1656
self._pack_collection = RepositoryPackCollection(self, control_files._transport,
1839
1657
index_transport,
1840
1658
control_files._transport.clone('upload'),
1841
1659
control_files._transport.clone('packs'))
1842
self._revision_store = KnitPackRevisionStore(self, index_transport, self._revision_store)
1843
self.weave_store = KnitPackTextStore(self, index_transport, self.weave_store)
1844
self._inv_thunk = InventoryKnitThunk(self, index_transport)
1660
KnitRepository.__init__(self, _format, a_bzrdir, control_files,
1661
_commit_builder_class, _serializer)
1662
self.inventories = KnitVersionedFiles(
1663
_KnitGraphIndex(self._pack_collection.inventory_index.combined_index,
1664
add_callback=self._pack_collection.inventory_index.add_callback,
1665
deltas=True, parents=True, is_locked=self.is_locked),
1666
data_access=self._pack_collection.inventory_index.data_access,
1667
max_delta_chain=200)
1668
self.revisions = KnitVersionedFiles(
1669
_KnitGraphIndex(self._pack_collection.revision_index.combined_index,
1670
add_callback=self._pack_collection.revision_index.add_callback,
1671
deltas=False, parents=True, is_locked=self.is_locked),
1672
data_access=self._pack_collection.revision_index.data_access,
1674
self.signatures = KnitVersionedFiles(
1675
_KnitGraphIndex(self._pack_collection.signature_index.combined_index,
1676
add_callback=self._pack_collection.signature_index.add_callback,
1677
deltas=False, parents=False, is_locked=self.is_locked),
1678
data_access=self._pack_collection.signature_index.data_access,
1680
self.texts = KnitVersionedFiles(
1681
_KnitGraphIndex(self._pack_collection.text_index.combined_index,
1682
add_callback=self._pack_collection.text_index.add_callback,
1683
deltas=True, parents=True, is_locked=self.is_locked),
1684
data_access=self._pack_collection.text_index.data_access,
1685
max_delta_chain=200)
1845
1686
# True when the repository object is 'write locked' (as opposed to the
1846
1687
# physical lock only taken out around changes to the pack-names list.)
1847
1688
# Another way to represent this would be a decorator around the control