/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
# TODO: At some point, handle upgrades by just passing the whole request
 
18
# across to run on the server.
 
19
 
 
20
from cStringIO import StringIO
 
21
 
 
22
from bzrlib import (
 
23
    branch,
 
24
    errors,
 
25
    lockdir,
 
26
    repository,
 
27
)
 
28
from bzrlib.branch import Branch, BranchReferenceFormat
 
29
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
 
30
from bzrlib.config import BranchConfig, TreeConfig
 
31
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
32
from bzrlib.errors import NoSuchRevision
 
33
from bzrlib.lockable_files import LockableFiles
 
34
from bzrlib.pack import ContainerReader
 
35
from bzrlib.revision import NULL_REVISION
 
36
from bzrlib.smart import client, vfs
 
37
from bzrlib.symbol_versioning import (
 
38
    deprecated_method,
 
39
    zero_ninetyone,
 
40
    )
 
41
from bzrlib.trace import note
 
42
 
 
43
# Note: RemoteBzrDirFormat is in bzrdir.py
 
44
 
 
45
class RemoteBzrDir(BzrDir):
 
46
    """Control directory on a remote server, accessed via bzr:// or similar."""
 
47
 
 
48
    def __init__(self, transport, _client=None):
 
49
        """Construct a RemoteBzrDir.
 
50
 
 
51
        :param _client: Private parameter for testing. Disables probing and the
 
52
            use of a real bzrdir.
 
53
        """
 
54
        BzrDir.__init__(self, transport, RemoteBzrDirFormat())
 
55
        # this object holds a delegated bzrdir that uses file-level operations
 
56
        # to talk to the other side
 
57
        self._real_bzrdir = None
 
58
 
 
59
        if _client is None:
 
60
            self._shared_medium = transport.get_shared_medium()
 
61
            self._client = client._SmartClient(self._shared_medium)
 
62
        else:
 
63
            self._client = _client
 
64
            self._shared_medium = None
 
65
            return
 
66
 
 
67
        path = self._path_for_remote_call(self._client)
 
68
        response = self._client.call('BzrDir.open', path)
 
69
        if response not in [('yes',), ('no',)]:
 
70
            raise errors.UnexpectedSmartServerResponse(response)
 
71
        if response == ('no',):
 
72
            raise errors.NotBranchError(path=transport.base)
 
73
 
 
74
    def _ensure_real(self):
 
75
        """Ensure that there is a _real_bzrdir set.
 
76
 
 
77
        Used before calls to self._real_bzrdir.
 
78
        """
 
79
        if not self._real_bzrdir:
 
80
            self._real_bzrdir = BzrDir.open_from_transport(
 
81
                self.root_transport, _server_formats=False)
 
82
 
 
83
    def create_repository(self, shared=False):
 
84
        self._ensure_real()
 
85
        self._real_bzrdir.create_repository(shared=shared)
 
86
        return self.open_repository()
 
87
 
 
88
    def create_branch(self):
 
89
        self._ensure_real()
 
90
        real_branch = self._real_bzrdir.create_branch()
 
91
        return RemoteBranch(self, self.find_repository(), real_branch)
 
92
 
 
93
    def create_workingtree(self, revision_id=None):
 
94
        raise errors.NotLocalUrl(self.transport.base)
 
95
 
 
96
    def find_branch_format(self):
 
97
        """Find the branch 'format' for this bzrdir.
 
98
 
 
99
        This might be a synthetic object for e.g. RemoteBranch and SVN.
 
100
        """
 
101
        b = self.open_branch()
 
102
        return b._format
 
103
 
 
104
    def get_branch_reference(self):
 
105
        """See BzrDir.get_branch_reference()."""
 
106
        path = self._path_for_remote_call(self._client)
 
107
        response = self._client.call('BzrDir.open_branch', path)
 
108
        if response[0] == 'ok':
 
109
            if response[1] == '':
 
110
                # branch at this location.
 
111
                return None
 
112
            else:
 
113
                # a branch reference, use the existing BranchReference logic.
 
114
                return response[1]
 
115
        elif response == ('nobranch',):
 
116
            raise errors.NotBranchError(path=self.root_transport.base)
 
117
        else:
 
118
            raise errors.UnexpectedSmartServerResponse(response)
 
119
 
 
120
    def open_branch(self, _unsupported=False):
 
121
        assert _unsupported == False, 'unsupported flag support not implemented yet.'
 
122
        reference_url = self.get_branch_reference()
 
123
        if reference_url is None:
 
124
            # branch at this location.
 
125
            return RemoteBranch(self, self.find_repository())
 
126
        else:
 
127
            # a branch reference, use the existing BranchReference logic.
 
128
            format = BranchReferenceFormat()
 
129
            return format.open(self, _found=True, location=reference_url)
 
130
                
 
131
    def open_repository(self):
 
132
        path = self._path_for_remote_call(self._client)
 
133
        response = self._client.call('BzrDir.find_repository', path)
 
134
        assert response[0] in ('ok', 'norepository'), \
 
135
            'unexpected response code %s' % (response,)
 
136
        if response[0] == 'norepository':
 
137
            raise errors.NoRepositoryPresent(self)
 
138
        assert len(response) == 4, 'incorrect response length %s' % (response,)
 
139
        if response[1] == '':
 
140
            format = RemoteRepositoryFormat()
 
141
            format.rich_root_data = (response[2] == 'yes')
 
142
            format.supports_tree_reference = (response[3] == 'yes')
 
143
            return RemoteRepository(self, format)
 
144
        else:
 
145
            raise errors.NoRepositoryPresent(self)
 
146
 
 
147
    def open_workingtree(self, recommend_upgrade=True):
 
148
        self._ensure_real()
 
149
        if self._real_bzrdir.has_workingtree():
 
150
            raise errors.NotLocalUrl(self.root_transport)
 
151
        else:
 
152
            raise errors.NoWorkingTree(self.root_transport.base)
 
153
 
 
154
    def _path_for_remote_call(self, client):
 
155
        """Return the path to be used for this bzrdir in a remote call."""
 
156
        return client.remote_path_from_transport(self.root_transport)
 
157
 
 
158
    def get_branch_transport(self, branch_format):
 
159
        self._ensure_real()
 
160
        return self._real_bzrdir.get_branch_transport(branch_format)
 
161
 
 
162
    def get_repository_transport(self, repository_format):
 
163
        self._ensure_real()
 
