/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
1
# Copyright (C) 2006, 2007 Canonical Ltd
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
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.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
20
from cStringIO import StringIO
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
21
2490.2.5 by Aaron Bentley
Use GraphWalker.unique_ancestor to determine merge base
22
from bzrlib import (
23
    branch,
24
    errors,
25
    lockdir,
26
    repository,
27
)
2477.1.5 by Martin Pool
More cleanups of Branch.push to get the right behaviour with RemoteBranches
28
from bzrlib.branch import Branch, BranchReferenceFormat
2018.5.174 by Andrew Bennetts
Various nits discovered by pyflakes.
29
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
2018.14.2 by Andrew Bennetts
All but one repository_implementation tests for RemoteRepository passing.
30
from bzrlib.config import BranchConfig, TreeConfig
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
31
from bzrlib.decorators import needs_read_lock, needs_write_lock
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
32
from bzrlib.errors import NoSuchRevision
2018.5.127 by Andrew Bennetts
Fix most of the lockable_files tests for RemoteBranchLockableFiles.
33
from bzrlib.lockable_files import LockableFiles
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
34
from bzrlib.revision import NULL_REVISION
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
35
from bzrlib.smart import client, vfs
2018.18.20 by Martin Pool
Route branch operations through remote copy_content_into
36
from bzrlib.trace import note
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
37
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
38
# Note: RemoteBzrDirFormat is in bzrdir.py
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
39
40
class RemoteBzrDir(BzrDir):
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
41
    """Control directory on a remote server, accessed via bzr:// or similar."""
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
42
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
43
    def __init__(self, transport, _client=None):
44
        """Construct a RemoteBzrDir.
45
46
        :param _client: Private parameter for testing. Disables probing and the
47
            use of a real bzrdir.
48
        """
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
49
        BzrDir.__init__(self, transport, RemoteBzrDirFormat())
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
50
        # this object holds a delegated bzrdir that uses file-level operations
51
        # to talk to the other side
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
52
        self._real_bzrdir = None
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
53
54
        if _client is None:
2485.8.54 by Vincent Ladeuil
Refactor medium uses by making a distinction betweem shared and real medium.
55
            self._shared_medium = transport.get_shared_medium()
56
            self._client = client._SmartClient(self._shared_medium)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
57
        else:
58
            self._client = _client
2485.8.54 by Vincent Ladeuil
Refactor medium uses by making a distinction betweem shared and real medium.
59
            self._shared_medium = None
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
60
            return
61
62
        path = self._path_for_remote_call(self._client)
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
63
        response = self._client.call('BzrDir.open', path)
64
        if response not in [('yes',), ('no',)]:
65
            raise errors.UnexpectedSmartServerResponse(response)
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.
66
        if response == ('no',):
67
            raise errors.NotBranchError(path=transport.base)
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
68
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
69
    def _ensure_real(self):
70
        """Ensure that there is a _real_bzrdir set.
71
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
72
        Used before calls to self._real_bzrdir.
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
73
        """
74
        if not self._real_bzrdir:
2018.5.169 by Andrew Bennetts
Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property.
75
            self._real_bzrdir = BzrDir.open_from_transport(
76
                self.root_transport, _server_formats=False)
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
77
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
78
    def create_repository(self, shared=False):
2018.5.162 by Andrew Bennetts
Add some missing _ensure_real calls, and a missing import.
79
        self._ensure_real()
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
80
        self._real_bzrdir.create_repository(shared=shared)
81
        return self.open_repository()
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
82
83
    def create_branch(self):
2018.5.162 by Andrew Bennetts
Add some missing _ensure_real calls, and a missing import.
84
        self._ensure_real()
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
85
        real_branch = self._real_bzrdir.create_branch()
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
86
        return RemoteBranch(self, self.find_repository(), real_branch)
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
87
88
    def create_workingtree(self, revision_id=None):
2018.5.174 by Andrew Bennetts
Various nits discovered by pyflakes.
89
        raise errors.NotLocalUrl(self.transport.base)
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
90
2018.5.124 by Robert Collins
Fix test_format_initialize_find_open by delegating Branch formt lookup to the BzrDir, where it should have stayed from the start.
91
    def find_branch_format(self):
92
        """Find the branch 'format' for this bzrdir.
93
94
        This might be a synthetic object for e.g. RemoteBranch and SVN.
95
        """
96
        b = self.open_branch()
97
        return b._format
98
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
99
    def get_branch_reference(self):
100
        """See BzrDir.get_branch_reference()."""
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
101
        path = self._path_for_remote_call(self._client)
102
        response = self._client.call('BzrDir.open_branch', path)
103
        if response[0] == 'ok':
104
            if response[1] == '':
105
                # branch at this location.
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
106
                return None
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
107
            else:
108
                # a branch reference, use the existing BranchReference logic.
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
109
                return response[1]
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
110
        elif response == ('nobranch',):
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
111
            raise errors.NotBranchError(path=self.root_transport.base)
112
        else:
2555.1.1 by Martin Pool
Remove use of 'assert False' to raise an exception unconditionally
113
            raise errors.UnexpectedSmartServerResponse(response)
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
114
115
    def open_branch(self, _unsupported=False):
116
        assert _unsupported == False, 'unsupported flag support not implemented yet.'
117
        reference_url = self.get_branch_reference()
118
        if reference_url is None:
119
            # branch at this location.
120
            return RemoteBranch(self, self.find_repository())
121
        else:
122
            # a branch reference, use the existing BranchReference logic.
123
            format = BranchReferenceFormat()
124
            return format.open(self, _found=True, location=reference_url)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
125
                
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
126
    def open_repository(self):
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
127
        path = self._path_for_remote_call(self._client)
128
        response = self._client.call('BzrDir.find_repository', path)
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
129
        assert response[0] in ('ok', 'norepository'), \
2018.5.52 by Wouter van Heyst
Provide more information when encountering unexpected responses from a smart
130
            'unexpected response code %s' % (response,)
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
131
        if response[0] == 'norepository':
132
            raise errors.NoRepositoryPresent(self)
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
133
        assert len(response) == 4, 'incorrect response length %s' % (response,)
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
134
        if response[1] == '':
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
135
            format = RemoteRepositoryFormat()
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
136
            format.rich_root_data = (response[2] == 'yes')
137
            format.supports_tree_reference = (response[3] == 'yes')
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
138
            return RemoteRepository(self, format)
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
139
        else:
140
            raise errors.NoRepositoryPresent(self)
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
141
2018.5.138 by Robert Collins
Merge bzr.dev.
142
    def open_workingtree(self, recommend_upgrade=True):
