875
875
This data is intended to be used for retrieving the knit records.
877
A dict of version_id to (method, data_pos, data_size, next) is
877
A dict of version_id to (method, index_memo, next) is
879
879
method is the way referenced data should be applied.
880
880
data_pos is the position of the data in the knit.
882
882
next is the build-parent of the version, or None for fulltexts.
884
884
component_data = {}
885
for version_id in version_ids:
888
while cursor is not None and cursor not in component_data:
889
method = self._index.get_method(cursor)
890
if method == 'fulltext':
893
next = self.get_parents_with_ghosts(cursor)[0]
894
index_memo = self._index.get_position(cursor)
895
component_data[cursor] = (method, index_memo, next)
885
pending_components = version_ids
886
while pending_components:
887
build_details = self._index.get_build_details(pending_components)
888
pending_components = set()
889
for version_id, details in build_details.items():
890
method, index_memo, compression_parent = details
891
if compression_parent is not None:
892
pending_components.add(compression_parent)
893
component_data[version_id] = details
897
894
return component_data
899
896
def _get_content(self, version_id, parent_texts={}):
1426
1423
graph[version] = parents
1427
1424
return topo_sort(graph.items())
1426
def get_build_details(self, version_ids):
1427
"""Get the method, index_memo and compression parent for version_ids.
1429
:param version_ids: An iterable of version_ids.
1430
:return: A dict of version_id:(method, index_memo, compression_parent).
1433
for version_id in version_ids:
1434
method = self.get_method(version_id)
1435
if method == 'fulltext':
1436
compression_parent = None
1438
compression_parent = self.get_parents_with_ghosts(version_id)[0]
1439
index_memo = self.get_position(version_id)
1440
result[version_id] = (method, index_memo, compression_parent)
1429
1443
def iter_parents(self, version_ids):
1430
1444
"""Iterate through the parents for many version ids.
1689
1703
result_keys = topo_sort(graph.items())
1690
1704
return [key[0] for key in result_keys]
1706
def get_build_details(self, version_ids):
1707
"""Get the method, index_memo and compression parent for version_ids.
1709
:param version_ids: An iterable of version_ids.
1710
:return: A dict of version_id:(method, index_memo, compression_parent).
1713
entries = self._get_entries(self._version_ids_to_keys(version_ids), True)
1714
for entry in entries:
1715
version_id = self._keys_to_version_ids((entry[1],))[0]
1716
if not self._deltas:
1717
compression_parent = None
1719
compression_parent_key = self._compression_parent(entry)
1720
if compression_parent_key:
1721
compression_parent = self._keys_to_version_ids(
1722
(compression_parent_key,))[0]
1724
compression_parent = None
1725
if compression_parent:
1726
method = 'line-delta'
1729
result[version_id] = (method, self._node_to_position(entry),
1733
def _compression_parent(self, an_entry):
1734
# return the key that an_entry is compressed against, or None
1735
# Grab the second parent list (as deltas implies parents currently)
1736
compression_parents = an_entry[3][1]
1737
if not compression_parents:
1739
assert len(compression_parents) == 1
1740
return compression_parents[0]
1742
def _get_method(self, node):
1743
if not self._deltas:
1745
if self._compression_parent(node):
1692
1750
def get_graph(self):
1693
1751
"""Return a list of the node:parents lists from this knit index."""
1694
1752
if not self._parents:
1750
1808
logic to get the record.
1752
1810
node = self._get_node(version_id)
1811
return self._node_to_position(node)
1813
def _node_to_position(self, node):
1814
"""Convert an index value to position details."""
1753
1815
bits = node[2][1:].split(' ')
1754
1816
return node[0], int(bits[0]), int(bits[1])
1756
1818
def get_method(self, version_id):
1757
1819
"""Return compression method of specified version."""
1758
if not self._deltas:
1760
return self._parent_compression(self._get_node(version_id)[3][1])
1762
def _parent_compression(self, reference_list):
1763
# use the second reference list to decide if this is delta'd or not.
1764
if len(reference_list):
1820
return self._get_method(self._get_node(version_id))
1769
1822
def _get_node(self, version_id):
2159
2209
ancestry.add(version)
2160
2210
return list(ancestry)
2212
def get_build_details(self, version_ids):
2213
"""Get the method, index_memo and compression parent for version_ids.
2215
:param version_ids: An iterable of version_ids.
2216
:return: A dict of version_id:(method, index_memo, compression_parent).
2219
for version_id in version_ids:
2220
method = self.get_method(version_id)
2221
if method == 'fulltext':
2222
compression_parent = None
2224
compression_parent = self.get_parents_with_ghosts(version_id)[0]
2225
index_memo = self.get_position(version_id)
2226
result[version_id] = (method, index_memo, compression_parent)
2162
2229
def get_method(self, version_id):
2163
2230
"""Return compression method of specified version."""