/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,
2948.3.1 by John Arbash Meinel
Fix bug #158333, make sure that Repository.fetch(self) is properly a no-op for all Repository implementations.
27
    revision,
2490.2.5 by Aaron Bentley
Use GraphWalker.unique_ancestor to determine merge base
28
)
2535.4.27 by Andrew Bennetts
Remove some unused imports.
29
from bzrlib.branch import BranchReferenceFormat
2018.5.174 by Andrew Bennetts
Various nits discovered by pyflakes.
30
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
2018.14.2 by Andrew Bennetts
All but one repository_implementation tests for RemoteRepository passing.
31
from bzrlib.config import BranchConfig, TreeConfig
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
32
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)
33
from bzrlib.errors import NoSuchRevision
2018.5.127 by Andrew Bennetts
Fix most of the lockable_files tests for RemoteBranchLockableFiles.
34
from bzrlib.lockable_files import LockableFiles
2535.4.20 by Andrew Bennetts
Remove unused import.
35
from bzrlib.pack import ContainerPushParser
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
36
from bzrlib.smart import client, vfs
2018.18.20 by Martin Pool
Route branch operations through remote copy_content_into
37
from bzrlib.trace import note
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
38
2018.5.25 by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts).
39
# Note: RemoteBzrDirFormat is in bzrdir.py
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
40
41
class RemoteBzrDir(BzrDir):
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
42
    """Control directory on a remote server, accessed via bzr:// or similar."""
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
43
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
44
    def __init__(self, transport, _client=None):
45
        """Construct a RemoteBzrDir.
46
47
        :param _client: Private parameter for testing. Disables probing and the
48
            use of a real bzrdir.
49
        """
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
50
        BzrDir.__init__(self, transport, RemoteBzrDirFormat())
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
51
        # this object holds a delegated bzrdir that uses file-level operations
52
        # to talk to the other side
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
53
        self._real_bzrdir = None
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
54
55
        if _client is None:
2485.8.54 by Vincent Ladeuil
Refactor medium uses by making a distinction betweem shared and real medium.
56
            self._shared_medium = transport.get_shared_medium()
57
            self._client = client._SmartClient(self._shared_medium)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
58
        else:
59
            self._client = _client
2485.8.54 by Vincent Ladeuil
Refactor medium uses by making a distinction betweem shared and real medium.
60
            self._shared_medium = None
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
61
            return
62
63
        path = self._path_for_remote_call(self._client)
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
64
        response = self._client.call('BzrDir.open', path)
65
        if response not in [('yes',), ('no',)]:
66
            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.
67
        if response == ('no',):
68
            raise errors.NotBranchError(path=transport.base)
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
69
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
70
    def _ensure_real(self):
71
        """Ensure that there is a _real_bzrdir set.
72
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
73
        Used before calls to self._real_bzrdir.
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
74
        """
75
        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.
76
            self._real_bzrdir = BzrDir.open_from_transport(
77
                self.root_transport, _server_formats=False)
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
78
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
79
    def create_repository(self, shared=False):
2018.5.162 by Andrew Bennetts
Add some missing _ensure_real calls, and a missing import.
80
        self._ensure_real()
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
81
        self._real_bzrdir.create_repository(shared=shared)
82
        return self.open_repository()
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
83
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
84
    def destroy_repository(self):
85
        """See BzrDir.destroy_repository"""
86
        self._ensure_real()
87
        self._real_bzrdir.destroy_repository()
88
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
89
    def create_branch(self):
2018.5.162 by Andrew Bennetts
Add some missing _ensure_real calls, and a missing import.
90
        self._ensure_real()
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
91
        real_branch = self._real_bzrdir.create_branch()
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
92
        return RemoteBranch(self, self.find_repository(), real_branch)
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
93
2796.2.6 by Aaron Bentley
Implement destroy_branch
94
    def destroy_branch(self):
2796.2.16 by Aaron Bentley
Documentation updates from review
95
        """See BzrDir.destroy_branch"""
2796.2.6 by Aaron Bentley
Implement destroy_branch
96
        self._ensure_real()
97
        self._real_bzrdir.destroy_branch()
98
2955.5.3 by Vincent Ladeuil
Fix second unwanted connection by providing the right branch to create_checkout.
99
    def create_workingtree(self, revision_id=None, from_branch=None):
2018.5.174 by Andrew Bennetts
Various nits discovered by pyflakes.
100
        raise errors.NotLocalUrl(self.transport.base)
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
101
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.
102
    def find_branch_format(self):
103
        """Find the branch 'format' for this bzrdir.
104
105
        This might be a synthetic object for e.g. RemoteBranch and SVN.
106
        """
107
        b = self.open_branch()
108
        return b._format
109
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.
110
    def get_branch_reference(self):
111
        """See BzrDir.get_branch_reference()."""
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
112
        path = self._path_for_remote_call(self._client)
113
        response = self._client.call('BzrDir.open_branch', path)
114
        if response[0] == 'ok':
115
            if response[1] == '':
116
                # 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.
117
                return None
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
118
            else:
119
                # 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.
120
                return response[1]
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
121
        elif response == ('nobranch',):
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
122
            raise errors.NotBranchError(path=self.root_transport.base)
123
        else:
2555.1.1 by Martin Pool
Remove use of 'assert False' to raise an exception unconditionally
124
            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.
125
126
    def open_branch(self, _unsupported=False):
127
        assert _unsupported == False, 'unsupported flag support not implemented yet.'
128
        reference_url = self.get_branch_reference()
129
        if reference_url is None:
130
            # branch at this location.
131
            return RemoteBranch(self, self.find_repository())
132
        else:
133
            # a branch reference, use the existing BranchReference logic.
134
            format = BranchReferenceFormat()
135
            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.
136
                
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
137
    def open_repository(self):
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
138
        path = self._path_for_remote_call(self._client)
139
        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 :).
140
        assert response[0] in ('ok', 'norepository'), \
2018.5.52 by Wouter van Heyst
Provide more information when encountering unexpected responses from a smart
141
            'unexpected response code %s' % (response,)
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
142
        if response[0] == 'norepository':
143
            raise errors.NoRepositoryPresent(self)
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
144
        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.
145
        if response[1] == '':
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
146
            format = RemoteRepositoryFormat()
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
147
            format.rich_root_data = (response[2] == 'yes')
148
            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.
149
            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.
150
        else:
151
            raise errors.NoRepositoryPresent(self)
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
152
2018.5.138 by Robert Collins
Merge bzr.dev.
153
    def open_workingtree(self, recommend_upgrade=True):
2445.1.1 by Andrew Bennetts
Make RemoteBzrDir.open_workingtree raise NoWorkingTree rather than NotLocalUrl
154
        self._ensure_real()
155
        if self._real_bzrdir.has_workingtree():
156
            raise errors.NotLocalUrl(self.root_transport)
157
        else:
158
            raise errors.NoWorkingTree(self.root_transport.base)
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
159
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
160
    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.
161
        """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 :).
162
        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.
163
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
164
    def get_branch_transport(self, branch_format):
2018.5.162 by Andrew Bennetts
Add some missing _ensure_real calls, and a missing import.
165
        self._ensure_real()
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
166
        return self._real_bzrdir.get_branch_transport(branch_format)
167
1752.2.43 by Andrew Bennetts
Fix get_{branch,repository,workingtree}_transport.
168
    def get_repository_transport(self, repository_format):
2018.5.162 by Andrew Bennetts
Add some missing _ensure_real calls, and a missing import.
169
        self._ensure_real()
1752.2.43 by Andrew Bennetts
Fix get_{branch,repository,workingtree}_transport.
170
        return self._real_bzrdir.get_repository_transport(repository_format)
171
172
    def get_workingtree_transport(self, workingtree_format):
2018.5.162 by Andrew Bennetts
Add some missing _ensure_real calls, and a missing import.
173
        self._ensure_real()
1752.2.43 by Andrew Bennetts
Fix get_{branch,repository,workingtree}_transport.
174
        return self._real_bzrdir.get_workingtree_transport(workingtree_format)
175
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
176
    def can_convert_format(self):
177
        """Upgrading of remote bzrdirs is not supported yet."""
178
        return False
179
180
    def needs_format_conversion(self, format=None):
181
        """Upgrading of remote bzrdirs is not supported yet."""
182
        return False
183
2018.5.138 by Robert Collins
Merge bzr.dev.
184
    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).
185
        self._ensure_real()
186
        return self._real_bzrdir.clone(url, revision_id=revision_id,
2018.5.138 by Robert Collins
Merge bzr.dev.
187
            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).
188
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
189
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
190
class RemoteRepositoryFormat(repository.RepositoryFormat):
2018.5.159 by Andrew Bennetts
Rename SmartClient to _SmartClient.
191
    """Format for repositories accessed over a _SmartClient.
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
192
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
193
    Instances of this repository are represented by RemoteRepository
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
194
    instances.
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
195
3128.1.3 by Vincent Ladeuil
Since we are there s/parameteris.*/parameteriz&/.
196
    The RemoteRepositoryFormat is parameterized during construction
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
197
    to reflect the capabilities of the real, remote format. Specifically