2445.1.1 by Andrew Bennetts
Make RemoteBzrDir.open_workingtree raise NoWorkingTree rather than NotLocalUrl
143
        self._ensure_real()
144
        if self._real_bzrdir.has_workingtree():
145
            raise errors.NotLocalUrl(self.root_transport)
146
        else:
147
            raise errors.NoWorkingTree(self.root_transport.base)
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
148
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
149
    def _path_for_remote_call(self, client):
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
150
        """Return the path to be used for this bzrdir in a remote call."""
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
151
        return client.remote_path_from_transport(self.root_transport)
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
152
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
153
    def get_branch_transport(self, branch_format):
2018.5.162 by Andrew Bennetts
Add some missing _ensure_real calls, and a missing import.
154
        self._ensure_real()
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
155
        return self._real_bzrdir.get_branch_transport(branch_format)
156
1752.2.43 by Andrew Bennetts
Fix get_{branch,repository,workingtree}_transport.
157
    def get_repository_transport(self, repository_format):
2018.5.162 by Andrew Bennetts
Add some missing _ensure_real calls, and a missing import.
158
        self._ensure_real()
1752.2.43 by Andrew Bennetts
Fix get_{branch,repository,workingtree}_transport.
159
        return self._real_bzrdir.get_repository_transport(repository_format)
160
161
    def get_workingtree_transport(self, workingtree_format):
2018.5.162 by Andrew Bennetts
Add some missing _ensure_real calls, and a missing import.
162
        self._ensure_real()
1752.2.43 by Andrew Bennetts
Fix get_{branch,repository,workingtree}_transport.
163
        return self._real_bzrdir.get_workingtree_transport(workingtree_format)
164
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
165
    def can_convert_format(self):
166
        """Upgrading of remote bzrdirs is not supported yet."""
167
        return False
168
169
    def needs_format_conversion(self, format=None):
170
        """Upgrading of remote bzrdirs is not supported yet."""
171
        return False
172
2018.5.138 by Robert Collins
Merge bzr.dev.
173
    def clone(self, url, revision_id=None, force_new_repo=False):
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
174
        self._ensure_real()
175
        return self._real_bzrdir.clone(url, revision_id=revision_id,
2018.5.138 by Robert Collins
Merge bzr.dev.
176
            force_new_repo=force_new_repo)
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
177
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
178
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
179
class RemoteRepositoryFormat(repository.RepositoryFormat):
2018.5.159 by Andrew Bennetts
Rename SmartClient to _SmartClient.
180
    """Format for repositories accessed over a _SmartClient.
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
181
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
182
    Instances of this repository are represented by RemoteRepository
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
183
    instances.
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
184
185
    The RemoteRepositoryFormat is parameterised during construction
186
    to reflect the capabilities of the real, remote format. Specifically
2018.5.138 by Robert Collins
Merge bzr.dev.
187
    the attributes rich_root_data and supports_tree_reference are set
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
188
    on a per instance basis, and are not set (and should not be) at
189
    the class level.
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
190
    """
191
192
    _matchingbzrdir = RemoteBzrDirFormat
193
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
194
    def initialize(self, a_bzrdir, shared=False):
2018.5.138 by Robert Collins
Merge bzr.dev.
195
        assert isinstance(a_bzrdir, RemoteBzrDir), \
196
            '%r is not a RemoteBzrDir' % (a_bzrdir,)
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
197
        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.
198
    
199
    def open(self, a_bzrdir):
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
200
        assert isinstance(a_bzrdir, RemoteBzrDir)
201
        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.
202
203
    def get_format_description(self):
204
        return 'bzr remote repository'
205
206
    def __eq__(self, other):
1752.2.87 by Andrew Bennetts
Make tests pass.
207
        return self.__class__ == other.__class__
208
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
209
    def check_conversion_target(self, target_format):
210
        if self.rich_root_data and not target_format.rich_root_data:
211
            raise errors.BadConversionTarget(
212
                'Does not support rich root data.', target_format)
2018.5.138 by Robert Collins
Merge bzr.dev.
213
        if (self.supports_tree_reference and
214
            not getattr(target_format, 'supports_tree_reference', False)):
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
215
            raise errors.BadConversionTarget(
216
                'Does not support nested trees', target_format)
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
217
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
218
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
219
class RemoteRepository(object):
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
220
    """Repository accessed over rpc.
221
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
222
    For the moment most operations are performed using local transport-backed
223
    Repository objects.
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
224
    """
225
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
226
    def __init__(self, remote_bzrdir, format, real_repository=None, _client=None):
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
227
        """Create a RemoteRepository instance.
228
        
229
        :param remote_bzrdir: The bzrdir hosting this repository.
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
230
        :param format: The RemoteFormat object to use.
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
231
        :param real_repository: If not None, a local implementation of the
232
            repository logic for the repository, usually accessing the data
233
            via the VFS.
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
234
        :param _client: Private testing parameter - override the smart client
235
            to be used by the repository.
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
236
        """
237
        if real_repository:
2018.5.36 by Andrew Bennetts
Fix typo, and clean up some ununsed import warnings from pyflakes at the same time.
238
            self._real_repository = real_repository
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
239
        else:
240
            self._real_repository = None
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
241
        self.bzrdir = remote_bzrdir
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
242
        if _client is None:
2485.8.54 by Vincent Ladeuil
Refactor medium uses by making a distinction betweem shared and real medium.
243
            self._client = client._SmartClient(self.bzrdir._shared_medium)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
244
        else:
245
            self._client = _client
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
246
        self._format = format
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
247
        self._lock_mode = None
248
        self._lock_token = None
249
        self._lock_count = 0
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
250
        self._leave_lock = False
2671.4.2 by Robert Collins
Review feedback.
251
        # for tests
252
        self._reconcile_does_inventory_gc = True
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
253
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
254
    def _ensure_real(self):
255
        """Ensure that there is a _real_repository set.
256
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
257
        Used before calls to self._real_repository.
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
258
        """
259
        if not self._real_repository:
260
            self.bzrdir._ensure_real()
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
261
            #self._real_repository = self.bzrdir._real_bzrdir.open_repository()
262
            self._set_real_repository(self.bzrdir._real_bzrdir.open_repository())
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
263
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
264
    def get_revision_graph(self, revision_id=None):
265
        """See Repository.get_revision_graph()."""
266
        if revision_id is None:
267
            revision_id = ''
268
        elif revision_id == NULL_REVISION:
269
            return {}
270
271
        path = self.bzrdir._path_for_remote_call(self._client)
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
272
        assert type(revision_id) is str
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
273
        response = self._client.call_expecting_body(
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
274
            'Repository.get_revision_graph', path, revision_id)
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
275
        if response[0][0] not in ['ok', 'nosuchrevision']:
