/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
 
1
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
34
34
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
35
35
from bzrlib.config import BranchConfig, TreeConfig
36
36
from bzrlib.decorators import needs_read_lock, needs_write_lock
37
 
from bzrlib.errors import NoSuchRevision
 
37
from bzrlib.errors import (
 
38
    NoSuchRevision,
 
39
    SmartProtocolError,
 
40
    )
38
41
from bzrlib.lockable_files import LockableFiles
39
42
from bzrlib.pack import ContainerPushParser
40
43
from bzrlib.smart import client, vfs
135
138
        return None, self.open_branch()
136
139
 
137
140
    def open_branch(self, _unsupported=False):
138
 
        assert _unsupported == False, 'unsupported flag support not implemented yet.'
 
141
        if _unsupported:
 
142
            raise NotImplementedError('unsupported flag support not implemented yet.')
139
143
        reference_url = self.get_branch_reference()
140
144
        if reference_url is None:
141
145
            # branch at this location.
164
168
            # servers that don't support the V2 method don't support external
165
169
            # references either.
166
170
            response = response + ('no', )
167
 
        assert len(response) == 5, 'incorrect response length %s' % (response,)
 
171
        if not (len(response) == 5):
 
172
            raise SmartProtocolError('incorrect response length %s' % (response,))
168
173
        if response[1] == '':
169
174
            format = RemoteRepositoryFormat()
170
175
            format.rich_root_data = (response[2] == 'yes')
228
233
    _matchingbzrdir = RemoteBzrDirFormat
229
234
 
230
235
    def initialize(self, a_bzrdir, shared=False):
231
 
        assert isinstance(a_bzrdir, RemoteBzrDir), \
232
 
            '%r is not a RemoteBzrDir' % (a_bzrdir,)
 
236
        if not isinstance(a_bzrdir, RemoteBzrDir):
 
237
            raise AssertionError('%r is not a RemoteBzrDir' % (a_bzrdir,))
233
238
        return a_bzrdir.create_repository(shared=shared)
234
239
    
235
240
    def open(self, a_bzrdir):
236
 
        assert isinstance(a_bzrdir, RemoteBzrDir)
 
241
        if not isinstance(a_bzrdir, RemoteBzrDir):
 
242
            raise AssertionError('%r is not a RemoteBzrDir' % (a_bzrdir,))
237
243
        return a_bzrdir.open_repository()
238
244
 
239
245
    def get_format_description(self):
373
379
            return {}
374
380
 
375
381
        path = self.bzrdir._path_for_remote_call(self._client)
376
 
        assert type(revision_id) is str
377
382
        try:
378
383
            response = self._client.call_expecting_body(
379
384
                'Repository.get_revision_graph', path, revision_id)
401
406
            return True
402
407
        path = self.bzrdir._path_for_remote_call(self._client)
403
408
        response = self._client.call('Repository.has_revision', path, revision_id)
404
 
        assert response[0] in ('yes', 'no'), 'unexpected response code %s' % (response,)
 
409
        if response[0] not in ('yes', 'no'):
 
410
            raise SmartProtocolError('unexpected response code %s' % (response,))
405
411
        return response[0] == 'yes'
406
412
 
407
413
    def has_revisions(self, revision_ids):
440
446
            fmt_committers = 'yes'
441
447
        response = self._client.call_expecting_body(
442
448
            'Repository.gather_stats', path, fmt_revid, fmt_committers)
443
 
        assert response[0][0] == 'ok', \
444
 
            'unexpected response code %s' % (response[0],)
 
449
        if response[0][0] != 'ok':
 
450
            raise SmartProtocolError('unexpected response code %s'
 
451
                % (response[0],))
445
452
 
446
453
        body = response[1].read_body_bytes()
447
454
        result = {}
484
491
        """See Repository.is_shared()."""
485
492
        path = self.bzrdir._path_for_remote_call(self._client)
486
493
        response = self._client.call('Repository.is_shared', path)
487
 
        assert response[0] in ('yes', 'no'), 'unexpected response code %s' % (response,)
 
494
        if response[0] not in ('yes', 'no'):
 
495
            raise SmartProtocolError('unexpected response code %s' % (response,))
488
496
        return response[0] == 'yes'
489
497
 
490
498
    def is_write_locked(self):
564
572
        :param repository: The repository to fallback to for non-hpss
565
573
            implemented operations.
566
574
        """
567
 
        assert not isinstance(repository, RemoteRepository)
 
575
        if isinstance(repository, RemoteRepository):
 
576
            raise AssertionError()
568
577
        self._real_repository = repository
569
578
        if self._lock_mode == 'w':
570
579
            # if we are already locked, the real repository must be able to
1167
1176
        self._dir_mode = None
1168
1177
        self._file_mode = None
1169
1178
 
1170
 
    def get(self, path):
1171
 
        """'get' a remote path as per the LockableFiles interface.
1172
 
 
1173
 
        :param path: the file to 'get'. If this is 'branch.conf', we do not
1174
 
             just retrieve a file, instead we ask the smart server to generate
1175
 
             a configuration for us - which is retrieved as an INI file.
