40
41
from bzrlib.graph import DictParentsProvider, Graph, _StackedParentsProvider
41
42
from bzrlib.transport.memory import MemoryTransport
43
from bzrlib.util import bencode
43
45
from bzrlib.inter import InterObject
44
46
from bzrlib.registry import Registry
1472
1474
pb.update("iterating texts", i, len(keys))
1473
1475
for l in self._get_lines(key):
1479
def network_bytes_to_kind_and_offset(network_bytes):
1480
"""Strip of a record kind from the front of network_bytes.
1482
:param network_bytes: The bytes of a record.
1483
:return: A tuple (storage_kind, offset_of_remaining_bytes)
1485
line_end = network_bytes.find('\n')
1486
storage_kind = network_bytes[:line_end]
1487
return storage_kind, line_end + 1
1490
class NetworkRecordStream(object):
1491
"""A record_stream which reconstitures a serialised stream."""
1493
def __init__(self, bytes_iterator):
1494
"""Create a NetworkRecordStream.
1496
:param bytes_iterator: An iterator of bytes. Each item in this
1497
iterator should have been obtained from a record_streams'
1498
record.get_bytes_as(record.storage_kind) call.
1500
self._bytes_iterator = bytes_iterator
1501
self._kind_factory = {'knit-ft-gz':knit.knit_network_to_record,
1502
'knit-annotated-ft-gz':knit.knit_network_to_record,
1508
:return: An iterator as per VersionedFiles.get_record_stream().
1510
for bytes in self._bytes_iterator:
1511
storage_kind, line_end = network_bytes_to_kind_and_offset(bytes)
1512
yield self._kind_factory[storage_kind](
1513
storage_kind, bytes, line_end)