276
            raise errors.UnexpectedSmartServerResponse(response[0])
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
277
        if response[0][0] == 'ok':
278
            coded = response[1].read_body_bytes()
2018.5.105 by Andrew Bennetts
Implement revision_history caching for RemoteBranch.
279
            if coded == '':
280
                # no revisions in this repository!
281
                return {}
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
282
            lines = coded.split('\n')
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
283
            revision_graph = {}
284
            for line in lines:
2625.8.1 by Robert Collins
LIBRARY API BREAKS:
285
                d = tuple(line.split())
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
286
                revision_graph[d[0]] = d[1:]
287
                
288
            return revision_graph
289
        else:
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
290
            response_body = response[1].read_body_bytes()
291
            assert response_body == ''
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
292
            raise NoSuchRevision(self, revision_id)
293
2018.5.40 by Robert Collins
Implement a remote Repository.has_revision method.
294
    def has_revision(self, revision_id):
295
        """See Repository.has_revision()."""
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
296
        if revision_id is None:
297
            # The null revision is always present.
298
            return True
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
299
        path = self.bzrdir._path_for_remote_call(self._client)
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
300
        response = self._client.call('Repository.has_revision', path, revision_id)
2018.5.158 by Andrew Bennetts
Return 'yes'/'no' rather than 'ok'/'no' from the Repository.has_revision smart command.
301
        assert response[0] in ('yes', 'no'), 'unexpected response code %s' % (response,)
302
        return response[0] == 'yes'
2018.5.40 by Robert Collins
Implement a remote Repository.has_revision method.
303
2490.2.21 by Aaron Bentley
Rename graph to deprecated_graph
304
    def get_graph(self, other_repository=None):
305
        """Return the graph for this repository format"""
306
        return self._real_repository.get_graph(other_repository)
2490.2.5 by Aaron Bentley
Use GraphWalker.unique_ancestor to determine merge base
307
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
308
    def gather_stats(self, revid=None, committers=None):
2018.5.62 by Robert Collins
Stub out RemoteRepository.gather_stats while its implemented in parallel.
309
        """See Repository.gather_stats()."""
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
310
        path = self.bzrdir._path_for_remote_call(self._client)
311
        if revid in (None, NULL_REVISION):
312
            fmt_revid = ''
313
        else:
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
314
            fmt_revid = revid
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
315
        if committers is None or not committers:
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
316
            fmt_committers = 'no'
317
        else:
318
            fmt_committers = 'yes'
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
319
        response = self._client.call_expecting_body(
320
            'Repository.gather_stats', path, fmt_revid, fmt_committers)
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
321
        assert response[0][0] == 'ok', \
322
            'unexpected response code %s' % (response[0],)
323
324
        body = response[1].read_body_bytes()
325
        result = {}
326
        for line in body.split('\n'):
327
            if not line:
328
                continue
329
            key, val_text = line.split(':')
330
            if key in ('revisions', 'size', 'committers'):
331
                result[key] = int(val_text)
332
            elif key in ('firstrev', 'latestrev'):
333
                values = val_text.split(' ')[1:]
334
                result[key] = (float(values[0]), long(values[1]))
335
336
        return result
2018.5.62 by Robert Collins
Stub out RemoteRepository.gather_stats while its implemented in parallel.
337
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
338
    def get_physical_lock_status(self):
339
        """See Repository.get_physical_lock_status()."""
340
        return False
341
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
342
    def is_shared(self):
343
        """See Repository.is_shared()."""
344
        path = self.bzrdir._path_for_remote_call(self._client)
345
        response = self._client.call('Repository.is_shared', path)
346
        assert response[0] in ('yes', 'no'), 'unexpected response code %s' % (response,)
347
        return response[0] == 'yes'
348
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
349
    def lock_read(self):
350
        # wrong eventually - want a local lock cache context
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
351
        if not self._lock_mode:
352
            self._lock_mode = 'r'
353
            self._lock_count = 1
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
354
            if self._real_repository is not None:
355
                self._real_repository.lock_read()
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
356
        else:
357
            self._lock_count += 1
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
358
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
359
    def _remote_lock_write(self, token):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
360
        path = self.bzrdir._path_for_remote_call(self._client)
361
        if token is None:
362
            token = ''
363
        response = self._client.call('Repository.lock_write', path, token)
364
        if response[0] == 'ok':
365
            ok, token = response
366
            return token
367
        elif response[0] == 'LockContention':
368
            raise errors.LockContention('(remote lock)')
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
369
        elif response[0] == 'UnlockableTransport':
370
            raise errors.UnlockableTransport(self.bzrdir.root_transport)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
371
        else:
2555.1.1 by Martin Pool
Remove use of 'assert False' to raise an exception unconditionally
372
            raise errors.UnexpectedSmartServerResponse(response)
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
373
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
374
    def lock_write(self, token=None):
375
        if not self._lock_mode:
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
376
            self._lock_token = self._remote_lock_write(token)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
377
            assert self._lock_token, 'Remote server did not return a token!'
378
            if self._real_repository is not None:
379
                self._real_repository.lock_write(token=self._lock_token)
380
            if token is not None:
381
                self._leave_lock = True
382
            else:
383
                self._leave_lock = False
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
384
            self._lock_mode = 'w'
385
            self._lock_count = 1
386
        elif self._lock_mode == 'r':
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
387
            raise errors.ReadOnlyError(self)
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
388
        else:
389
            self._lock_count += 1
390
        return self._lock_token
391
392
    def leave_lock_in_place(self):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
393
        self._leave_lock = True
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
394
395
    def dont_leave_lock_in_place(self):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
396
        self._leave_lock = False
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
397
398
    def _set_real_repository(self, repository):
399
        """Set the _real_repository for this repository.
400
401
        :param repository: The repository to fallback to for non-hpss
402
            implemented operations.
403
        """
2018.5.97 by Andrew Bennetts
Fix more tests.
404
        assert not isinstance(repository, RemoteRepository)
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
405
        self._real_repository = repository
406
        if self._lock_mode == 'w':
407
            # if we are already locked, the real repository must be able to
408
            # acquire the lock with our token.
409
            self._real_repository.lock_write(self._lock_token)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
410
        elif self._lock_mode == 'r':
411
            self._real_repository.lock_read()
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
412
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
413
    def _unlock(self, token):
414
        path = self.bzrdir._path_for_remote_call(self._client)
415
        response = self._client.call('Repository.unlock', path, token)
416
        if response == ('ok',):
417
            return
418
        elif response[0] == 'TokenMismatch':
419
            raise errors.TokenMismatch(token, '(remote token)')
420
        else:
