~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from bzrlib import branch, errors, repository
23
23
from bzrlib.bzrdir import BzrDir, BzrDirFormat, RemoteBzrDirFormat
24
 
from bzrlib.branch import Branch, BranchFormat
25
 
from bzrlib.smart import client
 
24
from bzrlib.branch import Branch, BranchFormat, BranchReferenceFormat
 
25
from bzrlib.smart import client, vfs
26
26
from bzrlib.trace import mutter
27
27
from bzrlib.urlutils import unescape
28
28
 
39
39
        # XXX: We should go into find_format, but not allow it to find
40
40
        # RemoteBzrDirFormat and make sure it finds the real underlying format.
41
41
        
 
42
        # THIS IS A COMPLETE AND UTTER LIE.
 
43
        # XXX: XXX: XXX: must be removed before merging to mainline
 
44
        # SMART_SERVER_MERGE_BLOCKER
42
45
        default_format = BzrDirFormat.get_default_format()
43
46
        self._real_bzrdir = default_format.open(transport, _found=True)
44
 
        path = unescape(urlparse(transport.base)[2])
 
47
        path = self._path_for_remote_call()
45
48
        #self._real_bzrdir._format.probe_transport(transport)
46
49
        response = client.SmartClient(self.client).call('probe_dont_use', path)
47
50
        if response == ('no',):
62
65
        real_workingtree = self._real_bzrdir.create_workingtree(revision_id=revision_id)
63
66
        return RemoteWorkingTree(self, real_workingtree)
64
67
 
 
68
    def open_branch(self, _unsupported=False):
 
69
        assert _unsupported == False, 'unsupported flag support not implemented yet.'
 
70
        path = self._path_for_remote_call()
 
71
        response = client.SmartClient(self.client).call('BzrDir.open_branch', path)
 
72
        assert response[0] == 'ok', 'unexpected response code %s' % response[0]
 
73
        if response[0] != 'ok':
 
74
            # this should probably be a regular translate no ?
 
75
            raise errors.NotBranchError(path=self.root_transport.base)
 
76
        if response[1] == '':
 
77
            # branch at this location.
 
78
            if vfs.vfs_enabled():
 
79
                # if the VFS is enabled, create a local object using the VFS.
 
80
                real_branch = self._real_bzrdir.open_branch(unsupported=_unsupported)
 
81
                # This branch accessed through the smart server, so wrap the
 
82
                # file-level objects.
 
83
                real_repository = real_branch.repository
 
84
                remote_repository = RemoteRepository(self, real_repository)
 
85
                return RemoteBranch(self, remote_repository, real_branch)
 
86
            else:
 
87
                # otherwise just create a proxy for the branch.
 
88
                return RemoteBranch(self, self.find_repository())
 
89
        else:
 
90
            # a branch reference, use the existing BranchReference logic.
 
91
            format = BranchReferenceFormat()
 
92
            return format.open(self, _found=True, location=response[1])
 
93
 
65
94
    def open_repository(self):
66
 
        return RemoteRepository(self, self._real_bzrdir.open_repository())
67
 
 
68
 
    def open_branch(self, _unsupported=False):
69
 
        real_branch = self._real_bzrdir.open_branch(unsupported=_unsupported)
70
 
        if real_branch.bzrdir is self._real_bzrdir:
71
 
            # This branch accessed through the smart server, so wrap the
72
 
            # file-level objects.
73
 
            real_repository = real_branch.repository
74
 
            remote_repository = RemoteRepository(self, real_repository)
75
 
            return RemoteBranch(self, remote_repository, real_branch)
 
95
        path = self._path_for_remote_call()
 
96
        response = client.SmartClient(self.client).call('BzrDir.find_repository', path)
 
97
        assert response[0] == 'ok', 'unexpected response code %s' % response[0]
 
98
        if response[1] == '':
 
99
            if vfs.vfs_enabled():
 
100
                return RemoteRepository(self, self._real_bzrdir.open_repository())
 
101
            else:
 
102
                return RemoteRepository(self)
76
103
        else:
77
 
            # We were redirected to somewhere else, so don't wrap.
78
 
            return real_branch
 
104
            raise errors.NoRepositoryPresent(self)
79
105
 
80
106
    def open_workingtree(self):
81
107
        return RemoteWorkingTree(self, self._real_bzrdir.open_workingtree())
82
108
 
 
109
    def _path_for_remote_call(self):
 
110
        """Return the path to be used for this bzrdir in a remote call."""
 
111
        return unescape(urlparse(self.root_transport.base)[2])
 
112
 
83
113
    def get_branch_transport(self, branch_format):
84
114
        return self._real_bzrdir.get_branch_transport(branch_format)
85
115
 
131
161
    the transport.
132
162
    """
133
163
 
134
 
    def __init__(self, remote_bzrdir, real_repository):
135
 
        self.real_repository = real_repository
 
164
    def __init__(self, remote_bzrdir, real_repository=None):
 
165
        """Create a RemoteRepository instance.
 
166
        
 
167
        :param remote_bzrdir: The bzrdir hosting this repository.
 
168
        :param real_repository: If not None, a local implementation of the
 
169
            repository logic for the repository, usually accessing the data
 
170
            via the VFS.
 
171
        """
 
172
        if real_repository:
 
173
            self._real_repository = _real_repository
136
174
        self.bzrdir = remote_bzrdir
137
175
        self._format = RemoteRepositoryFormat()
138
176
 
139
 
    def __getattr__(self, name):
140
 
        # XXX: temporary way to lazily delegate everything to the real
141
 
        # repository
142
 
        return getattr(self.real_repository, name)
143
 
 
144
177
 
145
178
class RemoteBranchFormat(branch.BranchFormat):
146
179
 
159
192
    At the moment most operations are mapped down to simple file operations.
160
193
    """
161
194
 
162
 
    def __init__(self, remote_bzrdir, remote_repository, real_branch):
 
195
    def __init__(self, remote_bzrdir, remote_repository, real_branch=None):
 
196
        """Create a RemoteBranch instance.
 
197
 
 
198
        :param real_branch: An optional local implementation of the branch
 
199
            format, usually accessing the data via the VFS.
 
200
        """
163
201
        self.bzrdir = remote_bzrdir
164
 
        self.transport = remote_bzrdir.transport
165
202
        self.repository = remote_repository
166
 
        self._real_branch = real_branch
 
203
        if real_branch is not None:
 
204
            self._real_branch = real_branch
167
205
        self._format = RemoteBranchFormat()
168
206
 
169
207
    def lock_read(self):