~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Vincent Ladeuil
  • Date: 2012-02-14 17:22:37 UTC
  • mfrom: (6466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120214172237-7dv7er3n4uy8d5m4
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
from bzrlib.repository import RepositoryWriteLockResult, _LazyListJoin
60
60
from bzrlib.serializer import format_registry as serializer_format_registry
61
61
from bzrlib.trace import mutter, note, warning, log_exception_quietly
62
 
from bzrlib.versionedfile import ChunkedContentFactory, FulltextContentFactory
 
62
from bzrlib.versionedfile import FulltextContentFactory
63
63
 
64
64
 
65
65
_DEFAULT_SEARCH_DEPTH = 100
113
113
 
114
114
    supports_workingtrees = False
115
115
 
 
116
    colocated_branches = False
 
117
 
116
118
    def __init__(self):
117
119
        _mod_bzrdir.BzrDirMetaFormat1.__init__(self)
118
120
        # XXX: It's a bit ugly that the network name is here, because we'd
625
627
 
626
628
    def create_branch(self, name=None, repository=None,
627
629
                      append_revisions_only=None):
 
630
        if name is None:
 
631
            name = self._get_selected_branch()
 
632
        if name != "":
 
633
            raise errors.NoColocatedBranchSupport(self)
628
634
        # as per meta1 formats - just delegate to the format object which may
629
635
        # be parameterised.
630
636
        real_branch = self._format.get_branch_format().initialize(self,
649
655
 
650
656
    def destroy_branch(self, name=None):
651
657
        """See BzrDir.destroy_branch"""
 
658
        if name is None:
 
659
            name = self._get_selected_branch()
 
660
        if name != "":
 
661
            raise errors.NoColocatedBranchSupport(self)
652
662
        path = self._path_for_remote_call(self._client)
653
663
        try:
654
 
            if name is not None:
 
664
            if name != "":
655
665
                args = (name, )
656
666
            else:
657
667
                args = ()
677
687
        b = self.open_branch(name=name)
678
688
        return b._format
679
689
 
 
690
    def get_branches(self, possible_transports=None, ignore_fallbacks=False):
 
691
        path = self._path_for_remote_call(self._client)
 
692
        try:
 
693
            response, handler = self._call_expecting_body(
 
694
                'BzrDir.get_branches', path)
 
695
        except errors.UnknownSmartMethod:
 
696
            self._ensure_real()
 
697
            return self._real_bzrdir.get_branches()
 
698
        if response[0] != "success":
 
699
            raise errors.UnexpectedSmartServerResponse(response)
 
700
        body = bencode.bdecode(handler.read_body_bytes())
 
701
        ret = {}
 
702
        for (name, value) in body.iteritems():
 
703
            ret[name] = self._open_branch(name, value[0], value[1],
 
704
                possible_transports=possible_transports,
 
705
                ignore_fallbacks=ignore_fallbacks)
 
706
        return ret
 
707
 
 
708
    def set_branch_reference(self, target_branch, name=None):
 
709
        """See BzrDir.set_branch_reference()."""
 
710
        if name is None:
 
711
            name = self._get_selected_branch()
 
712
        if name != "":
 
713
            raise errors.NoColocatedBranchSupport(self)
 
714
        self._ensure_real()
 
715
        return self._real_bzrdir.set_branch_reference(target_branch, name=name)
 
716
 
680
717
    def get_branch_reference(self, name=None):
681
718
        """See BzrDir.get_branch_reference()."""
682
 
        if name is not None:
683
 
            # XXX JRV20100304: Support opening colocated branches
 
719
        if name is None:
 
720
            name = self._get_selected_branch()
 
721
        if name != "":
684
722
            raise errors.NoColocatedBranchSupport(self)
685
723
        response = self._get_branch_reference()
686
724
        if response[0] == 'ref':
722
760
        """See BzrDir._get_tree_branch()."""
723
761
        return None, self.open_branch(name=name)
724
762
 
725
 
    def open_branch(self, name=None, unsupported=False,
726
 
                    ignore_fallbacks=False, possible_transports=None):
727
 
        if unsupported:
728
 
            raise NotImplementedError('unsupported flag support not implemented yet.')
729
 
        if self._next_open_branch_result is not None:
730
 
            # See create_branch for details.
731
 
            result = self._next_open_branch_result
732
 
            self._next_open_branch_result = None
733
 
            return result
734
 
        response = self._get_branch_reference()
735
 
        if response[0] == 'ref':
 
763
    def _open_branch(self, name, kind, location_or_format,
 
764
                     ignore_fallbacks=False, possible_transports=None):
 
765
        if kind == 'ref':
736
766
            # a branch reference, use the existing BranchReference logic.
737
767
            format = BranchReferenceFormat()
738
768
            return format.open(self, name=name, _found=True,
739
 
                location=response[1], ignore_fallbacks=ignore_fallbacks,
 
769
                location=location_or_format, ignore_fallbacks=ignore_fallbacks,
740
770
                possible_transports=possible_transports)
741
 
        branch_format_name = response[1]
 
771
        branch_format_name = location_or_format
742
772
        if not branch_format_name:
743
773
            branch_format_name = None
744
774
        format = RemoteBranchFormat(network_name=branch_format_name)
746
776
            setup_stacking=not ignore_fallbacks, name=name,
747
777
            possible_transports=possible_transports)
748
778
 
 
779
    def open_branch(self, name=None, unsupported=False,
 
780
                    ignore_fallbacks=False, possible_transports=None):
 
781
        if name is None:
 
782
            name = self._get_selected_branch()
 
783
        if name != "":
 
784
            raise errors.NoColocatedBranchSupport(self)
 
785
        if unsupported:
 
786
            raise NotImplementedError('unsupported flag support not implemented yet.')
 
787
        if self._next_open_branch_result is not None:
 
788
            # See create_branch for details.
 
789
            result = self._next_open_branch_result
 
790
            self._next_open_branch_result = None
 
791
            return result
 
792
        response = self._get_branch_reference()
 
793
        return self._open_branch(name, response[0], response[1],
 
794
            possible_transports=possible_transports,
 
795
            ignore_fallbacks=ignore_fallbacks)
 
796
 
749
797
    def _open_repo_v1(self, path):
750
798
        verb = 'BzrDir.find_repository'
751
799
        response = self._call(verb, path)
3089
3137
        if isinstance(a_bzrdir, RemoteBzrDir):
3090
3138
            a_bzrdir._ensure_real()
3091
3139
            result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
3092
 
                name, append_revisions_only=append_revisions_only)
 