2555.1.1 by Martin Pool
Remove use of 'assert False' to raise an exception unconditionally
421
            raise errors.UnexpectedSmartServerResponse(response)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
422
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
423
    def unlock(self):
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
424
        self._lock_count -= 1
425
        if not self._lock_count:
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
426
            mode = self._lock_mode
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
427
            self._lock_mode = None
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
428
            if self._real_repository is not None:
429
                self._real_repository.unlock()
430
            if mode != 'w':
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
431
                # Only write-locked repositories need to make a remote method
432
                # call to perfom the unlock.
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
433
                return
434
            assert self._lock_token, 'Locked, but no token!'
435
            token = self._lock_token
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
436
            self._lock_token = None
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
437
            if not self._leave_lock:
438
                self._unlock(token)
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
439
440
    def break_lock(self):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
441
        # should hand off to the network
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
442
        self._ensure_real()
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
443
        return self._real_repository.break_lock()
444
2018.18.8 by Ian Clatworthy
Tarball proxy code & tests
445
    def _get_tarball(self, compression):
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
446
        """Return a TemporaryFile containing a repository tarball"""
447
        import tempfile
2018.18.8 by Ian Clatworthy
Tarball proxy code & tests
448
        path = self.bzrdir._path_for_remote_call(self._client)
2018.18.14 by Martin Pool
merge hpss again; restore incorrectly removed RemoteRepository.break_lock
449
        response, protocol = self._client.call_expecting_body(
450
            'Repository.tarball', path, compression)
2018.18.8 by Ian Clatworthy
Tarball proxy code & tests
451
        assert response[0] in ('ok', 'failure'), \
452
            'unexpected response code %s' % (response,)
453
        if response[0] == 'ok':
454
            # Extract the tarball and return it
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
455
            t = tempfile.NamedTemporaryFile()
456
            # TODO: rpc layer should read directly into it...
457
            t.write(protocol.read_body_bytes())
458
            t.seek(0)
459
            return t
2018.18.8 by Ian Clatworthy
Tarball proxy code & tests
460
        else:
461
            raise errors.SmartServerError(error_code=response)
462
2440.1.1 by Martin Pool
Add new Repository.sprout,
463
    def sprout(self, to_bzrdir, revision_id=None):
464
        # TODO: Option to control what format is created?
465
        to_repo = to_bzrdir.create_repository()
2018.18.24 by Martin Pool
Merge Repository.sprout refactoring, and make that use Repository.tarball
466
        self._copy_repository_tarball(to_repo, revision_id)
2440.1.1 by Martin Pool
Add new Repository.sprout,
467
        return to_repo
468
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
469
    ### These methods are just thin shims to the VFS object for now.
470
471
    def revision_tree(self, revision_id):
472
        self._ensure_real()
473
        return self._real_repository.revision_tree(revision_id)
474
2520.4.113 by Aaron Bentley
Avoid peeking at Repository._serializer
475
    def get_serializer_format(self):
476
        self._ensure_real()
477
        return self._real_repository.get_serializer_format()
478
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
479
    def get_commit_builder(self, branch, parents, config, timestamp=None,
480
                           timezone=None, committer=None, revprops=None,
481
                           revision_id=None):
482
        # FIXME: It ought to be possible to call this without immediately
483
        # triggering _ensure_real.  For now it's the easiest thing to do.
484
        self._ensure_real()
485
        builder = self._real_repository.get_commit_builder(branch, parents,
486
                config, timestamp=timestamp, timezone=timezone,
487
                committer=committer, revprops=revprops, revision_id=revision_id)
488
        # Make the builder use this RemoteRepository rather than the real one.
489
        builder.repository = self
490
        return builder
491
492
    @needs_write_lock
493
    def add_inventory(self, revid, inv, parents):
494
        self._ensure_real()
495
        return self._real_repository.add_inventory(revid, inv, parents)
496
497
    @needs_write_lock
498
    def add_revision(self, rev_id, rev, inv=None, config=None):
499
        self._ensure_real()
500
        return self._real_repository.add_revision(
501
            rev_id, rev, inv=inv, config=config)
502
503
    @needs_read_lock
504
    def get_inventory(self, revision_id):
505
        self._ensure_real()
506
        return self._real_repository.get_inventory(revision_id)
507
508
    @needs_read_lock
509
    def get_revision(self, revision_id):
510
        self._ensure_real()
511
        return self._real_repository.get_revision(revision_id)
512
513
    @property
514
    def weave_store(self):
515
        self._ensure_real()
516
        return self._real_repository.weave_store
517
518
    def get_transaction(self):
519
        self._ensure_real()
520
        return self._real_repository.get_transaction()
521
522
    @needs_read_lock
2018.5.138 by Robert Collins
Merge bzr.dev.
523
    def clone(self, a_bzrdir, revision_id=None):
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
524
        self._ensure_real()
2018.5.138 by Robert Collins
Merge bzr.dev.
525
        return self._real_repository.clone(a_bzrdir, revision_id=revision_id)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
526
527
    def make_working_trees(self):
2018.5.120 by Robert Collins
The Repository API ``make_working_trees`` is now permitted to return
528
        """RemoteRepositories never create working trees by default."""
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
529
        return False
530
531
    def fetch(self, source, revision_id=None, pb=None):
532
        self._ensure_real()
533
        return self._real_repository.fetch(
534
            source, revision_id=revision_id, pb=pb)
535
2520.4.54 by Aaron Bentley
Hang a create_bundle method off repository
536
    def create_bundle(self, target, base, fileobj, format=None):
537
        self._ensure_real()
538
        self._real_repository.create_bundle(target, base, fileobj, format)
539
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
540
    @property
541
    def control_weaves(self):
542
        self._ensure_real()
543
        return self._real_repository.control_weaves
544
545
    @needs_read_lock
2530.1.1 by Aaron Bentley
Make topological sorting optional for get_ancestry
546
    def get_ancestry(self, revision_id, topo_sorted=True):
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
547
        self._ensure_real()
2530.1.1 by Aaron Bentley
Make topological sorting optional for get_ancestry
548
        return self._real_repository.get_ancestry(revision_id, topo_sorted)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
549
550
    @needs_read_lock
551
    def get_inventory_weave(self):
552
        self._ensure_real()
553
        return self._real_repository.get_inventory_weave()
554
555
    def fileids_altered_by_revision_ids(self, revision_ids):
556
        self._ensure_real()
557
        return self._real_repository.fileids_altered_by_revision_ids(revision_ids)
558
559
    @needs_read_lock
560
    def get_signature_text(self, revision_id):
561
        self._ensure_real()
562
        return self._real_repository.get_signature_text(revision_id)
563
564
    @needs_read_lock
