/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: Martin Pool
  • Date: 2007-10-08 07:29:57 UTC
  • mfrom: (2894 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2895.
  • Revision ID: mbp@sourcefrog.net-20071008072957-uhm1gl1mqcsdc377
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
259
259
        self._leave_lock = False
260
260
        # for tests
261
261
        self._reconcile_does_inventory_gc = True
 
262
        self.base = self.bzrdir.transport.base
 
263
 
 
264
    def __str__(self):
 
265
        return "%s(%s)" % (self.__class__.__name__, self.base)
 
266
 
 
267
    __repr__ = __str__
262
268
 
263
269
    def abort_write_group(self):
264
270
        """Complete a write group on the decorated repository.
505
511
        return self._real_repository.break_lock()
506
512
 
507
513
    def _get_tarball(self, compression):
508
 
        """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
        """
509
518
        import tempfile
510
519
        path = self.bzrdir._path_for_remote_call(self._client)
511
520
        response, protocol = self._client.call_expecting_body(
512
521
            'Repository.tarball', path, compression)
513
 
        assert response[0] in ('ok', 'failure'), \
514
 
            'unexpected response code %s' % (response,)
515
522
        if response[0] == 'ok':
516
523
            # Extract the tarball and return it
517
524
            t = tempfile.NamedTemporaryFile()
519
526
            t.write(protocol.read_body_bytes())
520
527
            t.seek(0)
521
528
            return t
522
 
        else:
523
 
            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)
524
536
 
525
537
    def sprout(self, to_bzrdir, revision_id=None):
526
538
        # TODO: Option to control what format is created?
527
 
        to_repo = to_bzrdir.create_repository()
528
 
        self._copy_repository_tarball(to_repo, revision_id)
529
 
        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
530
546
 
531
547
    ### These methods are just thin shims to the VFS object for now.
532
548
 
591
607
        return False
592
608
 
593
609
    def fetch(self, source, revision_id=None, pb=None):
 
610
        if self.has_same_location(source):
 
611
            # check that last_revision is in 'from' and then return a
 
612
            # no-operation.
 
613
            if (revision_id is not None and
 
614
                not _mod_revision.is_null(revision_id)):
 
615
                self.get_revision(revision_id)
 
616
            return 0, []
594
617
        self._ensure_real()
595
618
        return self._real_repository.fetch(
596
619
            source, revision_id=revision_id, pb=pb)
682
705
        return self._real_repository.copy_content_into(
683
706
            destination, revision_id=revision_id)
684
707
 
685
 
    def _copy_repository_tarball(self, destination, revision_id=None):
 
708
    def _copy_repository_tarball(self, to_bzrdir, revision_id=None):
686
709
        # get a tarball of the remote repository, and copy from that into the
687
710
        # destination
688
711
        from bzrlib import osutils
692
715
        # TODO: Maybe a progress bar while streaming the tarball?
693
716
        note("Copying repository content as tarball...")
694
717
        tar_file = self._get_tarball('bz2')
 
718
        if tar_file is None:
 
719
            return None
 
720
        destination = to_bzrdir.create_repository()
695
721
        try:
696
722
            tar = tarfile.open('repository', fileobj=tar_file,
697
723
                mode='r|bz2')
705
731
                osutils.rmtree(tmpdir)
706
732
        finally:
707
733
            tar_file.close()
708
 
        # TODO: if the server doesn't support this operation, maybe do it the
709
 
        # slow way using the _real_repository?
710
 
        #
 
734
        return destination
711
735
        # TODO: Suggestion from john: using external tar is much faster than
712
736
        # python's tarfile library, but it may not work on windows.
713
737