~ubuntu-branches/ubuntu/karmic/bzr/karmic-proposed

« back to all changes in this revision

Viewing changes to bzrlib/smart/repository.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2008-08-25 19:06:49 UTC
  • mfrom: (1.1.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20080825190649-pq87jonr4uvs7s0y
Tags: 1.6-1
New upstream release.

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
        """
350
349
 
351
350
    def do_repository_request(self, repository, compression):
352
351
        from bzrlib import osutils
353
 
        repo_transport = repository.control_files._transport
354
352
        tmp_dirname, tmp_repo = self._copy_to_tempdir(repository)
355
353
        try:
356
354
            controldir_name = tmp_dirname + '/.bzr'
394
392
            tarball.add(dirname, '.bzr') # recursive by default
395
393
        finally:
396
394
            tarball.close()
397
 
 
398
 
 
399
 
class SmartServerRepositoryStreamKnitDataForRevisions(SmartServerRepositoryRequest):
400
 
    """Bzr <= 1.1 streaming pull, buffers all data on server."""
401
 
 
402
 
    def do_repository_request(self, repository, *revision_ids):
403
 
        repository.lock_read()
404
 
        try:
405
 
            return self._do_repository_request(repository, revision_ids)
406
 
        finally:
407
 
            repository.unlock()
408
 
 
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)))
412
 
        buffer = StringIO()
413
 
        pack = ContainerSerialiser()
414
 
        buffer.write(pack.begin())
415
 
        try:
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())
422
 
 
423
 
 
424
 
class SmartServerRepositoryStreamRevisionsChunked(SmartServerRepositoryRequest):
425
 
    """Bzr 1.1+ streaming pull."""
426
 
 
427
 
    def do_body(self, body_bytes):
428
 
        repository = self._repository
429
 
        repository.lock_read()
430
 
        try:
431
 
            search, error = self.recreate_search(repository, body_bytes)
432
 
            if error is not None:
433
 
                repository.unlock()
434
 
                return error
435
 
            stream = repository.get_data_stream_for_search(search.get_result())
436
 
        except Exception:
437
 
            # On non-error, unlocking is done by the body stream handler.
438
 
            repository.unlock()
439
 
            raise
440
 
        return SuccessfulSmartServerResponse(('ok',),
441
 
            body_stream=self.body_stream(stream, repository))
442
 
 
443
 
    def body_stream(self, stream, repository):
444
 
        pack = ContainerSerialiser()
445
 
        yield pack.begin()
446
 
        try:
447
 
            try:
448
 
                for name_tuple, bytes in stream:
449
 
                    yield pack.bytes_record(bytes, [name_tuple])
450
 
            except:
451
 
                # Undo the lock_read that that happens once the iterator from
452
 
                # get_data_stream is started.
453
 
                repository.unlock()
454
 
                raise
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.
458
 
            repository.unlock()
459
 
            yield FailedSmartServerResponse(('NoSuchRevision', e.revision_id))
460
 
        else:
461
 
            repository.unlock()
462
 
            pack.end()
463