2018.5.138 by Robert Collins
Merge bzr.dev.
198
    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.
199
    on a per instance basis, and are not set (and should not be) at
200
    the class level.
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
201
    """
202
203
    _matchingbzrdir = RemoteBzrDirFormat
204
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
205
    def initialize(self, a_bzrdir, shared=False):
2018.5.138 by Robert Collins
Merge bzr.dev.
206
        assert isinstance(a_bzrdir, RemoteBzrDir), \
207
            '%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.
208
        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.
209
    
210
    def open(self, a_bzrdir):
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
211
        assert isinstance(a_bzrdir, RemoteBzrDir)
212
        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.
213
214
    def get_format_description(self):
215
        return 'bzr remote repository'
216
217
    def __eq__(self, other):
1752.2.87 by Andrew Bennetts
Make tests pass.
218
        return self.__class__ == other.__class__
219
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
220
    def check_conversion_target(self, target_format):
221
        if self.rich_root_data and not target_format.rich_root_data:
222
            raise errors.BadConversionTarget(
223
                'Does not support rich root data.', target_format)
2018.5.138 by Robert Collins
Merge bzr.dev.
224
        if (self.supports_tree_reference and
225
            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.
226
            raise errors.BadConversionTarget(
227
                '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.
228
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
229
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
230
class RemoteRepository(object):
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
231
    """Repository accessed over rpc.
232
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
233
    For the moment most operations are performed using local transport-backed
234
    Repository objects.
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
235
    """
236
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
237
    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.
238
        """Create a RemoteRepository instance.
239
        
240
        :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.
241
        :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.
242
        :param real_repository: If not None, a local implementation of the
243
            repository logic for the repository, usually accessing the data
244
            via the VFS.
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
245
        :param _client: Private testing parameter - override the smart client
246
            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.
247
        """
248
        if real_repository:
2018.5.36 by Andrew Bennetts
Fix typo, and clean up some ununsed import warnings from pyflakes at the same time.
249
            self._real_repository = real_repository
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
250
        else:
251
            self._real_repository = None
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
252
        self.bzrdir = remote_bzrdir
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
253
        if _client is None:
2485.8.54 by Vincent Ladeuil
Refactor medium uses by making a distinction betweem shared and real medium.
254
            self._client = client._SmartClient(self.bzrdir._shared_medium)
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
255
        else:
256
            self._client = _client
2018.5.118 by Robert Collins
Fix RemoteRepositoryFormat to have appropriate rich_root_data and support_tree_reference.
257
        self._format = format
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
258
        self._lock_mode = None
259
        self._lock_token = None
260
        self._lock_count = 0
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
261
        self._leave_lock = False
2951.1.10 by Robert Collins
Peer review feedback with Ian.
262
        # For tests:
263
        # These depend on the actual remote format, so force them off for
264
        # maximum compatibility. XXX: In future these should depend on the
265
        # remote repository instance, but this is irrelevant until we perform
266
        # reconcile via an RPC call.
2951.1.5 by Robert Collins
Some work towards including the correct changes for TREE_ROOT in check parameterised tests.
267
        self._reconcile_does_inventory_gc = False
268
        self._reconcile_fixes_text_parents = False
2951.1.3 by Robert Collins
Partial support for native reconcile with packs.
269
        self._reconcile_backsup_inventory = False
2592.4.5 by Martin Pool
Add Repository.base on all repositories.
270
        self.base = self.bzrdir.transport.base
271
272
    def __str__(self):
273
        return "%s(%s)" % (self.__class__.__name__, self.base)
274
275
    __repr__ = __str__
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
276
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
277
    def abort_write_group(self):
2617.6.7 by Robert Collins
More review feedback.
278
        """Complete a write group on the decorated repository.
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
279
        
280
        Smart methods peform operations in a single step so this api
2617.6.6 by Robert Collins
Some review feedback.
281
        is not really applicable except as a compatibility thunk
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
282
        for older plugins that don't use e.g. the CommitBuilder
283
        facility.
284
        """
285
        self._ensure_real()
286
        return self._real_repository.abort_write_group()
287
288
    def commit_write_group(self):
2617.6.7 by Robert Collins
More review feedback.
289
        """Complete a write group on the decorated repository.
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
290
        
291
        Smart methods peform operations in a single step so this api
2617.6.6 by Robert Collins
Some review feedback.
292
        is not really applicable except as a compatibility thunk
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
293
        for older plugins that don't use e.g. the CommitBuilder
294
        facility.
295
        """
296
        self._ensure_real()
297
        return self._real_repository.commit_write_group()
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
298
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
299
    def _ensure_real(self):
300
        """Ensure that there is a _real_repository set.
301
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
302
        Used before calls to self._real_repository.
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
303
        """
304
        if not self._real_repository:
305
            self.bzrdir._ensure_real()
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
306
            #self._real_repository = self.bzrdir._real_bzrdir.open_repository()
307
            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.
308
2988.1.2 by Robert Collins
New Repository API find_text_key_references for use by reconcile and check.
309
    def find_text_key_references(self):
310
        """Find the text key references within the repository.
311
312
        :return: a dictionary mapping (file_id, revision_id) tuples to altered file-ids to an iterable of
313
        revision_ids. Each altered file-ids has the exact revision_ids that
314
        altered it listed explicitly.
315
        :return: A dictionary mapping text keys ((fileid, revision_id) tuples)
316
            to whether they were referred to by the inventory of the
317
            revision_id that they contain. The inventory texts from all present
318
            revision ids are assessed to generate this report.
319
        """
320
        self._ensure_real()
321
        return self._real_repository.find_text_key_references()
322
2988.1.3 by Robert Collins
Add a new repositoy method _generate_text_key_index for use by reconcile/check.
323
    def _generate_text_key_index(self):
324
        """Generate a new text key index for the repository.
325
326
        This is an expensive function that will take considerable time to run.
327
328
        :return: A dict mapping (file_id, revision_id) tuples to a list of
329
            parents, also (file_id, revision_id) tuples.