3140
                name=name, append_revisions_only=append_revisions_only)
3093
3141
        else:
3094
3142
            # We assume the bzrdir is parameterised; it may not be.
3095
 
            result = self._custom_format.initialize(a_bzrdir, name,
 
3143
            result = self._custom_format.initialize(a_bzrdir, name=name,
3096
3144
                append_revisions_only=append_revisions_only)
3097
3145
        if (isinstance(a_bzrdir, RemoteBzrDir) and
3098
3146
            not isinstance(result, RemoteBranch)):
3102
3150
 
3103
3151
    def initialize(self, a_bzrdir, name=None, repository=None,
3104
3152
                   append_revisions_only=None):
 
3153
        if name is None:
 
3154
            name = a_bzrdir._get_selected_branch()
3105
3155
        # 1) get the network name to use.
3106
3156
        if self._custom_format:
3107
3157
            network_name = self._custom_format.network_name()
3122
3172
        # Creating on a remote bzr dir.
3123
3173
        # 2) try direct creation via RPC
3124
3174
        path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
3125
 
        if name is not None:
 
3175
        if name != "":
3126
3176
            # XXX JRV20100304: Support creating colocated branches
3127
3177
            raise errors.NoColocatedBranchSupport(self)
3128
3178
        verb = 'BzrDir.create_branch'
3273
3323
        # will try to assign to self.tags, which is a property in this subclass.
3274
3324
        # And the parent's __init__ doesn't do much anyway.
3275
3325
        self.bzrdir = remote_bzrdir
 
3326
        self.name = name
3276
3327
        if _client is not None:
3277
3328
            self._client = _client
3278
3329
        else: