/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
1
# Copyright (C) 2006 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
17
# TODO: At some point, handle upgrades by just passing the whole request
18
# across to run on the server.
19
2018.5.26 by Andrew Bennetts
Extract a simple SmartClient class from RemoteTransport, and a hack to avoid VFS operations when probing for a bzrdir over a smart transport.
20
from urlparse import urlparse
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
21
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
22
from bzrlib import branch, errors, repository
23
from bzrlib.bzrdir import BzrDir, BzrDirFormat, RemoteBzrDirFormat
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
24
from bzrlib.branch import Branch, BranchFormat
2018.5.32 by Robert Collins
Unescape urls before handing over the wire to the smart server for the probe_transport method.
25
from bzrlib.smart import client
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
26
from bzrlib.trace import mutter
2018.5.32 by Robert Collins
Unescape urls before handing over the wire to the smart server for the probe_transport method.
27
from bzrlib.urlutils import unescape
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
28
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
29
# Note: RemoteBzrDirFormat is in bzrdir.py
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
30
31
class RemoteBzrDir(BzrDir):
32
    """Control directory on a remote server, accessed by HPSS."""
33
34
    def __init__(self, transport):
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
35
        BzrDir.__init__(self, transport, RemoteBzrDirFormat())
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
36
        self.client = transport.get_smart_client()
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
37
        # this object holds a delegated bzrdir that uses file-level operations
38
        # to talk to the other side
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
39
        # XXX: We should go into find_format, but not allow it to find
40
        # RemoteBzrDirFormat and make sure it finds the real underlying format.
41
        
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
42
        default_format = BzrDirFormat.get_default_format()
43
        self._real_bzrdir = default_format.open(transport, _found=True)
2018.5.32 by Robert Collins
Unescape urls before handing over the wire to the smart server for the probe_transport method.
44
        path = unescape(urlparse(transport.base)[2])
2018.5.26 by Andrew Bennetts
Extract a simple SmartClient class from RemoteTransport, and a hack to avoid VFS operations when probing for a bzrdir over a smart transport.
45
        #self._real_bzrdir._format.probe_transport(transport)
46
        response = client.SmartClient(self.client).call('probe_dont_use', path)
47
        if response == ('no',):
48
            raise errors.NotBranchError(path=transport.base)
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
49
        self._branch = None
50
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
51
    def create_repository(self, shared=False):
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
52
        return RemoteRepository(
53
            self, self._real_bzrdir.create_repository(shared=shared))
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
54
55
    def create_branch(self):
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
56
        real_branch = self._real_bzrdir.create_branch()
57
        real_repository = real_branch.repository
58
        remote_repository = RemoteRepository(self, real_repository)
59
        return RemoteBranch(self, remote_repository, real_branch)
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
60
61
    def create_workingtree(self, revision_id=None):
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
62
        real_workingtree = self._real_bzrdir.create_workingtree(revision_id=revision_id)
63
        return RemoteWorkingTree(self, real_workingtree)
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
64
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
65
    def open_repository(self):
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
66
        return RemoteRepository(self, self._real_bzrdir.open_repository())
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
67
1752.2.87 by Andrew Bennetts
Make tests pass.
68
    def open_branch(self, _unsupported=False):
69
        real_branch = self._real_bzrdir.open_branch(unsupported=_unsupported)
1752.2.64 by Andrew Bennetts
Improve how RemoteBzrDir.open_branch works to handle references and not double-open repositories.
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
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
74
            remote_repository = RemoteRepository(self, real_repository)
1752.2.64 by Andrew Bennetts
Improve how RemoteBzrDir.open_branch works to handle references and not double-open repositories.
75
            return RemoteBranch(self, remote_repository, real_branch)
76
        else:
77
            # We were redirected to somewhere else, so don't wrap.
78
            return real_branch
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
79
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
80
    def open_workingtree(self):
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
81
        return RemoteWorkingTree(self, self._real_bzrdir.open_workingtree())
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
82
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
83
    def get_branch_transport(self, branch_format):
84
        return self._real_bzrdir.get_branch_transport(branch_format)
85
1752.2.43 by Andrew Bennetts
Fix get_{branch,repository,workingtree}_transport.
86
    def get_repository_transport(self, repository_format):