330
        """
331
        self._ensure_real()
332
        return self._real_repository._generate_text_key_index()
333
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
334
    def get_revision_graph(self, revision_id=None):
335
        """See Repository.get_revision_graph()."""
336
        if revision_id is None:
337
            revision_id = ''
2948.3.1 by John Arbash Meinel
Fix bug #158333, make sure that Repository.fetch(self) is properly a no-op for all Repository implementations.
338
        elif revision.is_null(revision_id):
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
339
            return {}
340
341
        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.
342
        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.
343
        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.
344
            'Repository.get_revision_graph', path, revision_id)
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
345
        if response[0][0] not in ['ok', 'nosuchrevision']:
346
            raise errors.UnexpectedSmartServerResponse(response[0])
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
347
        if response[0][0] == 'ok':
348
            coded = response[1].read_body_bytes()
2018.5.105 by Andrew Bennetts
Implement revision_history caching for RemoteBranch.
349
            if coded == '':
350
                # no revisions in this repository!
351
                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.
352
            lines = coded.split('\n')
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
353
            revision_graph = {}
354
            for line in lines:
2625.8.1 by Robert Collins
LIBRARY API BREAKS:
355
                d = tuple(line.split())
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
356
                revision_graph[d[0]] = d[1:]
357
                
358
            return revision_graph
359
        else:
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
360
            response_body = response[1].read_body_bytes()
361
            assert response_body == ''
2018.5.67 by Wouter van Heyst
Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)
362
            raise NoSuchRevision(self, revision_id)
363
2018.5.40 by Robert Collins
Implement a remote Repository.has_revision method.
364
    def has_revision(self, revision_id):
365
        """See Repository.has_revision()."""
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
366
        if revision_id is None:
367
            # The null revision is always present.
368
            return True
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
369
        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.
370
        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.
371
        assert response[0] in ('yes', 'no'), 'unexpected response code %s' % (response,)
372
        return response[0] == 'yes'
2018.5.40 by Robert Collins
Implement a remote Repository.has_revision method.
373
2617.6.9 by Robert Collins
Merge bzr.dev.
374
    def has_same_location(self, other):
2592.3.162 by Robert Collins
Remove some arbitrary differences from bzr.dev.
375
        return (self.__class__ == other.__class__ and
376
                self.bzrdir.transport.base == other.bzrdir.transport.base)
2617.6.9 by Robert Collins
Merge bzr.dev.
377
        
2490.2.21 by Aaron Bentley
Rename graph to deprecated_graph
378
    def get_graph(self, other_repository=None):
379
        """Return the graph for this repository format"""
2850.4.1 by Andrew Bennetts
Add smoketest for repo.get_graph, and fix bug in RemoteRepository.get_graph that it reveals.
380
        self._ensure_real()
2490.2.21 by Aaron Bentley
Rename graph to deprecated_graph
381
        return self._real_repository.get_graph(other_repository)
2490.2.5 by Aaron Bentley
Use GraphWalker.unique_ancestor to determine merge base
382
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
383
    def gather_stats(self, revid=None, committers=None):
2018.5.62 by Robert Collins
Stub out RemoteRepository.gather_stats while its implemented in parallel.
384
        """See Repository.gather_stats()."""
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
385
        path = self.bzrdir._path_for_remote_call(self._client)
2948.3.4 by John Arbash Meinel
Repository.gather_stats() validly can get None for the revid.
386
        # revid can be None to indicate no revisions, not just NULL_REVISION
387
        if revid is None or revision.is_null(revid):
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
388
            fmt_revid = ''
389
        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.
390
            fmt_revid = revid
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
391
        if committers is None or not committers:
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
392
            fmt_committers = 'no'
393
        else:
394
            fmt_committers = 'yes'
2018.5.153 by Andrew Bennetts
Rename call2 to call_expecting_body, and other small changes prompted by review.
395
        response = self._client.call_expecting_body(
396
            'Repository.gather_stats', path, fmt_revid, fmt_committers)
2018.10.3 by v.ladeuil+lp at free
more tests for gather_stats
397
        assert response[0][0] == 'ok', \
398
            'unexpected response code %s' % (response[0],)
399
400
        body = response[1].read_body_bytes()
401
        result = {}
402
        for line in body.split('\n'):
403
            if not line:
404
                continue
405
            key, val_text = line.split(':')
406
            if key in ('revisions', 'size', 'committers'):
407
                result[key] = int(val_text)
408
            elif key in ('firstrev', 'latestrev'):
409
                values = val_text.split(' ')[1:]
410
                result[key] = (float(values[0]), long(values[1]))
411
412
        return result
2018.5.62 by Robert Collins
Stub out RemoteRepository.gather_stats while its implemented in parallel.
413
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
414
    def find_branches(self, using=False):
415
        """See Repository.find_branches()."""
416
        # should be an API call to the server.
417
        self._ensure_real()
418
        return self._real_repository.find_branches(using=using)
419
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
420
    def get_physical_lock_status(self):
421
        """See Repository.get_physical_lock_status()."""
3015.2.10 by Robert Collins
Fix regression due to other pack related fixes in tests with packs not-default.
422
        # should be an API call to the server.
423
        self._ensure_real()
424
        return self._real_repository.get_physical_lock_status()
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
425
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
426
    def is_in_write_group(self):
427
        """Return True if there is an open write group.
428
429
        write groups are only applicable locally for the smart server..
430
        """
431
        if self._real_repository:
432
            return self._real_repository.is_in_write_group()
433
434
    def is_locked(self):
435
        return self._lock_count >= 1
436
2018.5.57 by Robert Collins
Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).
437
    def is_shared(self):
438
        """See Repository.is_shared()."""
439
        path = self.bzrdir._path_for_remote_call(self._client)
440
        response = self._client.call('Repository.is_shared', path)
441
        assert response[0] in ('yes', 'no'), 'unexpected response code %s' % (response,)
442
        return response[0] == 'yes'
443
2904.1.1 by Robert Collins
* New method ``bzrlib.repository.Repository.is_write_locked`` useful for
444
    def is_write_locked(self):
445
        return self._lock_mode == 'w'
446
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
447
    def lock_read(self):
448
        # wrong eventually - want a local lock cache context
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
449
        if not self._lock_mode:
450
            self._lock_mode = 'r'
451
            self._lock_count = 1
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
452
            if self._real_repository is not None:
453
                self._real_repository.lock_read()
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
454
        else:
455
            self._lock_count += 1
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
456
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
457
    def _remote_lock_write(self, token):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
458
        path = self.bzrdir._path_for_remote_call(self._client)
459
        if token is None:
460
            token = ''
461
        response = self._client.call('Repository.lock_write', path, token)
462
        if response[0] == 'ok':
463
            ok, token = response
464
            return token
465
        elif response[0] == 'LockContention':
466
            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.
467
        elif response[0] == 'UnlockableTransport':
468
            raise errors.UnlockableTransport(self.bzrdir.root_transport)
2872.5.3 by Martin Pool
Pass back LockFailed from smart server lock methods
469
        elif response[0] == 'LockFailed':
470
            raise errors.LockFailed(response[1], response[2])
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
471
        else:
2555.1.1 by Martin Pool
Remove use of 'assert False' to raise an exception unconditionally
472
            raise errors.UnexpectedSmartServerResponse(response)
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
473
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
474
    def lock_write(self, token=None):
475
        if not self._lock_mode:
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
476
            self._lock_token = self._remote_lock_write(token)
3015.2.9 by Robert Collins
Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.
477
            # if self._lock_token is None, then this is something like packs or
478
            # svn where we don't get to lock the repo, or a weave style repository
479
            # where we cannot lock it over the wire and attempts to do so will
480
            # fail.
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
481
            if self._real_repository is not None:
482
                self._real_repository.lock_write(token=self._lock_token)
483
            if token is not None:
484
                self._leave_lock = True
485
            else:
486
                self._leave_lock = False
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
487
            self._lock_mode = 'w'
488
            self._lock_count = 1
489
        elif self._lock_mode == 'r':
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
490
            raise errors.ReadOnlyError(self)
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
491
        else:
492
            self._lock_count += 1
3015.2.9 by Robert Collins
Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.
493
        return self._lock_token or None
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
494
495
    def leave_lock_in_place(self):
3015.2.9 by Robert Collins
Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.
496
        if not self._lock_token:
497
            raise NotImplementedError(self.leave_lock_in_place)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
498
        self._leave_lock = True
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
499
500
    def dont_leave_lock_in_place(self):
3015.2.9 by Robert Collins
Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.
501
        if not self._lock_token:
3015.2.15 by Robert Collins
Review feedback.
502
            raise NotImplementedError(self.dont_leave_lock_in_place)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
503
        self._leave_lock = False
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
504
505
    def _set_real_repository(self, repository):
506
        """Set the _real_repository for this repository.
507
508
        :param repository: The repository to fallback to for non-hpss
509
            implemented operations.
510
        """
2018.5.97 by Andrew Bennetts
Fix more tests.
511
        assert not isinstance(repository, RemoteRepository)
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
512
        self._real_repository = repository
513
        if self._lock_mode == 'w':
514
            # if we are already locked, the real repository must be able to
515
            # acquire the lock with our token.
516
            self._real_repository.lock_write(self._lock_token)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
517
        elif self._lock_mode == 'r':
518
            self._real_repository.lock_read()
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
519
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
520
    def start_write_group(self):
521
        """Start a write group on the decorated repository.
522
        
523
        Smart methods peform operations in a single step so this api
2617.6.6 by Robert Collins
Some review feedback.
524
        is not really applicable except as a compatibility thunk
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
525
        for older plugins that don't use e.g. the CommitBuilder
526
        facility.