164
        return self._real_bzrdir.get_repository_transport(repository_format)
 
165
 
 
166
    def get_workingtree_transport(self, workingtree_format):
 
167
        self._ensure_real()
 
168
        return self._real_bzrdir.get_workingtree_transport(workingtree_format)
 
169
 
 
170
    def can_convert_format(self):
 
171
        """Upgrading of remote bzrdirs is not supported yet."""
 
172
        return False
 
173
 
 
174
    def needs_format_conversion(self, format=None):
 
175
        """Upgrading of remote bzrdirs is not supported yet."""
 
176
        return False
 
177
 
 
178
    def clone(self, url, revision_id=None, force_new_repo=False):
 
179
        self._ensure_real()
 
180
        return self._real_bzrdir.clone(url, revision_id=revision_id,
 
181
            force_new_repo=force_new_repo)
 
182
 
 
183
 
 
184
class RemoteRepositoryFormat(repository.RepositoryFormat):
 
185
    """Format for repositories accessed over a _SmartClient.
 
186
 
 
187
    Instances of this repository are represented by RemoteRepository
 
188
    instances.
 
189
 
 
190
    The RemoteRepositoryFormat is parameterised during construction
 
191
    to reflect the capabilities of the real, remote format. Specifically
 
192
    the attributes rich_root_data and supports_tree_reference are set
 
193
    on a per instance basis, and are not set (and should not be) at
 
194
    the class level.
 
195
    """
 
196
 
 
197
    _matchingbzrdir = RemoteBzrDirFormat
 
198
 
 
199
    def initialize(self, a_bzrdir, shared=False):
 
200
        assert isinstance(a_bzrdir, RemoteBzrDir), \
 
201
            '%r is not a RemoteBzrDir' % (a_bzrdir,)
 
202
        return a_bzrdir.create_repository(shared=shared)
 
203
    
 
204
    def open(self, a_bzrdir):
 
205
        assert isinstance(a_bzrdir, RemoteBzrDir)
 
206
        return a_bzrdir.open_repository()
 
207
 
 
208
    def get_format_description(self):
 
209
        return 'bzr remote repository'
 
210
 
 
211
    def __eq__(self, other):
 
212
        return self.__class__ == other.__class__
 
213
 
 
214
    def check_conversion_target(self, target_format):
 
215
        if self.rich_root_data and not target_format.rich_root_data:
 
216
            raise errors.BadConversionTarget(
 
217
                'Does not support rich root data.', target_format)
 
218
        if (self.supports_tree_reference and
 
219
            not getattr(target_format, 'supports_tree_reference', False)):
 
220
            raise errors.BadConversionTarget(
 
221
                'Does not support nested trees', target_format)
 
222
 
 
223
 
 
224
class RemoteRepository(object):
 
225
    """Repository accessed over rpc.
 
226
 
 
227
    For the moment most operations are performed using local transport-backed
 
228
    Repository objects.
 
229
    """
 
230
 
 
231
    def __init__(self, remote_bzrdir, format, real_repository=None, _client=None):
 
232
        """Create a RemoteRepository instance.
 
233
        
 
234
        :param remote_bzrdir: The bzrdir hosting this repository.
 
235
        :param format: The RemoteFormat object to use.
 
236
        :param real_repository: If not None, a local implementation of the
 
237
            repository logic for the repository, usually accessing the data
 
238
            via the VFS.
 
239
        :param _client: Private testing parameter - override the smart client
 
240
            to be used by the repository.
 
241
        """
 
242
        if real_repository:
 
243
            self._real_repository = real_repository
 
244
        else:
 
245
            self._real_repository = None
 
246
        self.bzrdir = remote_bzrdir
 
247
        if _client is None:
 
248
            self._client = client._SmartClient(self.bzrdir._shared_medium)
 
249
        else:
 
250
            self._client = _client
 
251
        self._format = format
 
252
        self._lock_mode = None
 
253
        self._lock_token = None
 
254
        self._lock_count = 0
 
255
        self._leave_lock = False
 
256
        # for tests
 
257
        self._reconcile_does_inventory_gc = True
 
258
 
 
259
    def abort_write_group(self):
 
260
        """Complete a write group on the decorated repository.
 
261
        
 
262
        Smart methods peform operations in a single step so this api
 
263
        is not really applicable except as a compatibility thunk
 
264
        for older plugins that don't use e.g. the CommitBuilder
 
265
        facility.
 
266
        """
 
267
        self._ensure_real()
 
268
        return self._real_repository.abort_write_group()
 
269
 
 
270
    def commit_write_group(self):
 
271
        """Complete a write group on the decorated repository.
 
272
        
 
273
        Smart methods peform operations in a single step so this api
 
274
        is not really applicable except as a compatibility thunk
 
275
        for older plugins that don't use e.g. the CommitBuilder
 
276
        facility.
 
277
        """
 
278
        self._ensure_real()
 
279
        return self._real_repository.commit_write_group()
 
280
 
 
281
    def _ensure_real(self):
 
282
        """Ensure that there is a _real_repository set.
 
283
 
 
284
        Used before calls to self._real_repository.
 
285
        """
 
286
        if not self._real_repository:
 
287
            self.bzrdir._ensure_real()
 
288
            #self._real_repository = self.bzrdir._real_bzrdir.open_repository()
 
289
            self._set_real_repository(self.bzrdir._real_bzrdir.open_repository())
 
290
 
 
291
    def get_revision_graph(self, revision_id=None):
 
292
        """See Repository.get_revision_graph()."""
 
293
        if revision_id is None:
 
294
            revision_id = ''
 
295
        elif revision_id == NULL_REVISION:
 
296
            return {}
 
297
 
 
298
        path = self.bzrdir._path_for_remote_call(self._client)
 
299
        assert type(revision_id) is str
 
300
        response = self._client.call_expecting_body(
 
301
            'Repository.get_revision_graph', path, revision_id)
 
302
        if response[0][0] not in ['ok', 'nosuchrevision']:
 
303
            raise errors.UnexpectedSmartServerResponse(response[0])
 
304
        if response[0][0] == 'ok':
 
305
            coded = response[1].read_body_bytes()
 
306
            if coded == '':
 
307
                # no revisions in this repository!
 
308
                return {}
 
309
            lines = coded.split('\n')
 
310
            revision_graph = {}
 
311
            for line in lines:
 
312
                d = tuple(line.split())
 
313
                revision_graph[d[0]] = d[1:]
 