565
    def get_revision_graph_with_ghosts(self, revision_ids=None):
566
        self._ensure_real()
567
        return self._real_repository.get_revision_graph_with_ghosts(
568
            revision_ids=revision_ids)
569
570
    @needs_read_lock
571
    def get_inventory_xml(self, revision_id):
572
        self._ensure_real()
573
        return self._real_repository.get_inventory_xml(revision_id)
574
575
    def deserialise_inventory(self, revision_id, xml):
576
        self._ensure_real()
577
        return self._real_repository.deserialise_inventory(revision_id, xml)
578
579
    def reconcile(self, other=None, thorough=False):
580
        self._ensure_real()
581
        return self._real_repository.reconcile(other=other, thorough=thorough)
582
        
583
    def all_revision_ids(self):
584
        self._ensure_real()
585
        return self._real_repository.all_revision_ids()
586
    
587
    @needs_read_lock
588
    def get_deltas_for_revisions(self, revisions):
589
        self._ensure_real()
590
        return self._real_repository.get_deltas_for_revisions(revisions)
591
592
    @needs_read_lock
593
    def get_revision_delta(self, revision_id):
594
        self._ensure_real()
595
        return self._real_repository.get_revision_delta(revision_id)
596
597
    @needs_read_lock
598
    def revision_trees(self, revision_ids):
599
        self._ensure_real()
600
        return self._real_repository.revision_trees(revision_ids)
601
602
    @needs_read_lock
603
    def get_revision_reconcile(self, revision_id):
604
        self._ensure_real()
605
        return self._real_repository.get_revision_reconcile(revision_id)
606
607
    @needs_read_lock
608
    def check(self, revision_ids):
609
        self._ensure_real()
610
        return self._real_repository.check(revision_ids)
611
2018.5.138 by Robert Collins
Merge bzr.dev.
612
    def copy_content_into(self, destination, revision_id=None):
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
613
        self._ensure_real()
614
        return self._real_repository.copy_content_into(
2018.5.138 by Robert Collins
Merge bzr.dev.
615
            destination, revision_id=revision_id)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
616
2018.18.24 by Martin Pool
Merge Repository.sprout refactoring, and make that use Repository.tarball
617
    def _copy_repository_tarball(self, destination, revision_id=None):
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
618
        # get a tarball of the remote repository, and copy from that into the
619
        # destination
620
        from bzrlib import osutils
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
621
        import tarfile
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
622
        import tempfile
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
623
        from StringIO import StringIO
2018.18.20 by Martin Pool
Route branch operations through remote copy_content_into
624
        # TODO: Maybe a progress bar while streaming the tarball?
625
        note("Copying repository content as tarball...")
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
626
        tar_file = self._get_tarball('bz2')
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
627
        try:
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
628
            tar = tarfile.open('repository', fileobj=tar_file,
629
                mode='r|bz2')
630
            tmpdir = tempfile.mkdtemp()
631
            try:
632
                _extract_tar(tar, tmpdir)
633
                tmp_bzrdir = BzrDir.open(tmpdir)
634
                tmp_repo = tmp_bzrdir.open_repository()
635
                tmp_repo.copy_content_into(destination, revision_id)
636
            finally:
637
                osutils.rmtree(tmpdir)
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
638
        finally:
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
639
            tar_file.close()
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
640
        # TODO: if the server doesn't support this operation, maybe do it the
641
        # slow way using the _real_repository?
2018.18.23 by Martin Pool
review cleanups
642
        #
643
        # TODO: Suggestion from john: using external tar is much faster than
644
        # python's tarfile library, but it may not work on windows.
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
645
2604.2.1 by Robert Collins
(robertc) Introduce a pack command.
646
    @needs_write_lock
647
    def pack(self):
648
        """Compress the data within the repository.
649
650
        This is not currently implemented within the smart server.
651
        """
652
        self._ensure_real()
653
        return self._real_repository.pack()
654
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
655
    def set_make_working_trees(self, new_value):
656
        raise NotImplementedError(self.set_make_working_trees)
657
658
    @needs_write_lock
659
    def sign_revision(self, revision_id, gpg_strategy):
660
        self._ensure_real()
661
        return self._real_repository.sign_revision(revision_id, gpg_strategy)
662
663
    @needs_read_lock
664
    def get_revisions(self, revision_ids):
665
        self._ensure_real()
666
        return self._real_repository.get_revisions(revision_ids)
667
668
    def supports_rich_root(self):
2018.5.84 by Andrew Bennetts
Merge in supports-rich-root, another test passing.
669
        self._ensure_real()
670
        return self._real_repository.supports_rich_root()
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
671
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
672
    def iter_reverse_revision_history(self, revision_id):
673
        self._ensure_real()
674
        return self._real_repository.iter_reverse_revision_history(revision_id)
675
2018.5.96 by Andrew Bennetts
Merge from bzr.dev, resolving the worst of the semantic conflicts, but there's
676
    @property
677
    def _serializer(self):
678
        self._ensure_real()
679
        return self._real_repository._serializer
680
2018.5.97 by Andrew Bennetts
Fix more tests.
681
    def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
682
        self._ensure_real()
683
        return self._real_repository.store_revision_signature(
684
            gpg_strategy, plaintext, revision_id)
685
686
    def has_signature_for_revision_id(self, revision_id):
687
        self._ensure_real()
688
        return self._real_repository.has_signature_for_revision_id(revision_id)
689
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
690
2018.5.127 by Andrew Bennetts
Fix most of the lockable_files tests for RemoteBranchLockableFiles.
691
class RemoteBranchLockableFiles(LockableFiles):
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
692
    """A 'LockableFiles' implementation that talks to a smart server.
693
    
694
    This is not a public interface class.
695
    """
696
697
    def __init__(self, bzrdir, _client):
698
        self.bzrdir = bzrdir
699
        self._client = _client
2018.5.135 by Andrew Bennetts
Prevent remote branch clients from determining the 'right' mode for control files, because we don't want clients setting the mode anyway.
700
        self._need_find_modes = True
2018.5.133 by Andrew Bennetts
All TestLockableFiles_RemoteLockDir tests passing.
701
        LockableFiles.__init__(
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
702
            self, bzrdir.get_branch_transport(None),
2018.5.133 by Andrew Bennetts
All TestLockableFiles_RemoteLockDir tests passing.
703
            'lock', lockdir.LockDir)
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
704
2018.5.135 by Andrew Bennetts
Prevent remote branch clients from determining the 'right' mode for control files, because we don't want clients setting the mode anyway.
705
    def _find_modes(self):
706
        # RemoteBranches don't let the client set the mode of control files.
707
        self._dir_mode = None
708
        self._file_mode = None