527
        """
528
        self._ensure_real()
529
        return self._real_repository.start_write_group()
530
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
531
    def _unlock(self, token):
532
        path = self.bzrdir._path_for_remote_call(self._client)
3015.2.9 by Robert Collins
Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.
533
        if not token:
534
            # with no token the remote repository is not persistently locked.
535
            return
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
536
        response = self._client.call('Repository.unlock', path, token)
537
        if response == ('ok',):
538
            return
539
        elif response[0] == 'TokenMismatch':
540
            raise errors.TokenMismatch(token, '(remote token)')
541
        else:
2555.1.1 by Martin Pool
Remove use of 'assert False' to raise an exception unconditionally
542
            raise errors.UnexpectedSmartServerResponse(response)
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
543
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
544
    def unlock(self):
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
545
        self._lock_count -= 1
2592.3.244 by Martin Pool
unlock while in a write group now aborts the write group, unlocks, and errors.
546
        if self._lock_count > 0:
547
            return
548
        old_mode = self._lock_mode
549
        self._lock_mode = None
550
        try:
551
            # The real repository is responsible at present for raising an
552
            # exception if it's in an unfinished write group.  However, it
553
            # normally will *not* actually remove the lock from disk - that's
554
            # done by the server on receiving the Repository.unlock call.
555
            # This is just to let the _real_repository stay up to date.
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
556
            if self._real_repository is not None:
557
                self._real_repository.unlock()
2592.3.244 by Martin Pool
unlock while in a write group now aborts the write group, unlocks, and errors.
558
        finally:
559
            # The rpc-level lock should be released even if there was a
560
            # problem releasing the vfs-based lock.
561
            if old_mode == 'w':
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
562
                # Only write-locked repositories need to make a remote method
563
                # call to perfom the unlock.
2592.3.244 by Martin Pool
unlock while in a write group now aborts the write group, unlocks, and errors.
564
                old_token = self._lock_token
565
                self._lock_token = None
566
                if not self._leave_lock:
567
                    self._unlock(old_token)
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
568
569
    def break_lock(self):
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
570
        # should hand off to the network
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
571
        self._ensure_real()
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
572
        return self._real_repository.break_lock()
573
2018.18.8 by Ian Clatworthy
Tarball proxy code & tests
574
    def _get_tarball(self, compression):
2814.10.2 by Andrew Bennetts
Make the fallback a little tidier.
575
        """Return a TemporaryFile containing a repository tarball.
576
        
577
        Returns None if the server does not support sending tarballs.
578
        """
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
579
        import tempfile
2018.18.8 by Ian Clatworthy
Tarball proxy code & tests
580
        path = self.bzrdir._path_for_remote_call(self._client)
2018.18.14 by Martin Pool
merge hpss again; restore incorrectly removed RemoteRepository.break_lock
581
        response, protocol = self._client.call_expecting_body(
582
            'Repository.tarball', path, compression)
2018.18.8 by Ian Clatworthy
Tarball proxy code & tests
583
        if response[0] == 'ok':
584
            # Extract the tarball and return it
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
585
            t = tempfile.NamedTemporaryFile()
586
            # TODO: rpc layer should read directly into it...
587
            t.write(protocol.read_body_bytes())
588
            t.seek(0)
589
            return t
2814.10.1 by Andrew Bennetts
Cope gracefully if the server doesn't support the Repository.tarball smart request.
590
        if (response == ('error', "Generic bzr smart protocol error: "
591
                "bad request 'Repository.tarball'") or
592
              response == ('error', "Generic bzr smart protocol error: "
593
                "bad request u'Repository.tarball'")):
594
            protocol.cancel_read_body()
2814.10.2 by Andrew Bennetts
Make the fallback a little tidier.
595
            return None
2814.10.1 by Andrew Bennetts
Cope gracefully if the server doesn't support the Repository.tarball smart request.
596
        raise errors.UnexpectedSmartServerResponse(response)
2018.18.8 by Ian Clatworthy
Tarball proxy code & tests
597
2440.1.1 by Martin Pool
Add new Repository.sprout,
598
    def sprout(self, to_bzrdir, revision_id=None):
599
        # TODO: Option to control what format is created?
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
600
        self._ensure_real()
3047.1.4 by Andrew Bennetts
Simplify RemoteRepository.sprout thanks to review comments.
601
        dest_repo = self._real_repository._format.initialize(to_bzrdir,
602
                                                             shared=False)
2535.3.17 by Andrew Bennetts
[broken] Closer to a working Repository.fetch_revisions smart request.
603
        dest_repo.fetch(self, revision_id=revision_id)
604
        return dest_repo
2440.1.1 by Martin Pool
Add new Repository.sprout,
605
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
606
    ### These methods are just thin shims to the VFS object for now.
607
608
    def revision_tree(self, revision_id):
609
        self._ensure_real()
610
        return self._real_repository.revision_tree(revision_id)
611
2520.4.113 by Aaron Bentley
Avoid peeking at Repository._serializer
612
    def get_serializer_format(self):
613
        self._ensure_real()
614
        return self._real_repository.get_serializer_format()
615
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
616
    def get_commit_builder(self, branch, parents, config, timestamp=None,
617
                           timezone=None, committer=None, revprops=None,
618
                           revision_id=None):
619
        # FIXME: It ought to be possible to call this without immediately
620
        # triggering _ensure_real.  For now it's the easiest thing to do.
621
        self._ensure_real()
622
        builder = self._real_repository.get_commit_builder(branch, parents,
623
                config, timestamp=timestamp, timezone=timezone,
624
                committer=committer, revprops=revprops, revision_id=revision_id)
625
        return builder
626
627
    @needs_write_lock
628
    def add_inventory(self, revid, inv, parents):
629
        self._ensure_real()
630
        return self._real_repository.add_inventory(revid, inv, parents)
631
632
    @needs_write_lock
633
    def add_revision(self, rev_id, rev, inv=None, config=None):
634
        self._ensure_real()
635
        return self._real_repository.add_revision(
636
            rev_id, rev, inv=inv, config=config)
637
638
    @needs_read_lock
639
    def get_inventory(self, revision_id):
640
        self._ensure_real()
641
        return self._real_repository.get_inventory(revision_id)
642
3169.2.1 by Robert Collins
New method ``iter_inventories`` on Repository for access to many
643
    def iter_inventories(self, revision_ids):
644
        self._ensure_real()
645
        return self._real_repository.iter_inventories(revision_ids)
646
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
647
    @needs_read_lock
648
    def get_revision(self, revision_id):
649
        self._ensure_real()
650
        return self._real_repository.get_revision(revision_id)
651
652
    @property
653
    def weave_store(self):
654
        self._ensure_real()
655
        return self._real_repository.weave_store
656
657
    def get_transaction(self):
658
        self._ensure_real()
659
        return self._real_repository.get_transaction()
660
661
    @needs_read_lock
2018.5.138 by Robert Collins
Merge bzr.dev.
662
    def clone(self, a_bzrdir, revision_id=None):
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
663
        self._ensure_real()
2018.5.138 by Robert Collins
Merge bzr.dev.
664
        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.
665
666
    def make_working_trees(self):
2018.5.120 by Robert Collins
The Repository API ``make_working_trees`` is now permitted to return
667
        """RemoteRepositories never create working trees by default."""
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
668
        return False
669
670
    def fetch(self, source, revision_id=None, pb=None):
2881.4.1 by Robert Collins
Move responsibility for detecting same-repo fetching from the
671
        if self.has_same_location(source):
672
            # check that last_revision is in 'from' and then return a
673
            # no-operation.
674
            if (revision_id is not None and
2948.3.1 by John Arbash Meinel
Fix bug #158333, make sure that Repository.fetch(self) is properly a no-op for all Repository implementations.
675
                not revision.is_null(revision_id)):
2881.4.1 by Robert Collins
Move responsibility for detecting same-repo fetching from the
676
                self.get_revision(revision_id)
2592.4.5 by Martin Pool
Add Repository.base on all repositories.
677
            return 0, []
2592.3.119 by Robert Collins
Merge some test fixes from Martin.
678
        self._ensure_real()
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
679
        return self._real_repository.fetch(
680
            source, revision_id=revision_id, pb=pb)
681
2520.4.54 by Aaron Bentley
Hang a create_bundle method off repository
682
    def create_bundle(self, target, base, fileobj, format=None):
683
        self._ensure_real()
684
        self._real_repository.create_bundle(target, base, fileobj, format)
685
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
686
    @property
687
    def control_weaves(self):
688
        self._ensure_real()
689
        return self._real_repository.control_weaves
690
691
    @needs_read_lock
2530.1.1 by Aaron Bentley
Make topological sorting optional for get_ancestry
692
    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.
693
        self._ensure_real()
2530.1.1 by Aaron Bentley
Make topological sorting optional for get_ancestry
694
        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.
695
696
    @needs_read_lock
697
    def get_inventory_weave(self):
698
        self._ensure_real()
699
        return self._real_repository.get_inventory_weave()
700
701
    def fileids_altered_by_revision_ids(self, revision_ids):
702
        self._ensure_real()
703
        return self._real_repository.fileids_altered_by_revision_ids(revision_ids)
704
3036.1.3 by Robert Collins
Privatise VersionedFileChecker.
705
    def _get_versioned_file_checker(self, revisions, revision_versions_cache):
2745.6.1 by Aaron Bentley
Initial checking of knit graphs
706
        self._ensure_real()
3036.1.3 by Robert Collins
Privatise VersionedFileChecker.
707
        return self._real_repository._get_versioned_file_checker(
2745.6.50 by Andrew Bennetts
Remove find_bad_ancestors; it's not needed anymore.
708
            revisions, revision_versions_cache)
709
        
2708.1.7 by Aaron Bentley
Rename extract_files_bytes to iter_files_bytes
710
    def iter_files_bytes(self, desired_files):
2708.1.9 by Aaron Bentley
Clean-up docs and imports
711
        """See Repository.iter_file_bytes.
