/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Andrew Bennetts
  • Date: 2007-09-14 02:43:00 UTC
  • mto: (2814.9.2 0.91-integration)
  • mto: This revision was merged to the branch mainline in revision 2881.
  • Revision ID: andrew.bennetts@canonical.com-20070914024300-om8lbs7nag4n44u4
Make the fallback a little tidier.

Show diffs side-by-side

added added

removed removed

Lines of Context:
500
500
        return self._real_repository.break_lock()
501
501
 
502
502
    def _get_tarball(self, compression):
503
 
        """Return a TemporaryFile containing a repository tarball"""
 
503
        """Return a TemporaryFile containing a repository tarball.
 
504
        
 
505
        Returns None if the server does not support sending tarballs.
 
506
        """
504
507
        import tempfile
505
508
        path = self.bzrdir._path_for_remote_call(self._client)
506
509
        response, protocol = self._client.call_expecting_body(
517
520
              response == ('error', "Generic bzr smart protocol error: "
518
521
                "bad request u'Repository.tarball'")):
519
522
            protocol.cancel_read_body()
 
523
            return None
520
524
        raise errors.UnexpectedSmartServerResponse(response)
521
525
 
522
526
    def sprout(self, to_bzrdir, revision_id=None):
523
527
        # TODO: Option to control what format is created?
524
 
        to_repo = to_bzrdir.create_repository()
525
 
        try:
526
 
            self._copy_repository_tarball(to_repo, revision_id)
527
 
        except errors.UnexpectedSmartServerResponse:
528
 
            to_bzrdir.get_repository_transport(None).delete_tree('.')
 
528
        to_repo = self._copy_repository_tarball(to_bzrdir, revision_id)
 
529
        if to_repo is None:
529
530
            self._ensure_real()
530
531
            return self._real_repository.sprout(
531
532
                to_bzrdir, revision_id=revision_id)
532
 
        return to_repo
 
533
        else:
 
534
            return to_repo
533
535
 
534
536
    ### These methods are just thin shims to the VFS object for now.
535
537
 
685
687
        return self._real_repository.copy_content_into(
686
688
            destination, revision_id=revision_id)
687
689
 
688
 
    def _copy_repository_tarball(self, destination, revision_id=None):
 
690
    def _copy_repository_tarball(self, to_bzrdir, revision_id=None):
689
691
        # get a tarball of the remote repository, and copy from that into the
690
692
        # destination
691
693
        from bzrlib import osutils
695
697
        # TODO: Maybe a progress bar while streaming the tarball?
696
698
        note("Copying repository content as tarball...")
697
699
        tar_file = self._get_tarball('bz2')
 
700
        if tar_file is None:
 
701
            return None
 
702
        destination = to_bzrdir.create_repository()
698
703
        try:
699
704
            tar = tarfile.open('repository', fileobj=tar_file,
700
705
                mode='r|bz2')
708
713
                osutils.rmtree(tmpdir)
709
714
        finally:
710
715
            tar_file.close()
711
 
        # TODO: if the server doesn't support this operation, maybe do it the
712
 
        # slow way using the _real_repository?
713
 
        #
 
716
        return destination
714
717
        # TODO: Suggestion from john: using external tar is much faster than
715
718
        # python's tarfile library, but it may not work on windows.
716
719