82
81
recreate_search trusts that clients will look for missing things
83
82
they expected and get it from elsewhere.
84
if search_bytes == 'everything':
85
return graph.EverythingResult(repository), None
85
86
lines = search_bytes.split('\n')
86
87
if lines[0] == 'ancestry-of':
395
token = repository.lock_write(token=token)
396
token = repository.lock_write(token=token).repository_token
396
397
except errors.LockContention, e:
397
398
return FailedSmartServerResponse(('LockContention',))
398
399
except errors.UnlockableTransport:
413
414
def do_repository_request(self, repository, to_network_name):
414
415
"""Get a stream for inserting into a to_format repository.
417
The request body is 'search_bytes', a description of the revisions
420
In 2.3 this verb added support for search_bytes == 'everything'. Older
421
implementations will respond with a BadSearch error, and clients should
422
catch this and fallback appropriately.
416
424
:param repository: The repository to stream from.
417
425
:param to_network_name: The network name of the format of the target
492
500
class SmartServerRepositoryGetStream_1_19(SmartServerRepositoryGetStream):
501
"""The same as Repository.get_stream, but will return stream CHK formats to
504
See SmartServerRepositoryGetStream._should_fake_unknown.
494
509
def _should_fake_unknown(self):
495
510
"""Returns False; we don't need to workaround bugs in 1.19+ clients."""
505
520
for record in substream:
506
521
if record.storage_kind in ('chunked', 'fulltext'):
507
522
serialised = record_to_fulltext_bytes(record)
508
elif record.storage_kind == 'inventory-delta':
509
serialised = record_to_inventory_delta_bytes(record)
510
523
elif record.storage_kind == 'absent':
511
524
raise ValueError("Absent factory for %s" % (record.key,))
544
557
:ivar first_bytes: The first bytes to give the next NetworkRecordStream.
547
def __init__(self, byte_stream):
560
def __init__(self, byte_stream, record_counter):
548
561
"""Create a _ByteStreamDecoder."""
549
562
self.stream_decoder = pack.ContainerPushParser()
550
563
self.current_type = None
551
564
self.first_bytes = None
552
565
self.byte_stream = byte_stream
566
self._record_counter = record_counter
554
569
def iter_stream_decoder(self):
555
570
"""Iterate the contents of the pack from stream_decoder."""
581
596
def record_stream(self):
582
597
"""Yield substream_type, substream from the byte stream."""
598
def wrap_and_count(pb, rc, substream):
599
"""Yield records from stream while showing progress."""
602
if self.current_type != 'revisions' and self.key_count != 0:
603
# As we know the number of revisions now (in self.key_count)
604
# we can setup and use record_counter (rc).
605
if not rc.is_initialized():
606
rc.setup(self.key_count, self.key_count)
607
for record in substream.read():
609
if rc.is_initialized() and counter == rc.STEP:
610
rc.increment(counter)
611
pb.update('Estimate', rc.current, rc.max)
613
if self.current_type == 'revisions':
614
# Total records is proportional to number of revs
615
# to fetch. With remote, we used self.key_count to
616
# track the number of revs. Once we have the revs
617
# counts in self.key_count, the progress bar changes
618
# from 'Estimating..' to 'Estimate' above.
620
if counter == rc.STEP:
621
pb.update('Estimating..', self.key_count)
583
626
self.seed_state()
627
pb = ui.ui_factory.nested_progress_bar()
628
rc = self._record_counter
584
629
# Make and consume sub generators, one per substream type:
585
630
while self.first_bytes is not None:
586
631
substream = NetworkRecordStream(self.iter_substream_bytes())
587
632
# after substream is fully consumed, self.current_type is set to
588
633
# the next type, and self.first_bytes is set to the matching bytes.
589
yield self.current_type, substream.read()
634
yield self.current_type, wrap_and_count(pb, rc, substream)
636
pb.update('Done', rc.max, rc.max)
591
639
def seed_state(self):
592
640
"""Prepare the _ByteStreamDecoder to decode from the pack stream."""
597
645
list(self.iter_substream_bytes())
600
def _byte_stream_to_stream(byte_stream):
648
def _byte_stream_to_stream(byte_stream, record_counter=None):
601
649
"""Convert a byte stream into a format and a stream.
603
651
:param byte_stream: A bytes iterator, as output by _stream_to_byte_stream.
604
652
:return: (RepositoryFormat, stream_generator)
606
decoder = _ByteStreamDecoder(byte_stream)
654
decoder = _ByteStreamDecoder(byte_stream, record_counter)
607
655
for bytes in byte_stream:
608
656
decoder.stream_decoder.accept_bytes(bytes)
609
657
for record in decoder.stream_decoder.read_pending_records(max=1):