2708.1.3 by Aaron Bentley
Implement extract_files_bytes on Repository
712
        """
713
        self._ensure_real()
2708.1.7 by Aaron Bentley
Rename extract_files_bytes to iter_files_bytes
714
        return self._real_repository.iter_files_bytes(desired_files)
2708.1.3 by Aaron Bentley
Implement extract_files_bytes on Repository
715
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
716
    @needs_read_lock
717
    def get_signature_text(self, revision_id):
718
        self._ensure_real()
719
        return self._real_repository.get_signature_text(revision_id)
720
721
    @needs_read_lock
722
    def get_revision_graph_with_ghosts(self, revision_ids=None):
723
        self._ensure_real()
724
        return self._real_repository.get_revision_graph_with_ghosts(
725
            revision_ids=revision_ids)
726
727
    @needs_read_lock
728
    def get_inventory_xml(self, revision_id):
729
        self._ensure_real()
730
        return self._real_repository.get_inventory_xml(revision_id)
731
732
    def deserialise_inventory(self, revision_id, xml):
733
        self._ensure_real()
734
        return self._real_repository.deserialise_inventory(revision_id, xml)
735
736
    def reconcile(self, other=None, thorough=False):
737
        self._ensure_real()
738
        return self._real_repository.reconcile(other=other, thorough=thorough)
739
        
740
    def all_revision_ids(self):
741
        self._ensure_real()
742
        return self._real_repository.all_revision_ids()
743
    
744
    @needs_read_lock
745
    def get_deltas_for_revisions(self, revisions):
746
        self._ensure_real()
747
        return self._real_repository.get_deltas_for_revisions(revisions)
748
749
    @needs_read_lock
750
    def get_revision_delta(self, revision_id):
751
        self._ensure_real()
752
        return self._real_repository.get_revision_delta(revision_id)
753
754
    @needs_read_lock
755
    def revision_trees(self, revision_ids):
756
        self._ensure_real()
757
        return self._real_repository.revision_trees(revision_ids)
758
759
    @needs_read_lock
760
    def get_revision_reconcile(self, revision_id):
761
        self._ensure_real()
762
        return self._real_repository.get_revision_reconcile(revision_id)
763
764
    @needs_read_lock
2745.6.36 by Andrew Bennetts
Deprecate revision_ids arg to Repository.check and other tweaks.
765
    def check(self, revision_ids=None):
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
766
        self._ensure_real()
2745.6.36 by Andrew Bennetts
Deprecate revision_ids arg to Repository.check and other tweaks.
767
        return self._real_repository.check(revision_ids=revision_ids)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
768
2018.5.138 by Robert Collins
Merge bzr.dev.
769
    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.
770
        self._ensure_real()
771
        return self._real_repository.copy_content_into(
2018.5.138 by Robert Collins
Merge bzr.dev.
772
            destination, revision_id=revision_id)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
773
2814.10.2 by Andrew Bennetts
Make the fallback a little tidier.
774
    def _copy_repository_tarball(self, to_bzrdir, revision_id=None):
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
775
        # get a tarball of the remote repository, and copy from that into the
776
        # destination
777
        from bzrlib import osutils
2018.18.9 by Martin Pool
remote Repository.tarball builds a temporary directory and tars that
778
        import tarfile
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
779
        import tempfile
2018.18.20 by Martin Pool
Route branch operations through remote copy_content_into
780
        # TODO: Maybe a progress bar while streaming the tarball?
781
        note("Copying repository content as tarball...")
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
782
        tar_file = self._get_tarball('bz2')
2814.10.2 by Andrew Bennetts
Make the fallback a little tidier.
783
        if tar_file is None:
784
            return None
785
        destination = to_bzrdir.create_repository()
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
786
        try:
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
787
            tar = tarfile.open('repository', fileobj=tar_file,
788
                mode='r|bz2')
789
            tmpdir = tempfile.mkdtemp()
790
            try:
791
                _extract_tar(tar, tmpdir)
792
                tmp_bzrdir = BzrDir.open(tmpdir)
793
                tmp_repo = tmp_bzrdir.open_repository()
794
                tmp_repo.copy_content_into(destination, revision_id)
795
            finally:
796
                osutils.rmtree(tmpdir)
2018.18.10 by Martin Pool
copy_content_into from Remote repositories by using temporary directories on both ends.
797
        finally:
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
798
            tar_file.close()
2814.10.2 by Andrew Bennetts
Make the fallback a little tidier.
799
        return destination
2018.18.23 by Martin Pool
review cleanups
800
        # TODO: Suggestion from john: using external tar is much faster than
801
        # 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.
802
2604.2.1 by Robert Collins
(robertc) Introduce a pack command.
803
    @needs_write_lock
804
    def pack(self):
805
        """Compress the data within the repository.
806
807
        This is not currently implemented within the smart server.