709
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
710
    def get(self, path):
711
        """'get' a remote path as per the LockableFiles interface.
712
713
        :param path: the file to 'get'. If this is 'branch.conf', we do not
714
             just retrieve a file, instead we ask the smart server to generate
715
             a configuration for us - which is retrieved as an INI file.
716
        """
2018.5.133 by Andrew Bennetts
All TestLockableFiles_RemoteLockDir tests passing.
717
        if path == 'branch.conf':
718
            path = self.bzrdir._path_for_remote_call(self._client)
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
719
            response = self._client.call_expecting_body(
720
                'Branch.get_config_file', path)
2018.5.133 by Andrew Bennetts
All TestLockableFiles_RemoteLockDir tests passing.
721
            assert response[0][0] == 'ok', \
722
                'unexpected response code %s' % (response[0],)
723
            return StringIO(response[1].read_body_bytes())
724
        else:
725
            # VFS fallback.
726
            return LockableFiles.get(self, path)
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
727
728
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
729
class RemoteBranchFormat(branch.BranchFormat):
730
2018.5.124 by Robert Collins
Fix test_format_initialize_find_open by delegating Branch formt lookup to the BzrDir, where it should have stayed from the start.
731
    def __eq__(self, other):
732
        return (isinstance(other, RemoteBranchFormat) and 
733
            self.__dict__ == other.__dict__)
734
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
735
    def get_format_description(self):
736
        return 'Remote BZR Branch'
737
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
738
    def get_format_string(self):
739
        return 'Remote BZR Branch'
740
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
741
    def open(self, a_bzrdir):
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
742
        assert isinstance(a_bzrdir, RemoteBzrDir)
743
        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.
744
745
    def initialize(self, a_bzrdir):
746
        assert isinstance(a_bzrdir, RemoteBzrDir)
747
        return a_bzrdir.create_branch()
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
748
749
750
class RemoteBranch(branch.Branch):
751
    """Branch stored on a server accessed by HPSS RPC.
752
753
    At the moment most operations are mapped down to simple file operations.
754
    """
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
755
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
756
    def __init__(self, remote_bzrdir, remote_repository, real_branch=None,
757
        _client=None):
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
758
        """Create a RemoteBranch instance.
759
760
        :param real_branch: An optional local implementation of the branch
761
            format, usually accessing the data via the VFS.
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
762
        :param _client: Private parameter for testing.
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
763
        """
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
764
        # We intentionally don't call the parent class's __init__, because it
765
        # will try to assign to self.tags, which is a property in this subclass.
766
        # And the parent's __init__ doesn't do much anyway.
2018.5.105 by Andrew Bennetts
Implement revision_history caching for RemoteBranch.
767
        self._revision_history_cache = None
1752.2.64 by Andrew Bennetts
Improve how RemoteBzrDir.open_branch works to handle references and not double-open repositories.
768
        self.bzrdir = remote_bzrdir
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
769
        if _client is not None:
770
            self._client = _client
771
        else:
2485.8.54 by Vincent Ladeuil
Refactor medium uses by making a distinction betweem shared and real medium.
772
            self._client = client._SmartClient(self.bzrdir._shared_medium)
1752.2.64 by Andrew Bennetts
Improve how RemoteBzrDir.open_branch works to handle references and not double-open repositories.
773
        self.repository = remote_repository
2018.5.34 by Robert Collins
Get test_remote.BasicRemoteObjectTests.test_open_remote_branch passing by implementing a remote method BzrDir.find_repository.
774
        if real_branch is not None:
775
            self._real_branch = real_branch
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
776
            # Give the remote repository the matching real repo.
2018.5.97 by Andrew Bennetts
Fix more tests.
777
            real_repo = self._real_branch.repository
778
            if isinstance(real_repo, RemoteRepository):
779
                real_repo._ensure_real()
780
                real_repo = real_repo._real_repository
781
            self.repository._set_real_repository(real_repo)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
782
            # Give the branch the remote repository to let fast-pathing happen.
783
            self._real_branch.repository = self.repository
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
784
        else:
785
            self._real_branch = None
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
786
        # Fill out expected attributes of branch for bzrlib api users.
1752.2.64 by Andrew Bennetts
Improve how RemoteBzrDir.open_branch works to handle references and not double-open repositories.
787
        self._format = RemoteBranchFormat()
2018.5.55 by Robert Collins
Give RemoteBranch a base url in line with the Branch protocol.
788
        self.base = self.bzrdir.root_transport.base
2018.5.169 by Andrew Bennetts
Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property.
789
        self._control_files = None
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
790
        self._lock_mode = None
791
        self._lock_token = None
792
        self._lock_count = 0
793
        self._leave_lock = False
1752.2.64 by Andrew Bennetts
Improve how RemoteBzrDir.open_branch works to handle references and not double-open repositories.
794
2477.1.1 by Martin Pool
Add RemoteBranch repr
795
    def __str__(self):
796
        return "%s(%s)" % (self.__class__.__name__, self.base)
797
798
    __repr__ = __str__
799
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
800
    def _ensure_real(self):
801
        """Ensure that there is a _real_branch set.
802
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
803
        Used before calls to self._real_branch.
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
804
        """
805
        if not self._real_branch:
806
            assert vfs.vfs_enabled()
807
            self.bzrdir._ensure_real()
808
            self._real_branch = self.bzrdir._real_bzrdir.open_branch()
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
809
            # Give the remote repository the matching real repo.
2018.5.97 by Andrew Bennetts
Fix more tests.
810
            real_repo = self._real_branch.repository
811
            if isinstance(real_repo, RemoteRepository):
812
                real_repo._ensure_real()
813
                real_repo = real_repo._real_repository
814
            self.repository._set_real_repository(real_repo)
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
815
            # Give the branch the remote repository to let fast-pathing happen.
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
816
            self._real_branch.repository = self.repository
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
817
            # XXX: deal with _lock_mode == 'w'
818
            if self._lock_mode == 'r':
819
                self._real_branch.lock_read()
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
820
2018.5.169 by Andrew Bennetts
Add a _server_formats flag to BzrDir.open_from_transport and BzrDirFormat.find_format, make RemoteBranch.control_files into a property.
821
    @property
822
    def control_files(self):
823
        # Defer actually creating RemoteBranchLockableFiles until its needed,
824
        # because it triggers an _ensure_real that we otherwise might not need.
825
        if self._control_files is None:
826
            self._control_files = RemoteBranchLockableFiles(
827
                self.bzrdir, self._client)
828
        return self._control_files
829
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
830
    def _get_checkout_format(self):
831
        self._ensure_real()
832
        return self._real_branch._get_checkout_format()
