~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-10-03 23:24:50 UTC
  • mfrom: (2878.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20071003232450-c831pepea3skddct
merge 0.91 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
511
511
        return self._real_repository.break_lock()
512
512
 
513
513
    def _get_tarball(self, compression):
514
 
        """Return a TemporaryFile containing a repository tarball"""
 
514
        """Return a TemporaryFile containing a repository tarball.
 
515
        
 
516
        Returns None if the server does not support sending tarballs.
 
517
        """
515
518
        import tempfile
516
519
        path = self.bzrdir._path_for_remote_call(self._client)
517
520
        response, protocol = self._client.call_expecting_body(
518
521
            'Repository.tarball', path, compression)
519
 
        assert response[0] in ('ok', 'failure'), \
520
 
            'unexpected response code %s' % (response,)
521
522
        if response[0] == 'ok':
522
523
            # Extract the tarball and return it
523
524
            t = tempfile.NamedTemporaryFile()
525
526
            t.write(protocol.read_body_bytes())
526
527
            t.seek(0)
527
528
            return t
528
 
        else:
529
 
            raise errors.SmartServerError(error_code=response)
 
529
        if (response == ('error', "Generic bzr smart protocol error: "
 
530
                "bad request 'Repository.tarball'") or
 
531
              response == ('error', "Generic bzr smart protocol error: "
 
532
                "bad request u'Repository.tarball'")):
 
533
            protocol.cancel_read_body()
 
534
            return None
 
535
        raise errors.UnexpectedSmartServerResponse(response)
530
536
 
531
537
    def sprout(self, to_bzrdir, revision_id=None):
532
538
        # TODO: Option to control what format is created?
533
 
        to_repo = to_bzrdir.create_repository()
534
 
        self._copy_repository_tarball(to_repo, revision_id)
535
 
        return to_repo
 
539
        to_repo = self._copy_repository_tarball(to_bzrdir, revision_id)
 
540
        if to_repo is None:
 
541
            self._ensure_real()
 
542
            return self._real_repository.sprout(
 
543
                to_bzrdir, revision_id=revision_id)
 
544
        else:
 
545
            return to_repo
536
546
 
537
547
    ### These methods are just thin shims to the VFS object for now.
538
548
 
688
698
        return self._real_repository.copy_content_into(
689
699
            destination, revision_id=revision_id)
690
700
 
691
 
    def _copy_repository_tarball(self, destination, revision_id=None):
 
701
    def _copy_repository_tarball(self, to_bzrdir, revision_id=None):
692
702
        # get a tarball of the remote repository, and copy from that into the
693
703
        # destination
694
704
        from bzrlib import osutils
698
708
        # TODO: Maybe a progress bar while streaming the tarball?
699
709
        note("Copying repository content as tarball...")
700
710
        tar_file = self._get_tarball('bz2')
 
711
        if tar_file is None:
 
712
            return None
 
713
        destination = to_bzrdir.create_repository()
701
714
        try:
702
715
            tar = tarfile.open('repository', fileobj=tar_file,
703
716
                mode='r|bz2')
711
724
                osutils.rmtree(tmpdir)
712
725
        finally:
713
726
            tar_file.close()
714
 
        # TODO: if the server doesn't support this operation, maybe do it the
715
 
        # slow way using the _real_repository?
716
 
        #
 
727
        return destination
717
728
        # TODO: Suggestion from john: using external tar is much faster than
718
729
        # python's tarfile library, but it may not work on windows.
719
730