808
        """
809
        self._ensure_real()
810
        return self._real_repository.pack()
811
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
812
    def set_make_working_trees(self, new_value):
813
        raise NotImplementedError(self.set_make_working_trees)
814
815
    @needs_write_lock
816
    def sign_revision(self, revision_id, gpg_strategy):
817
        self._ensure_real()
818
        return self._real_repository.sign_revision(revision_id, gpg_strategy)
819
820
    @needs_read_lock
821
    def get_revisions(self, revision_ids):
822
        self._ensure_real()
823
        return self._real_repository.get_revisions(revision_ids)
824
825
    def supports_rich_root(self):
2018.5.84 by Andrew Bennetts
Merge in supports-rich-root, another test passing.
826
        self._ensure_real()
827
        return self._real_repository.supports_rich_root()
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
828
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
829
    def iter_reverse_revision_history(self, revision_id):
830
        self._ensure_real()
831
        return self._real_repository.iter_reverse_revision_history(revision_id)
832
2018.5.96 by Andrew Bennetts
Merge from bzr.dev, resolving the worst of the semantic conflicts, but there's
833
    @property
834
    def _serializer(self):
835
        self._ensure_real()
836
        return self._real_repository._serializer
837
2018.5.97 by Andrew Bennetts
Fix more tests.
838
    def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
839
        self._ensure_real()
840
        return self._real_repository.store_revision_signature(
841
            gpg_strategy, plaintext, revision_id)
842
2996.2.8 by Aaron Bentley
Fix add_signature discrepancies
843
    def add_signature_text(self, revision_id, signature):
2996.2.3 by Aaron Bentley
Add tests for install_revisions and add_signature
844
        self._ensure_real()
2996.2.8 by Aaron Bentley
Fix add_signature discrepancies
845
        return self._real_repository.add_signature_text(revision_id, signature)
2996.2.3 by Aaron Bentley
Add tests for install_revisions and add_signature
846
2018.5.97 by Andrew Bennetts
Fix more tests.
847
    def has_signature_for_revision_id(self, revision_id):
848
        self._ensure_real()
849
        return self._real_repository.has_signature_for_revision_id(revision_id)
850
2535.3.12 by Andrew Bennetts
Add a first cut of a get_data_stream method to Repository.
851
    def get_data_stream(self, revision_ids):
2535.4.29 by Andrew Bennetts
Add a new smart method, Repository.stream_revisions_chunked, rather than changing the behaviour of an existing method.
852
        REQUEST_NAME = 'Repository.stream_revisions_chunked'
2535.3.15 by Andrew Bennetts
Add KnitVersionedFile.get_stream_as_bytes, start smart implementation of RemoteRepository.get_data_stream.
853
        path = self.bzrdir._path_for_remote_call(self._client)
854
        response, protocol = self._client.call_expecting_body(
2535.4.21 by Andrew Bennetts
Rename smart request, to avoid confusion with non-chunked version merged into bzr.dev.
855
            REQUEST_NAME, path, *revision_ids)
2535.4.2 by Andrew Bennetts
Nasty hackery to make stream_knit_data_for_revisions response use streaming.
856
2535.3.39 by Andrew Bennetts
Tidy some XXXs.
857
        if response == ('ok',):
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
858
            return self._deserialise_stream(protocol)
859
        elif (response == ('error', "Generic bzr smart protocol error: "
2535.4.21 by Andrew Bennetts
Rename smart request, to avoid confusion with non-chunked version merged into bzr.dev.
860
                "bad request '%s'" % REQUEST_NAME) or
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
861
              response == ('error', "Generic bzr smart protocol error: "
2535.4.21 by Andrew Bennetts
Rename smart request, to avoid confusion with non-chunked version merged into bzr.dev.
862
                "bad request u'%s'" % REQUEST_NAME)):
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
863
            protocol.cancel_read_body()
864
            self._ensure_real()
865
            return self._real_repository.get_data_stream(revision_ids)
2535.3.15 by Andrew Bennetts
Add KnitVersionedFile.get_stream_as_bytes, start smart implementation of RemoteRepository.get_data_stream.
866
        else:
2535.3.17 by Andrew Bennetts
[broken] Closer to a working Repository.fetch_revisions smart request.
867
            raise errors.UnexpectedSmartServerResponse(response)
2535.3.15 by Andrew Bennetts
Add KnitVersionedFile.get_stream_as_bytes, start smart implementation of RemoteRepository.get_data_stream.
868
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
869
    def _deserialise_stream(self, protocol):
2535.4.11 by Andrew Bennetts
Merge from repo-refactor.
870
        stream = protocol.read_streamed_body()
2535.4.15 by Andrew Bennetts
Remove 'PackSource' hack by using the ContainerPushParser.
871
        container_parser = ContainerPushParser()
872
        for bytes in stream:
873
            container_parser.accept_bytes(bytes)
874
            records = container_parser.read_pending_records()
875
            for record_names, record_bytes in records:
2535.4.31 by Andrew Bennetts
Tweak in response to review comments.
876
                if len(record_names) != 1:
2535.4.15 by Andrew Bennetts
Remove 'PackSource' hack by using the ContainerPushParser.
877
                    # These records should have only one name, and that name
878
                    # should be a one-element tuple.
879
                    raise errors.SmartProtocolError(
880
                        'Repository data stream had invalid record name %r'
881
                        % (record_names,))
2535.4.31 by Andrew Bennetts
Tweak in response to review comments.
882
                name_tuple = record_names[0]
2535.4.15 by Andrew Bennetts
Remove 'PackSource' hack by using the ContainerPushParser.
883
                yield name_tuple, record_bytes
2535.3.68 by Andrew Bennetts
Backwards compatibility for new smart method.
884
2535.3.17 by Andrew Bennetts
[broken] Closer to a working Repository.fetch_revisions smart request.
885
    def insert_data_stream(self, stream):
886
        self._ensure_real()
887
        self._real_repository.insert_data_stream(stream)
2535.3.12 by Andrew Bennetts
Add a first cut of a get_data_stream method to Repository.
888
2535.3.45 by Andrew Bennetts
Add item_keys_introduced_by to RemoteRepository.
889
    def item_keys_introduced_by(self, revision_ids, _files_pb=None):
890
        self._ensure_real()
891
        return self._real_repository.item_keys_introduced_by(revision_ids,
892
            _files_pb=_files_pb)
893
2819.2.4 by Andrew Bennetts
Add a 'revision_graph_can_have_wrong_parents' method to repository.
894
    def revision_graph_can_have_wrong_parents(self):
895
        # The answer depends on the remote repo format.
896
        self._ensure_real()
897
        return self._real_repository.revision_graph_can_have_wrong_parents()
898
2819.2.5 by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents.
899
    def _find_inconsistent_revision_parents(self):
900
        self._ensure_real()
901
        return self._real_repository._find_inconsistent_revision_parents()
902
903
    def _check_for_inconsistent_revision_parents(self):
904
        self._ensure_real()
905
        return self._real_repository._check_for_inconsistent_revision_parents()
906
3089.2.1 by Andrew Bennetts
Implement RemoteRepository._make_parents_provider.
907
    def _make_parents_provider(self):
908
        self._ensure_real()
909
        return self._real_repository._make_parents_provider()
910
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
911
2018.5.127 by Andrew Bennetts
Fix most of the lockable_files tests for RemoteBranchLockableFiles.
912
class RemoteBranchLockableFiles(LockableFiles):
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
913
    """A 'LockableFiles' implementation that talks to a smart server.
914
    
915
    This is not a public interface class.
916
    """
917
918
    def __init__(self, bzrdir, _client):
919
        self.bzrdir = bzrdir
920
        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.
921
        self._need_find_modes = True
2018.5.133 by Andrew Bennetts
All TestLockableFiles_RemoteLockDir tests passing.
922
        LockableFiles.__init__(
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
923
            self, bzrdir.get_branch_transport(None),
2018.5.133 by Andrew Bennetts
All TestLockableFiles_RemoteLockDir tests passing.
924
            'lock', lockdir.LockDir)
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
925
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.
926
    def _find_modes(self):
927
        # RemoteBranches don't let the client set the mode of control files.
928
        self._dir_mode = None
929
        self._file_mode = None
930
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
931
    def get(self, path):
932
        """'get' a remote path as per the LockableFiles interface.
933
934
        :param path: the file to 'get'. If this is 'branch.conf', we do not
935
             just retrieve a file, instead we ask the smart server to generate
936
             a configuration for us - which is retrieved as an INI file.
937
        """
2018.5.133 by Andrew Bennetts
All TestLockableFiles_RemoteLockDir tests passing.
938
        if path == 'branch.conf':
939
            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.
940
            response = self._client.call_expecting_body(
941
                'Branch.get_config_file', path)
2018.5.133 by Andrew Bennetts
All TestLockableFiles_RemoteLockDir tests passing.
942
            assert response[0][0] == 'ok', \
943
                'unexpected response code %s' % (response[0],)
944
            return StringIO(response[1].read_body_bytes())
945
        else:
946
            # VFS fallback.
947
            return LockableFiles.get(self, path)
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
948
949
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
950
class RemoteBranchFormat(branch.BranchFormat):
951
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.
952
    def __eq__(self, other):
953
        return (isinstance(other, RemoteBranchFormat) and 
954
            self.__dict__ == other.__dict__)
955
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
956
    def get_format_description(self):
957
        return 'Remote BZR Branch'
958
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
959
    def get_format_string(self):
960
        return 'Remote BZR Branch'
961
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
962
    def open(self, a_bzrdir):
1752.2.72 by Andrew Bennetts
Make Remote* classes in remote.py more consistent and remove some dead code.
963
        assert isinstance(a_bzrdir, RemoteBzrDir)
964
        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.
965
966
    def initialize(self, a_bzrdir):
967
        assert isinstance(a_bzrdir, RemoteBzrDir)
968
        return a_bzrdir.create_branch()
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
969
2696.3.6 by Martin Pool
Mark RemoteBranch as (possibly) supporting tags
970
    def supports_tags(self):
971
        # Remote branches might support tags, but we won't know until we
972
        # access the real remote branch.
973
        return True
974
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
975
976
class RemoteBranch(branch.Branch):
977
    """Branch stored on a server accessed by HPSS RPC.
978
979
    At the moment most operations are mapped down to simple file operations.
980
    """
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
981
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
982
    def __init__(self, remote_bzrdir, remote_repository, real_branch=None,
983
        _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.
984
        """Create a RemoteBranch instance.
985
986
        :param real_branch: An optional local implementation of the branch
987
            format, usually accessing the data via the VFS.
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
988
        :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.
