394
393
tarball.add(dirname, '.bzr') # recursive by default
399
class SmartServerRepositoryStreamKnitDataForRevisions(SmartServerRepositoryRequest):
400
"""Bzr <= 1.1 streaming pull, buffers all data on server."""
402
def do_repository_request(self, repository, *revision_ids):
403
repository.lock_read()
405
return self._do_repository_request(repository, revision_ids)
409
def _do_repository_request(self, repository, revision_ids):
410
stream = repository.get_data_stream_for_search(
411
repository.revision_ids_to_search_result(set(revision_ids)))
413
pack = ContainerSerialiser()
414
buffer.write(pack.begin())
416
for name_tuple, bytes in stream:
417
buffer.write(pack.bytes_record(bytes, [name_tuple]))
418
except errors.RevisionNotPresent, e:
419
return FailedSmartServerResponse(('NoSuchRevision', e.revision_id))
420
buffer.write(pack.end())
421
return SuccessfulSmartServerResponse(('ok',), buffer.getvalue())
424
class SmartServerRepositoryStreamRevisionsChunked(SmartServerRepositoryRequest):
425
"""Bzr 1.1+ streaming pull."""
427
def do_body(self, body_bytes):
428
repository = self._repository
429
repository.lock_read()
431
search, error = self.recreate_search(repository, body_bytes)
432
if error is not None:
435
stream = repository.get_data_stream_for_search(search.get_result())
437
# On non-error, unlocking is done by the body stream handler.
440
return SuccessfulSmartServerResponse(('ok',),
441
body_stream=self.body_stream(stream, repository))
443
def body_stream(self, stream, repository):
444
pack = ContainerSerialiser()
448
for name_tuple, bytes in stream:
449
yield pack.bytes_record(bytes, [name_tuple])
451
# Undo the lock_read that that happens once the iterator from
452
# get_data_stream is started.
455
except errors.RevisionNotPresent, e:
456
# This shouldn't be able to happen, but as we don't buffer
457
# everything it can in theory happen.
459
yield FailedSmartServerResponse(('NoSuchRevision', e.revision_id))