833
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
834
    def get_physical_lock_status(self):
835
        """See Branch.get_physical_lock_status()."""
836
        # should be an API call to the server, as branches must be lockable.
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
837
        self._ensure_real()
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
838
        return self._real_branch.get_physical_lock_status()
839
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
840
    def lock_read(self):
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
841
        if not self._lock_mode:
842
            self._lock_mode = 'r'
843
            self._lock_count = 1
844
            if self._real_branch is not None:
845
                self._real_branch.lock_read()
846
        else:
847
            self._lock_count += 1
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
848
2018.5.142 by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).
849
    def _remote_lock_write(self, token):
850
        if token is None:
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
851
            branch_token = repo_token = ''
852
        else:
2018.5.142 by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).
853
            branch_token = token
854
            repo_token = self.repository.lock_write()
855
            self.repository.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
856
        path = self.bzrdir._path_for_remote_call(self._client)
857
        response = self._client.call('Branch.lock_write', path, branch_token,
858
                                     repo_token)
859
        if response[0] == 'ok':
860
            ok, branch_token, repo_token = response
861
            return branch_token, repo_token
862
        elif response[0] == 'LockContention':
863
            raise errors.LockContention('(remote lock)')
864
        elif response[0] == 'TokenMismatch':
2018.5.142 by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).
865
            raise errors.TokenMismatch(token, '(remote token)')
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
866
        elif response[0] == 'UnlockableTransport':
867
            raise errors.UnlockableTransport(self.bzrdir.root_transport)
2018.5.123 by Robert Collins
Translate ReadOnlyError in RemoteBranch._remote_lock_write.
868
        elif response[0] == 'ReadOnlyError':
869
            raise errors.ReadOnlyError(self)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
870
        else:
2555.1.1 by Martin Pool
Remove use of 'assert False' to raise an exception unconditionally
871
            raise errors.UnexpectedSmartServerResponse(response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
872
            
2018.5.142 by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).
873
    def lock_write(self, token=None):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
874
        if not self._lock_mode:
2018.5.142 by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).
875
            remote_tokens = self._remote_lock_write(token)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
876
            self._lock_token, self._repo_lock_token = remote_tokens
877
            assert self._lock_token, 'Remote server did not return a token!'
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
878
            # TODO: We really, really, really don't want to call _ensure_real
879
            # here, but it's the easiest way to ensure coherency between the
880
            # state of the RemoteBranch and RemoteRepository objects and the
881
            # physical locks.  If we don't materialise the real objects here,
882
            # then getting everything in the right state later is complex, so
883
            # for now we just do it the lazy way.
884
            #   -- Andrew Bennetts, 2007-02-22.
885
            self._ensure_real()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
886
            if self._real_branch is not None:
2018.5.142 by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).
887
                self._real_branch.repository.lock_write(
888
                    token=self._repo_lock_token)
889
                try:
890
                    self._real_branch.lock_write(token=self._lock_token)
891
                finally:
892
                    self._real_branch.repository.unlock()
893
            if token is not None:
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
894
                self._leave_lock = True
895
            else:
2018.5.142 by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).
896
                # XXX: this case seems to be unreachable; token cannot be None.
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
897
                self._leave_lock = False
898
            self._lock_mode = 'w'
899
            self._lock_count = 1
900
        elif self._lock_mode == 'r':
901
            raise errors.ReadOnlyTransaction
902
        else:
2018.5.142 by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).
903
            if token is not None:
904
                # A token was given to lock_write, and we're relocking, so check
905
                # that the given token actually matches the one we already have.
906
                if token != self._lock_token:
907
                    raise errors.TokenMismatch(token, self._lock_token)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
908
            self._lock_count += 1
2018.5.142 by Andrew Bennetts
Change Branch.lock_token to only accept and receive the branch lock token (rather than the branch and repo lock tokens).
909
        return self._lock_token
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
910
911
    def _unlock(self, branch_token, repo_token):
912
        path = self.bzrdir._path_for_remote_call(self._client)
913
        response = self._client.call('Branch.unlock', path, branch_token,
914
                                     repo_token)
915
        if response == ('ok',):
916
            return
917
        elif response[0] == 'TokenMismatch':
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
918
            raise errors.TokenMismatch(
919
                str((branch_token, repo_token)), '(remote tokens)')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
920
        else:
2555.1.1 by Martin Pool
Remove use of 'assert False' to raise an exception unconditionally
921
            raise errors.UnexpectedSmartServerResponse(response)
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
922
923
    def unlock(self):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
924
        self._lock_count -= 1
925
        if not self._lock_count:
2018.5.105 by Andrew Bennetts
Implement revision_history caching for RemoteBranch.
926
            self._clear_cached_state()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
927
            mode = self._lock_mode
928
            self._lock_mode = None
929
            if self._real_branch is not None:
2018.15.1 by Andrew Bennetts
All branch_implementations/test_locking tests passing.
930
                if not self._leave_lock:
931
                    # If this RemoteBranch will remove the physical lock for the
932
                    # repository, make sure the _real_branch doesn't do it
933
                    # first.  (Because the _real_branch's repository is set to
934
                    # be the RemoteRepository.)
935
                    self._real_branch.repository.leave_lock_in_place()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
936
                self._real_branch.unlock()
937
            if mode != 'w':
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
938
                # Only write-locked branched need to make a remote method call
939
                # to perfom the unlock.
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
940
                return
941
            assert self._lock_token, 'Locked, but no token!'
942
            branch_token = self._lock_token
943
            repo_token = self._repo_lock_token
944
            self._lock_token = None
945
            self._repo_lock_token = None
946
            if not self._leave_lock:
947
                self._unlock(branch_token, repo_token)
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
948
949
    def break_lock(self):
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
950
        self._ensure_real()
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
951
        return self._real_branch.break_lock()
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
952
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
953
    def leave_lock_in_place(self):
954
        self._leave_lock = True
955
956
    def dont_leave_lock_in_place(self):
957
        self._leave_lock = False
958
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
959
    def last_revision_info(self):
960
        """See Branch.last_revision_info()."""
961
        path = self.bzrdir._path_for_remote_call(self._client)
962
        response = self._client.call('Branch.last_revision_info', path)
2018.5.52 by Wouter van Heyst
Provide more information when encountering unexpected responses from a smart
963
        assert response[0] == 'ok', 'unexpected response code %s' % (response,)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
964
        revno = int(response[1])
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
965
        last_revision = response[2]
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
966
        return (revno, last_revision)
967
2018.5.105 by Andrew Bennetts
Implement revision_history caching for RemoteBranch.
968
    def _gen_revision_history(self):