989
        """
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
990
        # We intentionally don't call the parent class's __init__, because it
991
        # will try to assign to self.tags, which is a property in this subclass.
992
        # And the parent's __init__ doesn't do much anyway.
2978.7.1 by John Arbash Meinel
Fix bug #162486, by having RemoteBranch properly initialize self._revision_id_to_revno_map.
993
        self._revision_id_to_revno_cache = None
2018.5.105 by Andrew Bennetts
Implement revision_history caching for RemoteBranch.
994
        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.
995
        self.bzrdir = remote_bzrdir
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
996
        if _client is not None:
997
            self._client = _client
998
        else:
2485.8.54 by Vincent Ladeuil
Refactor medium uses by making a distinction betweem shared and real medium.
999
            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.
1000
        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.
1001
        if real_branch is not None:
1002
            self._real_branch = real_branch
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1003
            # Give the remote repository the matching real repo.
2018.5.97 by Andrew Bennetts
Fix more tests.
1004
            real_repo = self._real_branch.repository
1005
            if isinstance(real_repo, RemoteRepository):
1006
                real_repo._ensure_real()
1007
                real_repo = real_repo._real_repository
1008
            self.repository._set_real_repository(real_repo)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1009
            # Give the branch the remote repository to let fast-pathing happen.
1010
            self._real_branch.repository = self.repository
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
1011
        else:
1012
            self._real_branch = None
2018.5.59 by Robert Collins
Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).
1013
        # 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.
1014
        self._format = RemoteBranchFormat()
2018.5.55 by Robert Collins
Give RemoteBranch a base url in line with the Branch protocol.
1015
        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.
1016
        self._control_files = None
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1017
        self._lock_mode = None
1018
        self._lock_token = None
1019
        self._lock_count = 0
1020
        self._leave_lock = False
1752.2.64 by Andrew Bennetts
Improve how RemoteBzrDir.open_branch works to handle references and not double-open repositories.
1021
2477.1.1 by Martin Pool
Add RemoteBranch repr
1022
    def __str__(self):
1023
        return "%s(%s)" % (self.__class__.__name__, self.base)
1024
1025
    __repr__ = __str__
1026
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
1027
    def _ensure_real(self):
1028
        """Ensure that there is a _real_branch set.