314
                
 
315
            return revision_graph
 
316
        else:
 
317
            response_body = response[1].read_body_bytes()
 
318
            assert response_body == ''
 
319
            raise NoSuchRevision(self, revision_id)
 
320
 
 
321
    def has_revision(self, revision_id):
 
322
        """See Repository.has_revision()."""
 
323
        if revision_id is None:
 
324
            # The null revision is always present.
 
325
            return True
 
326
        path = self.bzrdir._path_for_remote_call(self._client)
 
327
        response = self._client.call('Repository.has_revision', path, revision_id)
 
328
        assert response[0] in ('yes', 'no'), 'unexpected response code %s' % (response,)
 
329
        return response[0] == 'yes'
 
330
 
 
331
    def has_same_location(self, other):
 
332
        return (self.__class__ == other.__class__ and
 
333
                self.bzrdir.transport.base == other.bzrdir.transport.base)
 
334
        
 
335
    def get_graph(self, other_repository=None):
 
336
        """Return the graph for this repository format"""
 
337
        return self._real_repository.get_graph(other_repository)
 
338
 
 
339
    def gather_stats(self, revid=None, committers=None):
 
340
        """See Repository.gather_stats()."""
 
341
        path = self.bzrdir._path_for_remote_call(self._client)
 
342
        if revid in (None, NULL_REVISION):
 
343
            fmt_revid = ''
 
344
        else:
 
345
            fmt_revid = revid
 
346
        if committers is None or not committers:
 
347
            fmt_committers = 'no'
 
348
        else:
 
349
            fmt_committers = 'yes'
 
350
        response = self._client.call_expecting_body(
 
351
            'Repository.gather_stats', path, fmt_revid, fmt_committers)
 
352
        assert response[0][0] == 'ok', \
 
353
            'unexpected response code %s' % (response[0],)
 
354
 
 
355
        body = response[1].read_body_bytes()
 
356
        result = {}
 
357
        for line in body.split('\n'):
 
358
            if not line:
 
359
                continue
 
360
            key, val_text = line.split(':')
 
361
            if key in ('revisions', 'size', 'committers'):
 
362
                result[key] = int(val_text)
 
363
            elif key in ('firstrev', 'latestrev'):
 
364
                values = val_text.split(' ')[1:]
 
365
                result[key] = (float(values[0]), long(values[1]))
 
366
 
 
367
        return result
 
368
 
 
369
    def get_physical_lock_status(self):
 
370
        """See Repository.get_physical_lock_status()."""
 
371
        return False
 
372
 
 
373
    def is_in_write_group(self):
 
374
        """Return True if there is an open write group.
 
375
 
 
376
        write groups are only applicable locally for the smart server..
 
377
        """
 
378
        if self._real_repository:
 
379
            return self._real_repository.is_in_write_group()
 
380
 
 
381
    def is_locked(self):
 
382
        return self._lock_count >= 1
 
383
 
 
384
    def is_shared(self):
 
385
        """See Repository.is_shared()."""
 
386
        path = self.bzrdir._path_for_remote_call(self._client)
 
387
        response = self._client.call('Repository.is_shared', path)
 
388
        assert response[0] in ('yes', 'no'), 'unexpected response code %s' % (response,)
 
389
        return response[0] == 'yes'
 
390
 
 
391
    def lock_read(self):
 
392
        # wrong eventually - want a local lock cache context
 
393
        if not self._lock_mode:
 
394
            self._lock_mode = 'r'
 
395
            self._lock_count = 1
 
396
            if self._real_repository is not None:
 
397
                self._real_repository.lock_read()
 
398
        else:
 
399
            self._lock_count += 1
 
400
 
 
401
    def _remote_lock_write(self, token):
 
402
        path = self.bzrdir._path_for_remote_call(self._client)
 
403
        if token is None:
 
404
            token = ''
 
405
        response = self._client.call('Repository.lock_write', path, token)
 
406
        if response[0] == 'ok':
 
407
            ok, token = response
 
408
            return token
 
409
        elif response[0] == 'LockContention':
 
410
            raise errors.LockContention('(remote lock)')
 
411
        elif response[0] == 'UnlockableTransport':
 
412
            raise errors.UnlockableTransport(self.bzrdir.root_transport)
 
413
        else:
 
414
            raise errors.UnexpectedSmartServerResponse(response)
 
415
 
 
416
    def lock_write(self, token=None):
 
417
        if not self._lock_mode:
 
418
            self._lock_token = self._remote_lock_write(token)
 
419
            assert self._lock_token, 'Remote server did not return a token!'
 
420
            if self._real_repository is not None:
 
421
                self._real_repository.lock_write(token=self._lock_token)
 
422
            if token is not None:
 
423
                self._leave_lock = True
 
424
            else:
 
425
                self._leave_lock = False
 
426
            self._lock_mode = 'w'
 
427
            self._lock_count = 1
 
428
        elif self._lock_mode == 'r':
 
429
            raise errors.ReadOnlyError(self)
 
430
        else:
 
431
            self._lock_count += 1
 
432
        return self._lock_token
 
433
 
 
434
    def leave_lock_in_place(self):
 
435
        self._leave_lock = True
 
436
 
 
437
    def dont_leave_lock_in_place(self):
 
438
        self._leave_lock = False
 
439
 
 
440
    def _set_real_repository(self, repository):
 
441
        """Set the _real_repository for this repository.
 
442
 
 
443
        :param repository: The repository to fallback to for non-hpss
 
444
            implemented operations.
 
445
        """
 
446
        assert not isinstance(repository, RemoteRepository)
 
447
        self._real_repository = repository
 
448
        if self._lock_mode == 'w':
 
449
            # if we are already locked, the real repository must be able to
 
450
            # acquire the lock with our token.
 
451
            self._real_repository.lock_write(self._lock_token)
 
452
        elif self._lock_mode == 'r':
 
453
            self._real_repository.lock_read()
 
454
 
 
455
    def start_write_group(self):
 
456
        """Start a write group on the decorated repository.
 
457
        
 
458
        Smart methods peform operations in a single step so this api
 
459
        is not really applicable except as a compatibility thunk
 
460
        for older plugins that don't use e.g. the CommitBuilder
 
461
        facility.
 
462
        """
 
463
        self._ensure_real()
 
464
        return self._real_repository.start_write_group()
 
465
 
 
466
    def _unlock(self, token):
 
