1689
1655
self.repo._text_knit = None
1692
class KnitPackRevisionStore(KnitRevisionStore):
1693
"""An object to adapt access from RevisionStore's to use KnitPacks.
1695
This class works by replacing the original RevisionStore.
1696
We need to do this because the KnitPackRevisionStore is less
1697
isolated in its layering - it uses services from the repo.
1700
def __init__(self, repo, transport, revisionstore):
1701
"""Create a KnitPackRevisionStore on repo with revisionstore.
1703
This will store its state in the Repository, use the
1704
indices to provide a KnitGraphIndex,
1705
and at the end of transactions write new indices.
1707
KnitRevisionStore.__init__(self, revisionstore.versioned_file_store)
1709
self._serializer = revisionstore._serializer
1710
self.transport = transport
1712
def get_revision_file(self, transaction):
1713
"""Get the revision versioned file object."""
1714
if getattr(self.repo, '_revision_knit', None) is not None:
1715
return self.repo._revision_knit
1716
self.repo._pack_collection.ensure_loaded()
1717
add_callback = self.repo._pack_collection.revision_index.add_callback
1718
# setup knit specific objects
1719
knit_index = KnitGraphIndex(
1720
self.repo._pack_collection.revision_index.combined_index,
1721
add_callback=add_callback)
1722
self.repo._revision_knit = knit.KnitVersionedFile(
1723
'revisions', self.transport.clone('..'),
1724
self.repo.bzrdir._get_file_mode(),
1726
index=knit_index, delta=False, factory=knit.KnitPlainFactory(),
1727
access_method=self.repo._pack_collection.revision_index.knit_access)
1728
return self.repo._revision_knit
1730
def get_signature_file(self, transaction):
1731
"""Get the signature versioned file object."""
1732
if getattr(self.repo, '_signature_knit', None) is not None:
1733
return self.repo._signature_knit
1734
self.repo._pack_collection.ensure_loaded()
1735
add_callback = self.repo._pack_collection.signature_index.add_callback
1736
# setup knit specific objects
1737
knit_index = KnitGraphIndex(
1738
self.repo._pack_collection.signature_index.combined_index,
1739
add_callback=add_callback, parents=False)
1740
self.repo._signature_knit = knit.KnitVersionedFile(
1741
'signatures', self.transport.clone('..'),
1742
self.repo.bzrdir._get_file_mode(),
1744
index=knit_index, delta=False, factory=knit.KnitPlainFactory(),
1745
access_method=self.repo._pack_collection.signature_index.knit_access)
1746
return self.repo._signature_knit
1749
class KnitPackTextStore(VersionedFileStore):
1750
"""Presents a TextStore abstraction on top of packs.
1752
This class works by replacing the original VersionedFileStore.
1753
We need to do this because the KnitPackRevisionStore is less
1754
isolated in its layering - it uses services from the repo and shares them
1755
with all the data written in a single write group.
1758
def __init__(self, repo, transport, weavestore):
1759
"""Create a KnitPackTextStore on repo with weavestore.
1761
This will store its state in the Repository, use the
1762
indices FileNames to provide a KnitGraphIndex,
1763
and at the end of transactions write new indices.
1765
# don't call base class constructor - it's not suitable.
1766
# no transient data stored in the transaction
1768
self._precious = False
1770
self.transport = transport
1771
self.weavestore = weavestore
1772
# XXX for check() which isn't updated yet
1773
self._transport = weavestore._transport
1775
def get_weave_or_empty(self, file_id, transaction):
1776
"""Get a 'Knit' backed by the .tix indices.
1778
The transaction parameter is ignored.
1780
self.repo._pack_collection.ensure_loaded()
1781
add_callback = self.repo._pack_collection.text_index.add_callback
1782
# setup knit specific objects
1783
file_id_index = GraphIndexPrefixAdapter(
1784
self.repo._pack_collection.text_index.combined_index,
1785
(file_id, ), 1, add_nodes_callback=add_callback)
1786
knit_index = KnitGraphIndex(file_id_index,
1787
add_callback=file_id_index.add_nodes,
1788
deltas=True, parents=True)
1789
return knit.KnitVersionedFile('text:' + file_id,
1790
self.transport.clone('..'),
1793
access_method=self.repo._pack_collection.text_index.knit_access,
1794
factory=knit.KnitPlainFactory())
1796
get_weave = get_weave_or_empty
1799
"""Generate a list of the fileids inserted, for use by check."""
1800
self.repo._pack_collection.ensure_loaded()
1802
for index, key, value, refs in \
1803
self.repo._pack_collection.text_index.combined_index.iter_all_entries():
1808
class InventoryKnitThunk(object):
1809
"""An object to manage thunking get_inventory_weave to pack based knits."""
1811
def __init__(self, repo, transport):
1812
"""Create an InventoryKnitThunk for repo at transport.
1814
This will store its state in the Repository, use the
1815
indices FileNames to provide a KnitGraphIndex,
1816
and at the end of transactions write a new index..
1819
self.transport = transport
1821
def get_weave(self):
1822
"""Get a 'Knit' that contains inventory data."""
1823
self.repo._pack_collection.ensure_loaded()
1824
add_callback = self.repo._pack_collection.inventory_index.add_callback
1825
# setup knit specific objects
1826
knit_index = KnitGraphIndex(
1827
self.repo._pack_collection.inventory_index.combined_index,
1828
add_callback=add_callback, deltas=True, parents=True)
1829
return knit.KnitVersionedFile(
1830
'inventory', self.transport.clone('..'),
1831
self.repo.bzrdir._get_file_mode(),
1833
index=knit_index, delta=True, factory=knit.KnitPlainFactory(),
1834
access_method=self.repo._pack_collection.inventory_index.knit_access)
1837
1658
class KnitPackRepository(KnitRepository):
1838
"""Repository with knit objects stored inside pack containers."""
1840
def __init__(self, _format, a_bzrdir, control_files, _revision_store,
1841
control_store, text_store, _commit_builder_class, _serializer):
1659
"""Repository with knit objects stored inside pack containers.
1661
The layering for a KnitPackRepository is:
1663
Graph | HPSS | Repository public layer |
1664
===================================================
1665
Tuple based apis below, string based, and key based apis above
1666
---------------------------------------------------
1668
Provides .texts, .revisions etc
1669
This adapts the N-tuple keys to physical knit records which only have a
1670
single string identifier (for historical reasons), which in older formats
1671
was always the revision_id, and in the mapped code for packs is always
1672
the last element of key tuples.
1673
---------------------------------------------------
1675
A separate GraphIndex is used for each of the
1676
texts/inventories/revisions/signatures contained within each individual
1677
pack file. The GraphIndex layer works in N-tuples and is unaware of any
1679
===================================================
1683
def __init__(self, _format, a_bzrdir, control_files, _commit_builder_class,
1842
1685
KnitRepository.__init__(self, _format, a_bzrdir, control_files,
1843
_revision_store, control_store, text_store, _commit_builder_class,
1686
_commit_builder_class, _serializer)
1845
1687
index_transport = self._transport.clone('indices')
1846
self._pack_collection = RepositoryPackCollection(self,
1688
self._pack_collection = RepositoryPackCollection(self, self._transport,
1848
1689
index_transport,
1849
1690
self._transport.clone('upload'),
1850
1691
self._transport.clone('packs'))
1851
self._revision_store = KnitPackRevisionStore(self, index_transport, self._revision_store)
1852
self.weave_store = KnitPackTextStore(self, index_transport, self.weave_store)
1853
self._inv_thunk = InventoryKnitThunk(self, index_transport)
1692
self.inventories = KnitVersionedFiles(
1693
_KnitGraphIndex(self._pack_collection.inventory_index.combined_index,
1694
add_callback=self._pack_collection.inventory_index.add_callback,
1695
deltas=True, parents=True, is_locked=self.is_locked),
1696
data_access=self._pack_collection.inventory_index.data_access,
1697
max_delta_chain=200)
1698
self.revisions = KnitVersionedFiles(
1699
_KnitGraphIndex(self._pack_collection.revision_index.combined_index,
1700
add_callback=self._pack_collection.revision_index.add_callback,
1701
deltas=False, parents=True, is_locked=self.is_locked),
1702
data_access=self._pack_collection.revision_index.data_access,
1704
self.signatures = KnitVersionedFiles(
1705
_KnitGraphIndex(self._pack_collection.signature_index.combined_index,
1706
add_callback=self._pack_collection.signature_index.add_callback,
1707
deltas=False, parents=False, is_locked=self.is_locked),
1708
data_access=self._pack_collection.signature_index.data_access,
1710
self.texts = KnitVersionedFiles(
1711
_KnitGraphIndex(self._pack_collection.text_index.combined_index,
1712
add_callback=self._pack_collection.text_index.add_callback,
1713
deltas=True, parents=True, is_locked=self.is_locked),
1714
data_access=self._pack_collection.text_index.data_access,
1715
max_delta_chain=200)
1854
1716
# True when the repository object is 'write locked' (as opposed to the
1855
1717
# physical lock only taken out around changes to the pack-names list.)
1856
1718
# Another way to represent this would be a decorator around the control