1029
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
1030
        Used before calls to self._real_branch.
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
1031
        """
1032
        if not self._real_branch:
1033
            assert vfs.vfs_enabled()
1034
            self.bzrdir._ensure_real()
1035
            self._real_branch = self.bzrdir._real_bzrdir.open_branch()
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
1036
            # Give the remote repository the matching real repo.
2018.5.97 by Andrew Bennetts
Fix more tests.
1037
            real_repo = self._real_branch.repository
1038
            if isinstance(real_repo, RemoteRepository):
1039
                real_repo._ensure_real()
1040
                real_repo = real_repo._real_repository
1041
            self.repository._set_real_repository(real_repo)
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
1042
            # 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.
1043
            self._real_branch.repository = self.repository
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1044
            # XXX: deal with _lock_mode == 'w'
1045
            if self._lock_mode == 'r':
1046
                self._real_branch.lock_read()
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
1047
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.
1048
    @property
1049
    def control_files(self):
1050
        # Defer actually creating RemoteBranchLockableFiles until its needed,
1051
        # because it triggers an _ensure_real that we otherwise might not need.
1052
        if self._control_files is None:
1053
            self._control_files = RemoteBranchLockableFiles(
1054
                self.bzrdir, self._client)
1055
        return self._control_files
1056
2018.5.166 by Andrew Bennetts
Small changes in response to Aaron's review.
1057
    def _get_checkout_format(self):
1058
        self._ensure_real()
1059
        return self._real_branch._get_checkout_format()
1060
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
1061
    def get_physical_lock_status(self):
1062
        """See Branch.get_physical_lock_status()."""
1063
        # 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.
1064
        self._ensure_real()
2018.5.60 by Robert Collins
More missing methods from RemoteBranch and RemoteRepository to let 'info' get further.
1065
        return self._real_branch.get_physical_lock_status()
1066
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
1067
    def lock_read(self):
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1068
        if not self._lock_mode:
1069
            self._lock_mode = 'r'
1070
            self._lock_count = 1
1071
            if self._real_branch is not None:
1072
                self._real_branch.lock_read()
1073
        else:
1074
            self._lock_count += 1
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1075
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).
1076
    def _remote_lock_write(self, token):
1077
        if token is None:
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1078
            branch_token = repo_token = ''
1079
        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).
1080
            branch_token = token
1081
            repo_token = self.repository.lock_write()
1082
            self.repository.unlock()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1083
        path = self.bzrdir._path_for_remote_call(self._client)
1084
        response = self._client.call('Branch.lock_write', path, branch_token,
3015.2.9 by Robert Collins
Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.
1085
                                     repo_token or '')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1086
        if response[0] == 'ok':
1087
            ok, branch_token, repo_token = response
1088
            return branch_token, repo_token
1089
        elif response[0] == 'LockContention':
1090
            raise errors.LockContention('(remote lock)')
1091
        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).
1092
            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.
1093
        elif response[0] == 'UnlockableTransport':
1094
            raise errors.UnlockableTransport(self.bzrdir.root_transport)
2018.5.123 by Robert Collins
Translate ReadOnlyError in RemoteBranch._remote_lock_write.
1095
        elif response[0] == 'ReadOnlyError':
1096
            raise errors.ReadOnlyError(self)
2872.5.3 by Martin Pool
Pass back LockFailed from smart server lock methods
1097
        elif response[0] == 'LockFailed':
1098
            raise errors.LockFailed(response[1], response[2])
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1099
        else:
2555.1.1 by Martin Pool
Remove use of 'assert False' to raise an exception unconditionally
1100
            raise errors.UnexpectedSmartServerResponse(response)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1101
            
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).
1102
    def lock_write(self, token=None):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1103
        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).
1104
            remote_tokens = self._remote_lock_write(token)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1105
            self._lock_token, self._repo_lock_token = remote_tokens
1106
            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.
1107
            # TODO: We really, really, really don't want to call _ensure_real
1108
            # here, but it's the easiest way to ensure coherency between the
1109
            # state of the RemoteBranch and RemoteRepository objects and the
1110
            # physical locks.  If we don't materialise the real objects here,
1111
            # then getting everything in the right state later is complex, so
1112
            # for now we just do it the lazy way.
1113
            #   -- Andrew Bennetts, 2007-02-22.
1114
            self._ensure_real()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1115
            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).
1116
                self._real_branch.repository.lock_write(
1117
                    token=self._repo_lock_token)
1118
                try:
1119
                    self._real_branch.lock_write(token=self._lock_token)
1120
                finally:
1121
                    self._real_branch.repository.unlock()
1122
            if token is not None:
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1123
                self._leave_lock = True
1124
            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).
1125
                # 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.
1126
                self._leave_lock = False
1127
            self._lock_mode = 'w'
1128
            self._lock_count = 1
1129
        elif self._lock_mode == 'r':
1130
            raise errors.ReadOnlyTransaction
1131
        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).
1132
            if token is not None:
1133
                # A token was given to lock_write, and we're relocking, so check
1134
                # that the given token actually matches the one we already have.
1135
                if token != self._lock_token:
1136
                    raise errors.TokenMismatch(token, self._lock_token)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1137
            self._lock_count += 1
3015.2.9 by Robert Collins
Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.
1138
        return self._lock_token or None
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1139
1140
    def _unlock(self, branch_token, repo_token):
1141
        path = self.bzrdir._path_for_remote_call(self._client)
1142
        response = self._client.call('Branch.unlock', path, branch_token,
3015.2.9 by Robert Collins
Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.
1143
                                     repo_token or '')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1144
        if response == ('ok',):
1145
            return
1146
        elif response[0] == 'TokenMismatch':
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1147
            raise errors.TokenMismatch(
1148
                str((branch_token, repo_token)), '(remote tokens)')
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1149
        else:
2555.1.1 by Martin Pool
Remove use of 'assert False' to raise an exception unconditionally
1150
            raise errors.UnexpectedSmartServerResponse(response)
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
1151
1152
    def unlock(self):
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1153
        self._lock_count -= 1
1154
        if not self._lock_count:
2018.5.105 by Andrew Bennetts
Implement revision_history caching for RemoteBranch.
1155
            self._clear_cached_state()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1156
            mode = self._lock_mode
1157
            self._lock_mode = None
1158
            if self._real_branch is not None:
3015.2.9 by Robert Collins
Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.
1159
                if (not self._leave_lock and mode == 'w' and
1160
                    self._repo_lock_token):
2018.15.1 by Andrew Bennetts
All branch_implementations/test_locking tests passing.
1161
                    # If this RemoteBranch will remove the physical lock for the
1162
                    # repository, make sure the _real_branch doesn't do it
1163
                    # first.  (Because the _real_branch's repository is set to
1164
                    # be the RemoteRepository.)
1165
                    self._real_branch.repository.leave_lock_in_place()
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1166
                self._real_branch.unlock()
1167
            if mode != 'w':
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
1168
                # Only write-locked branched need to make a remote method call
1169
                # to perfom the unlock.
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1170
                return
1171
            assert self._lock_token, 'Locked, but no token!'
1172
            branch_token = self._lock_token
1173
            repo_token = self._repo_lock_token
1174
            self._lock_token = None
1175
            self._repo_lock_token = None
1176
            if not self._leave_lock:
1177
                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.
1178
1179
    def break_lock(self):
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
1180
        self._ensure_real()
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1181
        return self._real_branch.break_lock()
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
1182
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1183
    def leave_lock_in_place(self):
3015.2.9 by Robert Collins
Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.
1184
        if not self._lock_token:
1185
            raise NotImplementedError(self.leave_lock_in_place)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1186
        self._leave_lock = True
1187
1188
    def dont_leave_lock_in_place(self):
3015.2.9 by Robert Collins
Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.
1189
        if not self._lock_token:
3015.2.15 by Robert Collins
Review feedback.
1190
            raise NotImplementedError(self.dont_leave_lock_in_place)
2018.5.79 by Andrew Bennetts
Implement RemoteBranch.lock_write/unlock as smart operations.
1191
        self._leave_lock = False
1192
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
1193
    def last_revision_info(self):
1194
        """See Branch.last_revision_info()."""
1195
        path = self.bzrdir._path_for_remote_call(self._client)
1196
        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
1197
        assert response[0] == 'ok', 'unexpected response code %s' % (response,)
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
1198
        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.
1199
        last_revision = response[2]
2018.5.51 by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info()
1200
        return (revno, last_revision)
1201
2018.5.105 by Andrew Bennetts
Implement revision_history caching for RemoteBranch.
1202
    def _gen_revision_history(self):
1203
        """See Branch._gen_revision_history()."""
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
1204
        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.
1205
        response = self._client.call_expecting_body(
1206
            'Branch.revision_history', path)
1207
        assert response[0][0] == 'ok', ('unexpected response code %s'
1208
                                        % (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.
1209
        result = response[1].read_body_bytes().split('\x00')
2018.5.38 by Robert Collins
Implement RemoteBranch.revision_history().
1210
        if result == ['']:
1211
            return []
1212
        return result
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
1213
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1214
    @needs_write_lock
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1215
    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.
1216
        # Send just the tip revision of the history; the server will generate
1217
        # the full history from that.  If the revision doesn't exist in this
1218
        # branch, NoSuchRevision will be raised.
1219
        path = self.bzrdir._path_for_remote_call(self._client)
1220
        if rev_history == []:
2018.5.170 by Andrew Bennetts
Use 'null:' instead of '' to mean NULL_REVISION on the wire.
1221
            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.
1222
        else:
1223
            rev_id = rev_history[-1]
2418.5.12 by John Arbash Meinel
Move functions from BzrBranch to base Branch object.
1224
        self._clear_cached_state()
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1225
        response = self._client.call('Branch.set_last_revision',
1226
            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.
1227
        if response[0] == 'NoSuchRevision':
1228
            raise NoSuchRevision(self, rev_id)
1229
        else:
1230
            assert response == ('ok',), (
1231
                'unexpected response code %r' % (response,))
2018.5.105 by Andrew Bennetts
Implement revision_history caching for RemoteBranch.
1232
        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.
1233
1234
    def get_parent(self):
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
1235
        self._ensure_real()
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1236
        return self._real_branch.get_parent()
1237
        
1752.2.63 by Andrew Bennetts
Delegate set_parent.
1238
    def set_parent(self, url):
2018.5.70 by Robert Collins
Only try to get real repositories when an operation requires them.
1239
        self._ensure_real()
1752.2.63 by Andrew Bennetts
Delegate set_parent.
1240
        return self._real_branch.set_parent(url)
1241
        
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1242
    def get_config(self):
1243
        return RemoteBranchConfig(self)
1244
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
1245
    def sprout(self, to_bzrdir, revision_id=None):
1246
        # Like Branch.sprout, except that it sprouts a branch in the default
1247
        # format, because RemoteBranches can't be created at arbitrary URLs.
1248
        # XXX: if to_bzrdir is a RemoteBranch, this should perhaps do
1249
        # to_bzrdir.create_branch...
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
1250
        self._ensure_real()
1251
        result = self._real_branch._format.initialize(to_bzrdir)
2018.18.20 by Martin Pool
Route branch operations through remote copy_content_into
1252
        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).
1253
        result.set_parent(self.bzrdir.root_transport.base)
1254
        return result
1255
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1256
    @needs_write_lock
2477.1.2 by Martin Pool
Rename push/pull back to 'run_hooks' (jameinel)
1257
    def pull(self, source, overwrite=False, stop_revision=None,
2477.1.9 by Martin Pool
Review cleanups from John, mostly docs
1258
             **kwargs):
1259
        # FIXME: This asks the real branch to run the hooks, which means
1260
        # they're called with the wrong target branch parameter. 
1261
        # The test suite specifically allows this at present but it should be
1262
        # fixed.  It should get a _override_hook_target branch,
1263
        # as push does.  -- mbp 20070405
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1264
        self._ensure_real()
1265
        self._real_branch.pull(
2477.1.2 by Martin Pool
Rename push/pull back to 'run_hooks' (jameinel)
1266
            source, overwrite=overwrite, stop_revision=stop_revision,
1267
            **kwargs)
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1268
2018.14.3 by Andrew Bennetts
Make a couple more branch_implementations tests pass.
1269
    @needs_read_lock
1270
    def push(self, target, overwrite=False, stop_revision=None):
1271
        self._ensure_real()
2018.5.97 by Andrew Bennetts
Fix more tests.
1272
        return self._real_branch.push(
2477.1.5 by Martin Pool
More cleanups of Branch.push to get the right behaviour with RemoteBranches
1273
            target, overwrite=overwrite, stop_revision=stop_revision,
1274
            _override_hook_source_branch=self)
2018.14.3 by Andrew Bennetts
Make a couple more branch_implementations tests pass.
1275
1276
    def is_locked(self):
1277
        return self._lock_count >= 1
1278
2018.5.83 by Andrew Bennetts
Fix some test failures caused by the switch from unicode to UTF-8-encoded strs for revision IDs.
1279
    def set_last_revision_info(self, revno, revision_id):
1280
        self._ensure_real()
2018.5.105 by Andrew Bennetts
Implement revision_history caching for RemoteBranch.
1281
        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.
1282
        return self._real_branch.set_last_revision_info(revno, revision_id)
1283
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.
1284
    def generate_revision_history(self, revision_id, last_rev=None,
1285
                                  other_branch=None):
1286
        self._ensure_real()
1287
        return self._real_branch.generate_revision_history(
1288
            revision_id, last_rev=last_rev, other_branch=other_branch)
1289
2018.5.96 by Andrew Bennetts
Merge from bzr.dev, resolving the worst of the semantic conflicts, but there's
1290
    @property
1291
    def tags(self):
1292
        self._ensure_real()
1293
        return self._real_branch.tags
1294
2018.5.97 by Andrew Bennetts
Fix more tests.
1295
    def set_push_location(self, location):
1296
        self._ensure_real()
1297
        return self._real_branch.set_push_location(location)
1298
3052.5.4 by John Arbash Meinel
If we are going to overwrite the target, we don't have to do
1299
    def update_revisions(self, other, stop_revision=None, overwrite=False):
2018.5.97 by Andrew Bennetts
Fix more tests.
1300
        self._ensure_real()
1301
        return self._real_branch.update_revisions(
3052.5.4 by John Arbash Meinel
If we are going to overwrite the target, we don't have to do
1302
            other, stop_revision=stop_revision, overwrite=overwrite)
2018.5.97 by Andrew Bennetts
Fix more tests.
1303
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
1304
2018.14.1 by Andrew Bennetts
Update to current hpss branch? Fix lots of test failures.
1305
class RemoteBranchConfig(BranchConfig):
1306
1307
    def username(self):
1308
        self.branch._ensure_real()
1309
        return self.branch._real_branch.get_config().username()
1310
2018.14.2 by Andrew Bennetts
All but one repository_implementation tests for RemoteRepository passing.
1311
    def _get_branch_data_config(self):
1312
        self.branch._ensure_real()
1313
        if self._branch_data_config is None:
1314
            self._branch_data_config = TreeConfig(self.branch._real_branch)
1315
        return self._branch_data_config
1316
2018.18.25 by Martin Pool
Repository.tarball fixes for python2.4
1317
1318
def _extract_tar(tar, to_dir):
1319
    """Extract all the contents of a tarfile object.
1320
1321
    A replacement for extractall, which is not present in python2.4
1322
    """
1323
    for tarinfo in tar:
1324
        tar.extract(tarinfo, to_dir)