467
        path = self.bzrdir._path_for_remote_call(self._client)
 
468
        response = self._client.call('Repository.unlock', path, token)
 
469
        if response == ('ok',):
 
470
            return
 
471
        elif response[0] == 'TokenMismatch':
 
472
            raise errors.TokenMismatch(token, '(remote token)')
 
473
        else:
 
474
            raise errors.UnexpectedSmartServerResponse(response)
 
475
 
 
476
    def unlock(self):
 
477
        if self._lock_count == 1 and self._lock_mode == 'w':
 
478
            # don't unlock if inside a write group.
 
479
            if self.is_in_write_group():
 
480
                raise errors.BzrError(
 
481
                    'Must end write groups before releasing write locks.')
 
482
        self._lock_count -= 1
 
483
        if not self._lock_count:
 
484
            mode = self._lock_mode
 
485
            self._lock_mode = None
 
486
            if self._real_repository is not None:
 
487
                self._real_repository.unlock()
 
488
            if mode != 'w':
 
489
                # Only write-locked repositories need to make a remote method
 
490
                # call to perfom the unlock.
 
491
                return
 
492
            assert self._lock_token, 'Locked, but no token!'
 
493
            token = self._lock_token
 
494
            self._lock_token = None
 
495
            if not self._leave_lock:
 
496
                self._unlock(token)
 
497
 
 
498
    def break_lock(self):
 
499
        # should hand off to the network
 
500
        self._ensure_real()
 
501
        return self._real_repository.break_lock()
 
502
 
 
503
    def _get_tarball(self, compression):
 
504
        """Return a TemporaryFile containing a repository tarball"""
 
505
        import tempfile
 
506
        path = self.bzrdir._path_for_remote_call(self._client)
 
507
        response, protocol = self._client.call_expecting_body(
 
508
            'Repository.tarball', path, compression)
 
509
        assert response[0] in ('ok', 'failure'), \
 
510
            'unexpected response code %s' % (response,)
 
511
        if response[0] == 'ok':
 
512
            # Extract the tarball and return it
 
513
            t = tempfile.NamedTemporaryFile()
 
514
            # TODO: rpc layer should read directly into it...
 
515
            t.write(protocol.read_body_bytes())
 
516
            t.seek(0)
 
517
            return t
 
518
        else:
 
519
            raise errors.SmartServerError(error_code=response)
 
520
 
 
521
    def sprout(self, to_bzrdir, revision_id=None):
 
522
        # TODO: Option to control what format is created?
 
523
        dest_repo = to_bzrdir.create_repository()
 
524
        dest_repo.fetch(self, revision_id=revision_id)
 
525
        return dest_repo
 
526
 
 
527
    ### These methods are just thin shims to the VFS object for now.
 
528
 
 
529
    def revision_tree(self, revision_id):
 
530
        self._ensure_real()
 
531
        return self._real_repository.revision_tree(revision_id)
 
532
 
 
533
    def get_serializer_format(self):
 
534
        self._ensure_real()
 
535
        return self._real_repository.get_serializer_format()
 
536
 
 
537
    def get_commit_builder(self, branch, parents, config, timestamp=None,
 
538
                           timezone=None, committer=None, revprops=None,
 
539
                           revision_id=None):
 
540
        # FIXME: It ought to be possible to call this without immediately
 
541
        # triggering _ensure_real.  For now it's the easiest thing to do.
 
542
        self._ensure_real()
 
543
        builder = self._real_repository.get_commit_builder(branch, parents,
 
544
                config, timestamp=timestamp, timezone=timezone,
 
545
                committer=committer, revprops=revprops, revision_id=revision_id)
 
546
        # Make the builder use this RemoteRepository rather than the real one.
 
547
        builder.repository = self
 
548
        return builder
 
549
 
 
550
    @needs_write_lock
 
551
    def add_inventory(self, revid, inv, parents):
 
552
        self._ensure_real()
 
553
        return self._real_repository.add_inventory(revid, inv, parents)
 
554
 
 
555
    @needs_write_lock
 
556
    def add_revision(self, rev_id, rev, inv=None, config=None):
 
557
        self._ensure_real()
 
558
        return self._real_repository.add_revision(
 
559
            rev_id, rev, inv=inv, config=config)
 
560
 
 
561
    @needs_read_lock
 
562
    def get_inventory(self, revision_id):
 
563
        self._ensure_real()
 
564
        return self._real_repository.get_inventory(revision_id)
 
565
 
 
566
    @needs_read_lock
 
567
    def get_revision(self, revision_id):
 
568
        self._ensure_real()
 
569
        return self._real_repository.get_revision(revision_id)
 
570
 
 
571
    @property
 
572
    def weave_store(self):
 
573
        self._ensure_real()
 
574
        return self._real_repository.weave_store
 
575
 
 
576
    def get_transaction(self):
 
577
        self._ensure_real()
 
578
        return self._real_repository.get_transaction()
 
579
 
 
580
    @needs_read_lock
 
581
    def clone(self, a_bzrdir, revision_id=None):
 
582
        self._ensure_real()
 
583
        return self._real_repository.clone(a_bzrdir, revision_id=revision_id)
 
584
 
 
585
    def make_working_trees(self):
 
586
        """RemoteRepositories never create working trees by default."""
 
587
        return False
 
588
 
 
589
    def fetch(self, source, revision_id=None, pb=None):
 
590
        self._ensure_real()
 
591
        return self._real_repository.fetch(
 
592
            source, revision_id=revision_id, pb=pb)
 
593
 
 
594
    def create_bundle(self, target, base, fileobj, format=None):
 
595
        self._ensure_real()
 
596
        self._real_repository.create_bundle(target, base, fileobj, format)
 
597
 
 
598
    @property
 
599
    def control_weaves(self):
 
600
        self._ensure_real()
 
601
        return self._real_repository.control_weaves
 
602
 
 
603
    @needs_read_lock
 
604
    def get_ancestry(self, revision_id, topo_sorted=True):
 
605
        self._ensure_real()
 
606
        return self._real_repository.get_ancestry(revision_id, topo_sorted)
 
607
 
 
608
    @needs_read_lock
 
609
    def get_inventory_weave(self):
 
610
        self._ensure_real()
 
611
        return self._real_repository.get_inventory_weave()
 
612
 
 
613
    def fileids_altered_by_revision_ids(self, revision_ids):
 
614
        self._ensure_real()
 
