/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-10 00:21:57 UTC
  • mfrom: (2900 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2901.
  • Revision ID: mbp@sourcefrog.net-20071010002157-utci0x44m2w47wgd
merge news

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.
507
513
        return self._real_repository.break_lock()
508
514
 
509
515
    def _get_tarball(self, compression):
510
 
        """Return a TemporaryFile containing a repository tarball"""
 
516
        """Return a TemporaryFile containing a repository tarball.
 
517
        
 
518
        Returns None if the server does not support sending tarballs.
 
519
        """
511
520
        import tempfile
512
521
        path = self.bzrdir._path_for_remote_call(self._client)
513
522
        response, protocol = self._client.call_expecting_body(
514
523
            'Repository.tarball', path, compression)
515
 
        assert response[0] in ('ok', 'failure'), \
516
 
            'unexpected response code %s' % (response,)
517
524
        if response[0] == 'ok':
518
525
            # Extract the tarball and return it
519
526
            t = tempfile.NamedTemporaryFile()
521
528
            t.write(protocol.read_body_bytes())
522
529
            t.seek(0)
523
530
            return t
524
 
        else:
525
 
            raise errors.SmartServerError(error_code=response)
 
531
        if (response == ('error', "Generic bzr smart protocol error: "
 
532
                "bad request 'Repository.tarball'") or
 
533
              response == ('error', "Generic bzr smart protocol error: "
 
534
                "bad request u'Repository.tarball'")):
 
535
            protocol.cancel_read_body()
 
536
            return None
 
537
        raise errors.UnexpectedSmartServerResponse(response)
526
538
 
527
539
    def sprout(self, to_bzrdir, revision_id=None):
528
540
        # TODO: Option to control what format is created?
529
 
        to_repo = to_bzrdir.create_repository()
530
 
        self._copy_repository_tarball(to_repo, revision_id)
531
 
        return to_repo
 
541
        to_repo = self._copy_repository_tarball(to_bzrdir, revision_id)
 
542
        if to_repo is None:
 
543
            self._ensure_real()
 
544
            return self._real_repository.sprout(
 
545
                to_bzrdir, revision_id=revision_id)
 
546
        else:
 
547
            return to_repo
532
548
 
533
549
    ### These methods are just thin shims to the VFS object for now.
534
550
 
593
609
        return False
594
610
 
595
611
    def fetch(self, source, revision_id=None, pb=None):
 
612
        if self.has_same_location(source):
 
613
            # check that last_revision is in 'from' and then return a
 
614
            # no-operation.
 
615
            if (revision_id is not None and
 
616
                not _mod_revision.is_null(revision_id)):
 
617
                self.get_revision(revision_id)
 
618
            return 0, []
596
619
        self._ensure_real()
597
620
        return self._real_repository.fetch(
598
621
            source, revision_id=revision_id, pb=pb)
684
707
        return self._real_repository.copy_content_into(
685
708
            destination, revision_id=revision_id)
686
709
 
687
 
    def _copy_repository_tarball(self, destination, revision_id=None):
 
710
    def _copy_repository_tarball(self, to_bzrdir, revision_id=None):
688
711
        # get a tarball of the remote repository, and copy from that into the
689
712
        # destination
690
713
        from bzrlib import osutils
694
717
        # TODO: Maybe a progress bar while streaming the tarball?
695
718
        note("Copying repository content as tarball...")
696
719
        tar_file = self._get_tarball('bz2')
 
720
        if tar_file is None:
 
721
            return None
 
722
        destination = to_bzrdir.create_repository()
697
723
        try:
698
724
            tar = tarfile.open('repository', fileobj=tar_file,
699
725
                mode='r|bz2')
707
733
                osutils.rmtree(tmpdir)
708
734
        finally:
709
735
            tar_file.close()
710
 
        # TODO: if the server doesn't support this operation, maybe do it the
711
 
        # slow way using the _real_repository?
712
 
        #
 
736
        return destination
713
737
        # TODO: Suggestion from john: using external tar is much faster than
714
738
        # python's tarfile library, but it may not work on windows.
715
739