969
        """See Branch._gen_revision_history()."""
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
970
        path = self.bzrdir._path_for_remote_call(self._client)
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
971
        response = self._client.call_expecting_body(
972
            'Branch.revision_history', path)
973
        assert response[0][0] == 'ok', ('unexpected response code %s'
974
                                        % (response[0],))
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
975
        result = response[1].read_body_bytes().split('\x00')
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
976
        if result == ['']:
977
            return []
978
        return result
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
979
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
980
    @needs_write_lock
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
981
    def set_revision_history(self, rev_history):
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
982
        # Send just the tip revision of the history; the server will generate
983
        # the full history from that.  If the revision doesn't exist in this
984
        # branch, NoSuchRevision will be raised.
985
        path = self.bzrdir._path_for_remote_call(self._client)
986
        if rev_history == []:
2018.5.170 by Andrew Bennetts
Use 'null:' instead of '' to mean NULL_REVISION on the wire.
987
            rev_id = 'null:'
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
988
        else:
989
            rev_id = rev_history[-1]
2418.5.12 by John Arbash Meinel
Move functions from BzrBranch to base Branch object.
990
        self._clear_cached_state()
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
991
        response = self._client.call('Branch.set_last_revision',
992
            path, self._lock_token, self._repo_lock_token, rev_id)
2018.12.3 by Andrew Bennetts
Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.
993
        if response[0] == 'NoSuchRevision':
994
            raise NoSuchRevision(self, rev_id)
995
        else:
996
            assert response == ('ok',), (
997
                'unexpected response code %r' % (response,))
2018.5.105 by Andrew Bennetts
Implement revision_history caching for RemoteBranch.
998
        self._cache_revision_history(rev_history)
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
999
1000
    def get_parent(self):
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
1001
        self._ensure_real()
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1002
        return self._real_branch.get_parent()
1003
        
1752.2.63 by Andrew Bennetts
Delegate set_parent.
1004
    def set_parent(self, url):
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
1005
        self._ensure_real()
1752.2.63 by Andrew Bennetts
Delegate set_parent.
1006
        return self._real_branch.set_parent(url)
1007
        
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1008
    def get_config(self):
1009
        return RemoteBranchConfig(self)
1010
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
1011
    def sprout(self, to_bzrdir, revision_id=None):
1012
        # Like Branch.sprout, except that it sprouts a branch in the default
1013
        # format, because RemoteBranches can't be created at arbitrary URLs.
1014
        # XXX: if to_bzrdir is a RemoteBranch, this should perhaps do
1015
        # to_bzrdir.create_branch...
1016
        result = branch.BranchFormat.get_default_format().initialize(to_bzrdir)
2018.18.20 by Martin Pool
Route branch operations through remote copy_content_into
1017
        self.copy_content_into(result, revision_id=revision_id)
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
1018
        result.set_parent(self.bzrdir.root_transport.base)
1019
        return result
1020
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1021
    @needs_write_lock
1022
    def append_revision(self, *revision_ids):
1023
        self._ensure_real()
1024
        return self._real_branch.append_revision(*revision_ids)
1025
1026
    @needs_write_lock
2477.1.2 by Martin Pool
Rename push/pull back to 'run_hooks' (jameinel)
1027
    def pull(self, source, overwrite=False, stop_revision=None,
2477.1.9 by Martin Pool
Review cleanups from John, mostly docs
1028
             **kwargs):
1029
        # FIXME: This asks the real branch to run the hooks, which means
1030
        # they're called with the wrong target branch parameter. 
1031
        # The test suite specifically allows this at present but it should be
1032
        # fixed.  It should get a _override_hook_target branch,
1033
        # as push does.  -- mbp 20070405
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1034
        self._ensure_real()
1035
        self._real_branch.pull(
2477.1.2 by Martin Pool
Rename push/pull back to 'run_hooks' (jameinel)
1036
            source, overwrite=overwrite, stop_revision=stop_revision,
1037
            **kwargs)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1038
2018.14.3 by Andrew Bennetts
Make a couple more branch_implementations tests pass.
1039
    @needs_read_lock
1040
    def push(self, target, overwrite=False, stop_revision=None):
1041
        self._ensure_real()
2018.5.97 by Andrew Bennetts
Fix more tests.
1042
        return self._real_branch.push(
2477.1.5 by Martin Pool
More cleanups of Branch.push to get the right behaviour with RemoteBranches
1043
            target, overwrite=overwrite, stop_revision=stop_revision,
1044
            _override_hook_source_branch=self)
2018.14.3 by Andrew Bennetts
Make a couple more branch_implementations tests pass.
1045
1046
    def is_locked(self):
1047
        return self._lock_count >= 1
1048
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
1049
    def set_last_revision_info(self, revno, revision_id):
1050
        self._ensure_real()
2018.5.105 by Andrew Bennetts
Implement revision_history caching for RemoteBranch.
1051
        self._clear_cached_state()
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
1052
        return self._real_branch.set_last_revision_info(revno, revision_id)
1053
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
1054
    def generate_revision_history(self, revision_id, last_rev=None,
1055
                                  other_branch=None):
1056
        self._ensure_real()
1057
        return self._real_branch.generate_revision_history(
1058
            revision_id, last_rev=last_rev, other_branch=other_branch)
1059
2018.5.96 by Andrew Bennetts
Merge from bzr.dev, resolving the worst of the semantic conflicts, but there's
1060
    @property
1061
    def tags(self):
1062
        self._ensure_real()
1063
        return self._real_branch.tags
1064
2018.5.97 by Andrew Bennetts
Fix more tests.
1065
    def set_push_location(self, location):
1066
        self._ensure_real()
1067
        return self._real_branch.set_push_location(location)
1068
1069
    def update_revisions(self, other, stop_revision=None):
1070
        self._ensure_real()
1071
        return self._real_branch.update_revisions(
1072
            other, stop_revision=stop_revision)
1073
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
1074
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1075
class RemoteBranchConfig(BranchConfig):
1076
1077
    def username(self):
1078
        self.branch._ensure_real()
1079
        return self.branch._real_branch.get_config().username()
1080
2018.14.2 by Andrew Bennetts
All but one repository_implementation tests for RemoteRepository passing.
1081
    def _get_branch_data_config(self):
1082
        self.branch._ensure_real()
1083
        if self._branch_data_config is None:
1084
            self._branch_data_config = TreeConfig(self.branch._real_branch)
1085
        return self._branch_data_config
1086
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
1087
1088
def _extract_tar(tar, to_dir):
1089
    """Extract all the contents of a tarfile object.
1090
1091
    A replacement for extractall, which is not present in python2.4
1092
    """
1093
    for tarinfo in tar:
1094
        tar.extract(tarinfo, to_dir)