615
        return self._real_repository.fileids_altered_by_revision_ids(revision_ids)
 
616
 
 
617
    def iter_files_bytes(self, desired_files):
 
618
        """See Repository.iter_file_bytes.
 
619
        """
 
620
        self._ensure_real()
 
621
        return self._real_repository.iter_files_bytes(desired_files)
 
622
 
 
623
    @needs_read_lock
 
624
    def get_signature_text(self, revision_id):
 
625
        self._ensure_real()
 
626
        return self._real_repository.get_signature_text(revision_id)
 
627
 
 
628
    @needs_read_lock
 
629
    def get_revision_graph_with_ghosts(self, revision_ids=None):
 
630
        self._ensure_real()
 
631
        return self._real_repository.get_revision_graph_with_ghosts(
 
632
            revision_ids=revision_ids)
 
633
 
 
634
    @needs_read_lock
 
635
    def get_inventory_xml(self, revision_id):
 
636
        self._ensure_real()
 
637
        return self._real_repository.get_inventory_xml(revision_id)
 
638
 
 
639
    def deserialise_inventory(self, revision_id, xml):
 
640
        self._ensure_real()
 
641
        return self._real_repository.deserialise_inventory(revision_id, xml)
 
642
 
 
643
    def reconcile(self, other=None, thorough=False):
 
644
        self._ensure_real()
 
645
        return self._real_repository.reconcile(other=other, thorough=thorough)
 
646
        
 
647
    def all_revision_ids(self):
 
648
        self._ensure_real()
 
649
        return self._real_repository.all_revision_ids()
 
650
    
 
651
    @needs_read_lock
 
652
    def get_deltas_for_revisions(self, revisions):
 
653
        self._ensure_real()
 
654
        return self._real_repository.get_deltas_for_revisions(revisions)
 
655
 
 
656
    @needs_read_lock
 
657
    def get_revision_delta(self, revision_id):
 
658
        self._ensure_real()
 
659
        return self._real_repository.get_revision_delta(revision_id)
 
660
 
 
661
    @needs_read_lock
 
662
    def revision_trees(self, revision_ids):
 
663
        self._ensure_real()
 
664
        return self._real_repository.revision_trees(revision_ids)
 
665
 
 
666
    @needs_read_lock
 
667
    def get_revision_reconcile(self, revision_id):
 
668
        self._ensure_real()
 
669
        return self._real_repository.get_revision_reconcile(revision_id)
 
670
 
 
671
    @needs_read_lock
 
672
    def check(self, revision_ids):
 
673
        self._ensure_real()
 
674
        return self._real_repository.check(revision_ids)
 
675
 
 
676
    def copy_content_into(self, destination, revision_id=None):
 
677
        self._ensure_real()
 
678
        return self._real_repository.copy_content_into(
 
679
            destination, revision_id=revision_id)
 
680
 
 
681
    def _copy_repository_tarball(self, destination, revision_id=None):
 
682
        # get a tarball of the remote repository, and copy from that into the
 
683
        # destination
 
684
        from bzrlib import osutils
 
685
        import tarfile
 
686
        import tempfile
 
687
        from StringIO import StringIO
 
688
        # TODO: Maybe a progress bar while streaming the tarball?
 
689
        note("Copying repository content as tarball...")
 
690
        tar_file = self._get_tarball('bz2')
 
691
        try:
 
692
            tar = tarfile.open('repository', fileobj=tar_file,
 
693
                mode='r|bz2')
 
694
            tmpdir = tempfile.mkdtemp()
 
695
            try:
 
696
                _extract_tar(tar, tmpdir)
 
697
                tmp_bzrdir = BzrDir.open(tmpdir)
 
698
                tmp_repo = tmp_bzrdir.open_repository()
 
699
                tmp_repo.copy_content_into(destination, revision_id)
 
700
            finally:
 
701
                osutils.rmtree(tmpdir)
 
702
        finally:
 
703
            tar_file.close()
 
704
        # TODO: if the server doesn't support this operation, maybe do it the
 
705
        # slow way using the _real_repository?
 
706
        #
 
707
        # TODO: Suggestion from john: using external tar is much faster than
 
708
        # python's tarfile library, but it may not work on windows.
 
709
 
 
710
    @needs_write_lock
 
711
    def pack(self):
 
712
        """Compress the data within the repository.
 
713
 
 
714
        This is not currently implemented within the smart server.
 
715
        """
 
716
        self._ensure_real()
 
717
        return self._real_repository.pack()
 
718
 
 
719
    def set_make_working_trees(self, new_value):
 
720
        raise NotImplementedError(self.set_make_working_trees)
 
721
 
 
722
    @needs_write_lock
 
723
    def sign_revision(self, revision_id, gpg_strategy):
 
724
        self._ensure_real()
 
725
        return self._real_repository.sign_revision(revision_id, gpg_strategy)
 
726
 
 
727
    @needs_read_lock
 
728
    def get_revisions(self, revision_ids):
 
729
        self._ensure_real()
 
730
        return self._real_repository.get_revisions(revision_ids)
 
731
 
 
732
    def supports_rich_root(self):
 
733
        self._ensure_real()
 
734
        return self._real_repository.supports_rich_root()
 
735
 
 
736
    def iter_reverse_revision_history(self, revision_id):
 
737
        self._ensure_real()
 
738
        return self._real_repository.iter_reverse_revision_history(revision_id)
 
739
 
 
740
    @property
 
741
    def _serializer(self):
 
742
        self._ensure_real()
 
743
        return self._real_repository._serializer
 
744
 
 
745
    def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
 
746
        self._ensure_real()
 
747
        return self._real_repository.store_revision_signature(
 
748
            gpg_strategy, plaintext, revision_id)
 
749
 
 
750
    def has_signature_for_revision_id(self, revision_id):
 
751
        self._ensure_real()
 
752
        return self._real_repository.has_signature_for_revision_id(revision_id)
 
753
 
 
754
    def get_data_stream(self, revision_ids):
 
755
        path = self.bzrdir._path_for_remote_call(self._client)
 
756
        response, protocol = self._client.call_expecting_body(
 
757
            'Repository.stream_knit_data_for_revisions', path, *revision_ids)
 
758
        if response == ('ok',):
 
759
            buffer = StringIO(protocol.read_body_bytes())
 
760
            reader = ContainerReader(buffer)
 
761
            for record_names, read_bytes in reader.iter_records():
 
762
                try:
 
763
                    # These records should have only one name, and that name
 
