59
59
'bzrlib.knit', 'FTAnnotatedToUnannotated')
60
60
adapter_registry.register_lazy(('knit-annotated-ft-gz', 'fulltext'),
61
61
'bzrlib.knit', 'FTAnnotatedToFullText')
62
# adapter_registry.register_lazy(('knit-annotated-ft-gz', 'chunked'),
63
# 'bzrlib.knit', 'FTAnnotatedToChunked')
64
66
class ContentFactory(object):
84
86
self.parents = None
89
class ChunkedContentFactory(ContentFactory):
90
"""Static data content factory.
92
This takes a 'chunked' list of strings. The only requirement on 'chunked' is
93
that ''.join(lines) becomes a valid fulltext. A tuple of a single string
94
satisfies this, as does a list of lines.
96
:ivar sha1: None, or the sha1 of the content fulltext.
97
:ivar storage_kind: The native storage kind of this factory. Always
99
:ivar key: The key of this content. Each key is a tuple with a single
101
:ivar parents: A tuple of parent keys for self.key. If the object has
102
no parent information, None (as opposed to () for an empty list of
106
def __init__(self, key, parents, sha1, chunks):
107
"""Create a ContentFactory."""
109
self.storage_kind = 'chunked'
111
self.parents = parents
112
self._chunks = chunks
114
def get_bytes_as(self, storage_kind):
115
if storage_kind == 'chunked':
117
elif storage_kind == 'fulltext':
118
return ''.join(self._chunks)
119
raise errors.UnavailableRepresentation(self.key, storage_kind,
87
123
class FulltextContentFactory(ContentFactory):
88
124
"""Static data content factory.
90
126
This takes a fulltext when created and just returns that during
91
127
get_bytes_as('fulltext').
93
129
:ivar sha1: None, or the sha1 of the content fulltext.
94
130
:ivar storage_kind: The native storage kind of this factory. Always
111
147
def get_bytes_as(self, storage_kind):
112
148
if storage_kind == self.storage_kind:
113
149
return self._text
150
elif storage_kind == 'chunked':
114
152
raise errors.UnavailableRepresentation(self.key, storage_kind,
115
153
self.storage_kind)
804
842
if not mpvf.has_version(p))
805
843
# It seems likely that adding all the present parents as fulltexts can
806
844
# easily exhaust memory.
807
split_lines = osutils.split_lines
845
chunks_to_lines = osutils.chunks_to_lines
808
846
for record in self.get_record_stream(needed_parents, 'unordered',
810
848
if record.storage_kind == 'absent':
812
mpvf.add_version(split_lines(record.get_bytes_as('fulltext')),
850
mpvf.add_version(chunks_to_lines(record.get_bytes_as('chunked')),
814
852
for (key, parent_keys, expected_sha1, mpdiff), lines in\
815
853
zip(records, mpvf.get_line_list(versions)):
940
978
ghosts = maybe_ghosts - set(self.get_parent_map(maybe_ghosts))
941
979
knit_keys.difference_update(ghosts)
943
split_lines = osutils.split_lines
981
chunks_to_lines = osutils.chunks_to_lines
944
982
for record in self.get_record_stream(knit_keys, 'topological', True):
945
lines[record.key] = split_lines(record.get_bytes_as('fulltext'))
983
lines[record.key] = chunks_to_lines(record.get_bytes_as('chunked'))
946
984
# line_block_dict = {}
947
985
# for parent, blocks in record.extract_line_blocks():
948
986
# line_blocks[parent] = blocks
1251
1289
lines = self._lines[key]
1252
1290
parents = self._parents[key]
1253
1291
pending.remove(key)
1254
yield FulltextContentFactory(key, parents, None,
1292
yield ChunkedContentFactory(key, parents, None, lines)
1256
1293
for versionedfile in self.fallback_versionedfiles:
1257
1294
for record in versionedfile.get_record_stream(
1258
1295
pending, 'unordered', True):
1422
1459
if lines is not None:
1423
1460
if not isinstance(lines, list):
1424
1461
raise AssertionError
1425
yield FulltextContentFactory((k,), None,
1462
yield ChunkedContentFactory((k,), None,
1426
1463
sha1=osutils.sha_strings(lines),
1427
text=''.join(lines))
1429
1466
yield AbsentContentFactory((k,))