87
        return self._real_bzrdir.get_repository_transport(repository_format)
88
89
    def get_workingtree_transport(self, workingtree_format):
90
        return self._real_bzrdir.get_workingtree_transport(workingtree_format)
91
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
92
    def can_convert_format(self):
93
        """Upgrading of remote bzrdirs is not supported yet."""
94
        return False
95
96
    def needs_format_conversion(self, format=None):
97
        """Upgrading of remote bzrdirs is not supported yet."""
98
        return False
99
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
100
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
101
class RemoteRepositoryFormat(repository.RepositoryFormat):
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
102
    """Format for repositories accessed over rpc.
103
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
104
    Instances of this repository are represented by RemoteRepository
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
105
    instances.
106
    """
107
108
    _matchingbzrdir = RemoteBzrDirFormat
109
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
110
    def initialize(self, a_bzrdir, shared=False):
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
111
        assert isinstance(a_bzrdir, RemoteBzrDir)
112
        return a_bzrdir.create_repository(shared=shared)
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
113
    
114
    def open(self, a_bzrdir):
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
115
        assert isinstance(a_bzrdir, RemoteBzrDir)
116
        return a_bzrdir.open_repository()
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
117
118
    def get_format_description(self):
119
        return 'bzr remote repository'
120
121
    def __eq__(self, other):
1752.2.87 by Andrew Bennetts
Make tests pass.
122
        return self.__class__ == other.__class__
123
124
    rich_root_data = False
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
125
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
126
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
127
class RemoteRepository(object):
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
128
    """Repository accessed over rpc.
129
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
130
    For the moment everything is delegated to IO-like operations over
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
131
    the transport.
132
    """
133
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
134
    def __init__(self, remote_bzrdir, real_repository):
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
135
        self.real_repository = real_repository
136
        self.bzrdir = remote_bzrdir
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
137
        self._format = RemoteRepositoryFormat()
138
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
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
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
144
145
class RemoteBranchFormat(branch.BranchFormat):
146
147
    def open(self, a_bzrdir):
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
148
        assert isinstance(a_bzrdir, RemoteBzrDir)
149
        return a_bzrdir.open_branch()
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
150
151
    def initialize(self, a_bzrdir):
152
        assert isinstance(a_bzrdir, RemoteBzrDir)
153
        return a_bzrdir.create_branch()
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
154
155
156
class RemoteBranch(branch.Branch):
157
    """Branch stored on a server accessed by HPSS RPC.
158
159
    At the moment most operations are mapped down to simple file operations.
160
    """
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
161
1752.2.64 by Andrew Bennetts
Improve how RemoteBzrDir.open_branch works to handle references and not double-open repositories.
162
    def __init__(self, remote_bzrdir, remote_repository, real_branch):
163
        self.bzrdir = remote_bzrdir
164
        self.transport = remote_bzrdir.transport
165
        self.repository = remote_repository
166
        self._real_branch = real_branch
167
        self._format = RemoteBranchFormat()
168
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
169
    def lock_read(self):
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
170
        return self._real_branch.lock_read()
171
172
    def lock_write(self):
173
        return self._real_branch.lock_write()
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
174
175
    def unlock(self):
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
176
        return self._real_branch.unlock()
177
178
    def break_lock(self):
179
        return self._real_branch.break_lock()
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
180
181
    def revision_history(self):
182
        return self._real_branch.revision_history()
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
183
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
184
    def set_revision_history(self, rev_history):
185
        return self._real_branch.set_revision_history(rev_history)
186
187
    def get_parent(self):
188
        return self._real_branch.get_parent()
189
        
1752.2.63 by Andrew Bennetts
Delegate set_parent.
190
    def set_parent(self, url):
191
        return self._real_branch.set_parent(url)
192
        
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
193
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
194
class RemoteWorkingTree(object):
195
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
196
    def __init__(self, remote_bzrdir, real_workingtree):
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
197
        self.real_workingtree = real_workingtree
198
        self.bzrdir = remote_bzrdir
199
200
    def __getattr__(self, name):
201
        # XXX: temporary way to lazily delegate everything to the real
202
        # workingtree
203
        return getattr(self.real_workingtree, name)
204
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
205