764
                    # should be a one-element tuple.
 
765
                    [name_tuple] = record_names
 
766
                except ValueError:
 
767
                    raise errors.SmartProtocolError(
 
768
                        'Repository data stream had invalid record name %r'
 
769
                        % (record_names,))
 
770
                yield name_tuple, read_bytes(None)
 
771
        else:
 
772
            raise errors.UnexpectedSmartServerResponse(response)
 
773
 
 
774
    def insert_data_stream(self, stream):
 
775
        self._ensure_real()
 
776
        self._real_repository.insert_data_stream(stream)
 
777
 
 
778
    def item_keys_introduced_by(self, revision_ids, _files_pb=None):
 
779
        self._ensure_real()
 
780
        return self._real_repository.item_keys_introduced_by(revision_ids,
 
781
            _files_pb=_files_pb)
 
782
 
 
783
 
 
784
class RemoteBranchLockableFiles(LockableFiles):
 
785
    """A 'LockableFiles' implementation that talks to a smart server.
 
786
    
 
787
    This is not a public interface class.
 
788
    """
 
789
 
 
790
    def __init__(self, bzrdir, _client):
 
791
        self.bzrdir = bzrdir
 
792
        self._client = _client
 
793
        self._need_find_modes = True
 
794
        LockableFiles.__init__(
 
795
            self, bzrdir.get_branch_transport(None),
 
796
            'lock', lockdir.LockDir)
 
797
 
 
798
    def _find_modes(self):
 
799
        # RemoteBranches don't let the client set the mode of control files.
 
800
        self._dir_mode = None
 
801
        self._file_mode = None
 
802
 
 
803
    def get(self, path):
 
804
        """'get' a remote path as per the LockableFiles interface.
 
805
 
 
806
        :param path: the file to 'get'. If this is 'branch.conf', we do not
 
807
             just retrieve a file, instead we ask the smart server to generate
 
808
             a configuration for us - which is retrieved as an INI file.
 
809
        """
 
810
        if path == 'branch.conf':
 
811
            path = self.bzrdir._path_for_remote_call(self._client)
 
812
            response = self._client.call_expecting_body(
 
813
                'Branch.get_config_file', path)
 
814
            assert response[0][0] == 'ok', \
 
815
                'unexpected response code %s' % (response[0],)
 
816
            return StringIO(response[1].read_body_bytes())
 
817
        else:
 
818
            # VFS fallback.
 
819
            return LockableFiles.get(self, path)
 
820
 
 
821
 
 
822
class RemoteBranchFormat(branch.BranchFormat):
 
823
 
 
824
    def __eq__(self, other):
 
825
        return (isinstance(other, RemoteBranchFormat) and 
 
826
            self.__dict__ == other.__dict__)
 
827
 
 
828
    def get_format_description(self):
 
829
        return 'Remote BZR Branch'
 
830
 
 
831
    def get_format_string(self):
 
832
        return 'Remote BZR Branch'
 
833
 
 
834
    def open(self, a_bzrdir):
 
835
        assert isinstance(a_bzrdir, RemoteBzrDir)
 
836
        return a_bzrdir.open_branch()
 
837
 
 
838
    def initialize(self, a_bzrdir):
 
839
        assert isinstance(a_bzrdir, RemoteBzrDir)
 
840
        return a_bzrdir.create_branch()
 
841
 
 
842
    def supports_tags(self):
 
843
        # Remote branches might support tags, but we won't know until we
 
844
        # access the real remote branch.
 
845
        return True
 
846
 
 
847
 
 
848
class RemoteBranch(branch.Branch):
 
849
    """Branch stored on a server accessed by HPSS RPC.
 
850
 
 
851
    At the moment most operations are mapped down to simple file operations.
 
852
    """
 
853
 
 
854
    def __init__(self, remote_bzrdir, remote_repository, real_branch=None,
 
855
        _client=None):
 
856
        """Create a RemoteBranch instance.
 
857
 
 
858
        :param real_branch: An optional local implementation of the branch
 
859
            format, usually accessing the data via the VFS.
 
860
        :param _client: Private parameter for testing.
 
861
        """
 
862
        # We intentionally don't call the parent class's __init__, because it
 
863
        # will try to assign to self.tags, which is a property in this subclass.
 
864
        # And the parent's __init__ doesn't do much anyway.
 
865
        self._revision_history_cache = None
 
866
        self.bzrdir = remote_bzrdir
 
867
        if _client is not None:
 
868
            self._client = _client
 
869
        else:
 
870
            self._client = client._SmartClient(self.bzrdir._shared_medium)
 
871
        self.repository = remote_repository
 
872
        if real_branch is not None:
 
873
            self._real_branch = real_branch
 
874
            # Give the remote repository the matching real repo.
 
875
            real_repo = self._real_branch.repository
 
876
            if isinstance(real_repo, RemoteRepository):
 
877
                real_repo._ensure_real()
 
878
                real_repo = real_repo._real_repository
 
879
            self.repository._set_real_repository(real_repo)
 
880
            # Give the branch the remote repository to let fast-pathing happen.
 
881
            self._real_branch.repository = self.repository
 
882
        else:
 
883
            self._real_branch = None
 
884
        # Fill out expected attributes of branch for bzrlib api users.
 
885
        self._format = RemoteBranchFormat()
 
886
        self.base = self.bzrdir.root_transport.base
 
887
        self._control_files = None
 
888
        self._lock_mode = None
 
889
        self._lock_token = None
 
890
        self._lock_count = 0
 
891
        self._leave_lock = False
 
892
 
 
893
    def __str__(self):
 
894
        return "%s(%s)" % (self.__class__.__name__, self.base)
 
895
 
 
896
    __repr__ = __str__
 
897
 
 
898
    def _ensure_real(self):
 
899
        """Ensure that there is a _real_branch set.
 
900
 
 
901
        Used before calls to self._real_branch.
 
902
        """
 
903
        if not self._real_branch:
 
904
            assert vfs.vfs_enabled()
 
905
            self.bzrdir._ensure_real()
 
906
            self._real_branch = self.bzrdir._real_bzrdir.open_branch()
 
907
            # Give the remote repository the matching real repo.
 
908
            real_repo = self._real_branch.repository
 
909
            if isinstance(real_repo, RemoteRepository):
 
910
                real_repo._ensure_real()
 
911
                real_repo = real_repo._real_repository
 