1176
 
        """
1177
 
        if path == 'branch.conf':
1178
 
            path = self.bzrdir._path_for_remote_call(self._client)
1179
 
            response = self._client.call_expecting_body(
1180
 
                'Branch.get_config_file', path)
1181
 
            assert response[0][0] == 'ok', \
1182
 
                'unexpected response code %s' % (response[0],)
1183
 
            return StringIO(response[1].read_body_bytes())
1184
 
        else:
1185
 
            # VFS fallback.
1186
 
            return LockableFiles.get(self, path)
1187
 
 
1188
1179
 
1189
1180
class RemoteBranchFormat(branch.BranchFormat):
1190
1181
 
1199
1190
        return 'Remote BZR Branch'
1200
1191
 
1201
1192
    def open(self, a_bzrdir):
1202
 
        assert isinstance(a_bzrdir, RemoteBzrDir)
1203
1193
        return a_bzrdir.open_branch()
1204
1194
 
1205
1195
    def initialize(self, a_bzrdir):
1206
 
        assert isinstance(a_bzrdir, RemoteBzrDir)
1207
1196
        return a_bzrdir.create_branch()
1208
1197
 
1209
1198
    def supports_tags(self):
1270
1259
        Used before calls to self._real_branch.
1271
1260
        """
1272
1261
        if not self._real_branch:
1273
 
            assert vfs.vfs_enabled()
 
1262
            if not vfs.vfs_enabled():
 
1263
                raise AssertionError('smart server vfs must be enabled '
 
1264
                    'to use vfs implementation')
1274
1265
            self.bzrdir._ensure_real()
1275
1266
            self._real_branch = self.bzrdir._real_bzrdir.open_branch()
1276
1267
            # Give the remote repository the matching real repo.
1345
1336
        if not self._lock_mode:
1346
1337
            remote_tokens = self._remote_lock_write(token)
1347
1338
            self._lock_token, self._repo_lock_token = remote_tokens
1348
 
            assert self._lock_token, 'Remote server did not return a token!'
 
1339
            if not self._lock_token:
 
1340
                raise SmartProtocolError('Remote server did not return a token!')
1349
1341
            # TODO: We really, really, really don't want to call _ensure_real
1350
1342
            # here, but it's the easiest way to ensure coherency between the
1351
1343
            # state of the RemoteBranch and RemoteRepository objects and the
1412
1404
                # Only write-locked branched need to make a remote method call
1413
1405
                # to perfom the unlock.
1414
1406
                return
1415
 
            assert self._lock_token, 'Locked, but no token!'
 
1407
            if not self._lock_token:
 
1408
                raise AssertionError('Locked, but no token!')
1416
1409
            branch_token = self._lock_token
1417
1410
            repo_token = self._repo_lock_token
1418
1411
            self._lock_token = None
1438
1431
        """See Branch.last_revision_info()."""
1439
1432
        path = self.bzrdir._path_for_remote_call(self._client)
1440
1433
        response = self._client.call('Branch.last_revision_info', path)
1441
 
        assert response[0] == 'ok', 'unexpected response code %s' % (response,)
 
1434
        if response[0] != 'ok':
 
1435
            raise SmartProtocolError('unexpected response code %s' % (response,))
1442
1436
        revno = int(response[1])
1443
1437
        last_revision = response[2]
1444
1438
        return (revno, last_revision)
1448
1442
        path = self.bzrdir._path_for_remote_call(self._client)
1449
1443
        response = self._client.call_expecting_body(
1450
1444
            'Branch.revision_history', path)
1451
 
        assert response[0][0] == 'ok', ('unexpected response code %s'
1452
 
                                        % (response[0],))
 
1445
        if response[0][0] != 'ok':
 
1446
            raise SmartProtocolError('unexpected response code %s' % (response,))
1453
1447
        result = response[1].read_body_bytes().split('\x00')
1454
1448
        if result == ['']:
1455
1449
            return []
1485
1479
        self._ensure_real()
1486
1480
        return self._real_branch.set_parent(url)
1487
1481
        
1488
 
    def get_config(self):
1489
 
        return RemoteBranchConfig(self)
1490
 
 
1491
1482
    def sprout(self, to_bzrdir, revision_id=None):
1492
1483
        # Like Branch.sprout, except that it sprouts a branch in the default
1493
1484
        # format, because RemoteBranches can't be created at arbitrary URLs.
1524
1515
 
1525
1516
    @needs_write_lock
1526
1517
    def set_last_revision_info(self, revno, revision_id):
1527
 
        assert type(revno) is int
1528
1518
        revision_id = ensure_null(revision_id)
1529
1519
        path = self.bzrdir._path_for_remote_call(self._client)
1530
1520
        try:
1563
1553
            other, stop_revision=stop_revision, overwrite=overwrite)
1564
1554
 
1565
1555
 
1566
 
class RemoteBranchConfig(BranchConfig):
1567
 
 
1568
 
    def username(self):
1569
 
        self.branch._ensure_real()
1570
 
        return self.branch._real_branch.get_config().username()
1571
 
 
1572
 
    def _get_branch_data_config(self):
1573
 
        self.branch._ensure_real()
1574
 
        if self._branch_data_config is None:
1575
 
            self._branch_data_config = TreeConfig(self.branch._real_branch)
1576
 
        return self._branch_data_config
1577
 
 
1578
 
 
1579
1556
def _extract_tar(tar, to_dir):
1580
1557
    """Extract all the contents of a tarfile object.
1581
1558