339
339
:param sha1: TODO (should we validate only when sha1 is supplied?)
340
340
:return: The bytes for the content
342
# Handle the 'Empty Content' record, even if we don't always write it
344
342
if start == end == 0:
346
344
self._ensure_content(end)
498
497
if storage_kind in ('fulltext', 'chunked'):
499
self._manager._prepare_for_extract()
500
block = self._manager._block
501
bytes = block.extract(self.key, self._start, self._end)
498
if self._bytes is None:
499
# Grab and cache the raw bytes for this entry
500
# and break the ref-cycle with _manager since we don't need it
502
self._manager._prepare_for_extract()
503
block = self._manager._block
504
self._bytes = block.extract(self.key, self._start, self._end)
502
506
if storage_kind == 'fulltext':
506
510
raise errors.UnavailableRepresentation(self.key, storage_kind,
510
514
class _LazyGroupContentManager(object):
1281
1288
for key in missing:
1282
1289
yield AbsentContentFactory(key)
1291
last_read_memo = None
1284
1292
# TODO: This works fairly well at batching up existing groups into a
1285
1293
# streamable format, and possibly allowing for taking one big
1286
1294
# group and splitting it when it isn't fully utilized.
1295
1303
for key in keys:
1296
1304
if key in self._unadded_refs:
1297
1305
if manager is not None:
1298
# Yield everything buffered so far
1299
1306
for factory in manager.get_record_stream():
1308
last_read_memo = manager = None
1302
1309
bytes, sha1 = self._compressor.extract(key)
1303
1310
parents = self._unadded_refs[key]
1304
1311
yield FulltextContentFactory(key, parents, sha1, bytes)
1306
1313
index_memo, _, parents, (method, _) = locations[key]
1307
block = self._get_block(index_memo)
1314
read_memo = index_memo[0:3]
1315
if last_read_memo != read_memo:
1316
# We are starting a new block. If we have a
1317
# manager, we have found everything that fits for
1318
# now, so yield records
1319
if manager is not None:
1320
for factory in manager.get_record_stream():
1322
# Now start a new manager
1323
block = self._get_block(index_memo)
1324
manager = _LazyGroupContentManager(block)
1325
last_read_memo = read_memo
1308
1326
start, end = index_memo[3:5]
1310
manager = _LazyGroupContentManager(block)
1311
elif manager._block is not block:
1312
# Flush and create a new manager
1313
for factory in manager.get_record_stream():
1315
manager = _LazyGroupContentManager(block)
1316
1327
manager.add_factory(key, parents, start, end)
1318
1329
if manager is not None:
1319
# Yield everything buffered so far
1320
1330
for factory in manager.get_record_stream():
1332
last_read_memo = manager = None
1323
1333
for record in source.get_record_stream(keys, ordering,
1324
1334
include_delta_closure):
1326
1336
if manager is not None:
1327
# Yield everything buffered so far
1328
1337
for factory in manager.get_record_stream():
1332
1340
def get_sha1s(self, keys):
1333
1341
"""See VersionedFiles.get_sha1s()."""