~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/repository.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-06-25 10:36:36 UTC
  • mfrom: (3350.6.12 versionedfiles)
  • Revision ID: pqm@pqm.ubuntu.com-20080625103636-6kxh4e1gmyn82f50
(mbp for robertc) VersionedFiles refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
257
257
              firstrev: 1234.230 0
258
258
              latestrev: 345.700 3600
259
259
              revisions: 2
260
 
              size:45
261
260
 
262
261
              But containing only fields returned by the gather_stats() call
263
262
        """
393
392
            tarball.add(dirname, '.bzr') # recursive by default
394
393
        finally:
395
394
            tarball.close()
396
 
 
397
 
 
398
 
class SmartServerRepositoryStreamKnitDataForRevisions(SmartServerRepositoryRequest):
399
 
    """Bzr <= 1.1 streaming pull, buffers all data on server."""
400
 
 
401
 
    def do_repository_request(self, repository, *revision_ids):
402
 
        repository.lock_read()
403
 
        try:
404
 
            return self._do_repository_request(repository, revision_ids)
405
 
        finally:
406
 
            repository.unlock()
407
 
 
408
 
    def _do_repository_request(self, repository, revision_ids):
409
 
        stream = repository.get_data_stream_for_search(
410
 
            repository.revision_ids_to_search_result(set(revision_ids)))
411
 
        buffer = StringIO()
412
 
        pack = ContainerSerialiser()
413
 
        buffer.write(pack.begin())
414
 
        try:
415
 
            for name_tuple, bytes in stream:
416
 
                buffer.write(pack.bytes_record(bytes, [name_tuple]))
417
 
        except errors.RevisionNotPresent, e:
418
 
            return FailedSmartServerResponse(('NoSuchRevision', e.revision_id))
419
 
        buffer.write(pack.end())
420
 
        return SuccessfulSmartServerResponse(('ok',), buffer.getvalue())
421
 
 
422
 
 
423
 
class SmartServerRepositoryStreamRevisionsChunked(SmartServerRepositoryRequest):
424
 
    """Bzr 1.1+ streaming pull."""
425
 
 
426
 
    def do_body(self, body_bytes):
427
 
        repository = self._repository
428
 
        repository.lock_read()
429
 
        try:
430
 
            search, error = self.recreate_search(repository, body_bytes)
431
 
            if error is not None:
432
 
                repository.unlock()
433
 
                return error
434
 
            stream = repository.get_data_stream_for_search(search.get_result())
435
 
        except Exception:
436
 
            # On non-error, unlocking is done by the body stream handler.
437
 
            repository.unlock()
438
 
            raise
439
 
        return SuccessfulSmartServerResponse(('ok',),
440
 
            body_stream=self.body_stream(stream, repository))
441
 
 
442
 
    def body_stream(self, stream, repository):
443
 
        pack = ContainerSerialiser()
444
 
        yield pack.begin()
445
 
        try:
446
 
            try:
447
 
                for name_tuple, bytes in stream:
448
 
                    yield pack.bytes_record(bytes, [name_tuple])
449
 
            except:
450
 
                # Undo the lock_read that that happens once the iterator from
451
 
                # get_data_stream is started.
452
 
                repository.unlock()
453
 
                raise
454
 
        except errors.RevisionNotPresent, e:
455
 
            # This shouldn't be able to happen, but as we don't buffer
456
 
            # everything it can in theory happen.
457
 
            repository.unlock()
458
 
            yield FailedSmartServerResponse(('NoSuchRevision', e.revision_id))
459
 
        else:
460
 
            repository.unlock()
461
 
            pack.end()
462