912
            self.repository._set_real_repository(real_repo)
 
913
            # Give the branch the remote repository to let fast-pathing happen.
 
914
            self._real_branch.repository = self.repository
 
915
            # XXX: deal with _lock_mode == 'w'
 
916
            if self._lock_mode == 'r':
 
917
                self._real_branch.lock_read()
 
918
 
 
919
    @property
 
920
    def control_files(self):
 
921
        # Defer actually creating RemoteBranchLockableFiles until its needed,
 
922
        # because it triggers an _ensure_real that we otherwise might not need.
 
923
        if self._control_files is None:
 
924
            self._control_files = RemoteBranchLockableFiles(
 
925
                self.bzrdir, self._client)
 
926
        return self._control_files
 
927
 
 
928
    def _get_checkout_format(self):
 
929
        self._ensure_real()
 
930
        return self._real_branch._get_checkout_format()
 
931
 
 
932
    def get_physical_lock_status(self):
 
933
        """See Branch.get_physical_lock_status()."""
 
934
        # should be an API call to the server, as branches must be lockable.
 
935
        self._ensure_real()
 
936
        return self._real_branch.get_physical_lock_status()
 
937
 
 
938
    def lock_read(self):
 
939
        if not self._lock_mode:
 
940
            self._lock_mode = 'r'
 
941
            self._lock_count = 1
 
942
            if self._real_branch is not None:
 
943
                self._real_branch.lock_read()
 
944
        else:
 
945
            self._lock_count += 1
 
946
 
 
947
    def _remote_lock_write(self, token):
 
948
        if token is None:
 
949
            branch_token = repo_token = ''
 
950
        else:
 
951
            branch_token = token
 
952
            repo_token = self.repository.lock_write()
 
953
            self.repository.unlock()
 
954
        path = self.bzrdir._path_for_remote_call(self._client)
 
955
        response = self._client.call('Branch.lock_write', path, branch_token,
 
956
                                     repo_token)
 
957
        if response[0] == 'ok':
 
958
            ok, branch_token, repo_token = response
 
959
            return branch_token, repo_token
 
960
        elif response[0] == 'LockContention':
 
961
            raise errors.LockContention('(remote lock)')
 
962
        elif response[0] == 'TokenMismatch':
 
963
            raise errors.TokenMismatch(token, '(remote token)')
 
964
        elif response[0] == 'UnlockableTransport':
 
965
            raise errors.UnlockableTransport(self.bzrdir.root_transport)
 
966
        elif response[0] == 'ReadOnlyError':
 
967
            raise errors.ReadOnlyError(self)
 
968
        else:
 
969
            raise errors.UnexpectedSmartServerResponse(response)
 
970
            
 
971
    def lock_write(self, token=None):
 
972
        if not self._lock_mode:
 
973
            remote_tokens = self._remote_lock_write(token)
 
974
            self._lock_token, self._repo_lock_token = remote_tokens
 
975
            assert self._lock_token, 'Remote server did not return a token!'
 
976
            # TODO: We really, really, really don't want to call _ensure_real
 
977
            # here, but it's the easiest way to ensure coherency between the
 
978
            # state of the RemoteBranch and RemoteRepository objects and the
 
979
            # physical locks.  If we don't materialise the real objects here,
 
980
            # then getting everything in the right state later is complex, so
 
981
            # for now we just do it the lazy way.
 
982
            #   -- Andrew Bennetts, 2007-02-22.
 
983
            self._ensure_real()
 
984
            if self._real_branch is not None:
 
985
                self._real_branch.repository.lock_write(
 
986
                    token=self._repo_lock_token)
 
987
                try:
 
988
                    self._real_branch.lock_write(token=self._lock_token)
 
989
                finally:
 
990
                    self._real_branch.repository.unlock()
 
991
            if token is not None:
 
992
                self._leave_lock = True
 
993
            else:
 
994
                # XXX: this case seems to be unreachable; token cannot be None.
 
995
                self._leave_lock = False
 
996
            self._lock_mode = 'w'
 
997
            self._lock_count = 1
 
998
        elif self._lock_mode == 'r':
 
999
            raise errors.ReadOnlyTransaction
 
1000
        else:
 
1001
            if token is not None:
 
1002
                # A token was given to lock_write, and we're relocking, so check
 
1003
                # that the given token actually matches the one we already have.
 
1004
                if token != self._lock_token:
 
1005
                    raise errors.TokenMismatch(token, self._lock_token)
 
1006
            self._lock_count += 1
 
1007
        return self._lock_token
 
1008
 
 
1009
    def _unlock(self, branch_token, repo_token):
 
1010
        path = self.bzrdir._path_for_remote_call(self._client)
 
1011
        response = self._client.call('Branch.unlock', path, branch_token,
 
1012
                                     repo_token)
 
1013
        if response == ('ok',):
 
1014
            return
 
1015
        elif response[0] == 'TokenMismatch':
 
1016
            raise errors.TokenMismatch(
 
1017
                str((branch_token, repo_token)), '(remote tokens)')
 
1018
        else:
 
1019
            raise errors.UnexpectedSmartServerResponse(response)
 
1020
 
 
1021
    def unlock(self):
 
1022
        self._lock_count -= 1
 
1023
        if not self._lock_count:
 
1024
            self._clear_cached_state()
 
1025
            mode = self._lock_mode
 
1026
            self._lock_mode = None
 
1027
            if self._real_branch is not None:
 
1028
                if not self._leave_lock:
 
1029
                    # If this RemoteBranch will remove the physical lock for the
 
1030
                    # repository, make sure the _real_branch doesn't do it
 
1031
                    # first.  (Because the _real_branch's repository is set to
 
1032
                    # be the RemoteRepository.)
 
1033
                    self._real_branch.repository.leave_lock_in_place()
 
1034
                self._real_branch.unlock()
 
1035
            if mode != 'w':
 
1036
                # Only write-locked branched need to make a remote method call
 
1037
                # to perfom the unlock.
 
1038
                return
 
1039
            assert self._lock_token, 'Locked, but no token!'
 
1040
            branch_token = self._lock_token
 
1041
            repo_token = self._repo_lock_token
 
1042
            self._lock_token = None
 
1043
            self._repo_lock_token = None
 
1044
            if not self._leave_lock:
 
1045
                self._unlock(branch_token, repo_token)
 
1046
 
 
1047
    def break_lock(self):
 
1048
        self._ensure_real()
 
1049
        return self._real_branch.break_lock()
 
1050
 
 
1051
    def leave_lock_in_place(self):
 
1052
        self._leave_lock = True
 
1053
 
 
1054
    def dont_leave_lock_in_place(self):
 
1055
        self._leave_lock = False
 
1056
 
 
1057
    def last_revision_info(self):
 
1058
        """See Branch.last_revision_info()."""
 
1059
        path = self.bzrdir._path_for_remote_call(self._client)
 
1060
        response = self._client.call('Branch.last_revision_info', path)
 
1061
        assert response[0] == 'ok', 'unexpected response code %s' % (response,)
 
1062
        revno = int(response[1])
 
1063
        last_revision = response[2]
 
1064
        return (revno, last_revision)
 
1065
 
 
1066
    def _gen_revision_history(self):
 
1067
        """See Branch._gen_revision_history()."""
 
1068
        path = self.bzrdir._path_for_remote_call(self._client)
 
1069
        response = self._client.call_expecting_body(
 
1070
            'Branch.revision_history', path)
 
1071
        assert response[0][0] == 'ok', ('unexpected response code %s'
 
1072
                                        % (response[0],))
 
1073
        result = response[1].read_body_bytes().split('\x00')
 
1074
        if result == ['']:
 
1075
            return []
 
1076
        return result
 
1077
 
 
1078
    @needs_write_lock
 
1079
    def set_revision_history(self, rev_history):
 
1080
        # Send just the tip revision of the history; the server will generate
 
1081
        # the full history from that.  If the revision doesn't exist in this
 
1082
        # branch, NoSuchRevision will be raised.
 
1083
        path = self.bzrdir._path_for_remote_call(self._client)
 
1084
        if rev_history == []:
 
1085
            rev_id = 'null:'
 
1086
        else:
 
1087
            rev_id = rev_history[-1]
 
1088
        self._clear_cached_state()
 
1089
        response = self._client.call('Branch.set_last_revision',
 
1090
            path, self._lock_token, self._repo_lock_token, rev_id)
 
1091
        if response[0] == 'NoSuchRevision':
 
1092
            raise NoSuchRevision(self, rev_id)
 
1093
        else:
 
1094
            assert response == ('ok',), (
 
1095
                'unexpected response code %r' % (response,))
 
1096
        self._cache_revision_history(rev_history)
 
1097
 
 
1098
    def get_parent(self):
 
1099
        self._ensure_real()
 
1100
        return self._real_branch.get_parent()
 
1101
        
 
1102
    def set_parent(self, url):
 
1103
        self._ensure_real()
 
1104
        return self._real_branch.set_parent(url)
 
1105
        
 
1106
    def get_config(self):
 
1107
        return RemoteBranchConfig(self)
 
1108
 
 
1109
    def sprout(self, to_bzrdir, revision_id=None):
 
1110
        # Like Branch.sprout, except that it sprouts a branch in the default
 
1111
        # format, because RemoteBranches can't be created at arbitrary URLs.
 
1112
        # XXX: if to_bzrdir is a RemoteBranch, this should perhaps do
 
1113
        # to_bzrdir.create_branch...
 
1114
        result = branch.BranchFormat.get_default_format().initialize(to_bzrdir)
 
1115
        self.copy_content_into(result, revision_id=revision_id)
 
1116
        result.set_parent(self.bzrdir.root_transport.base)
 
1117
        return result
 
1118
 
 
1119
    @needs_write_lock
 
1120
    def pull(self, source, overwrite=False, stop_revision=None,
 
1121
             **kwargs):
 
1122
        # FIXME: This asks the real branch to run the hooks, which means
 
1123
        # they're called with the wrong target branch parameter. 
 
1124
        # The test suite specifically allows this at present but it should be
 
1125
        # fixed.  It should get a _override_hook_target branch,
 
1126
        # as push does.  -- mbp 20070405
 
1127
        self._ensure_real()
 
1128
        self._real_branch.pull(
 
1129
            source, overwrite=overwrite, stop_revision=stop_revision,
 
1130
            **kwargs)
 
1131
 
 
1132
    @needs_read_lock
 
1133
    def push(self, target, overwrite=False, stop_revision=None):
 
1134
        self._ensure_real()
 
1135
        return self._real_branch.push(
 
1136
            target, overwrite=overwrite, stop_revision=stop_revision,
 
1137
            _override_hook_source_branch=self)
 
1138
 
 
1139
    def is_locked(self):
 
1140
        return self._lock_count >= 1
 
1141
 
 
1142
    def set_last_revision_info(self, revno, revision_id):
 
1143
        self._ensure_real()
 
1144
        self._clear_cached_state()
 
1145
        return self._real_branch.set_last_revision_info(revno, revision_id)
 
1146
 
 
1147
    def generate_revision_history(self, revision_id, last_rev=None,
 
1148
                                  other_branch=None):
 
1149
        self._ensure_real()
 
1150
        return self._real_branch.generate_revision_history(
 
1151
            revision_id, last_rev=last_rev, other_branch=other_branch)
 
1152
 
 
1153
    @property
 
1154
    def tags(self):
 
1155
        self._ensure_real()
 
1156
        return self._real_branch.tags
 
1157
 
 
1158
    def set_push_location(self, location):
 
1159
        self._ensure_real()
 
1160
        return self._real_branch.set_push_location(location)
 
1161
 
 
1162
    def update_revisions(self, other, stop_revision=None):
 
1163
        self._ensure_real()
 
1164
        return self._real_branch.update_revisions(
 
1165
            other, stop_revision=stop_revision)
 
1166
 
 
1167
 
 
1168
class RemoteBranchConfig(BranchConfig):
 
1169
 
 
1170
    def username(self):
 
1171
        self.branch._ensure_real()
 
1172
        return self.branch._real_branch.get_config().username()
 
1173
 
 
1174
    def _get_branch_data_config(self):
 
1175
        self.branch._ensure_real()
 
1176
        if self._branch_data_config is None:
 
1177
            self._branch_data_config = TreeConfig(self.branch._real_branch)
 
1178
        return self._branch_data_config
 
1179
 
 
1180
 
 
1181
def _extract_tar(tar, to_dir):
 
1182
    """Extract all the contents of a tarfile object.
 
1183
 
 
1184
    A replacement for extractall, which is not present in python2.4
 
1185
    """
 
1186
    for tarinfo in tar:
 
1187
        tar.extract(tarinfo, to_dir)