92
92
self._ensure_real()
93
93
return self._real_bzrdir.cloning_metadir()
95
def _translate_error(self, err, **context):
96
_translate_error(err, bzrdir=self, **context)
95
98
def create_repository(self, shared=False):
96
99
self._ensure_real()
97
100
self._real_bzrdir.create_repository(shared=shared)
130
133
response = self._client.call('BzrDir.open_branch', path)
131
134
except errors.ErrorFromSmartServer, err:
132
if err.error_tuple == ('nobranch',):
133
raise errors.NotBranchError(path=self.root_transport.base)
135
self._translate_error(err)
135
136
if response[0] == 'ok':
136
137
if response[1] == '':
137
138
# branch at this location.
168
169
verb = 'BzrDir.find_repository'
169
170
response = self._client.call(verb, path)
170
171
except errors.ErrorFromSmartServer, err:
171
if err.error_verb == 'norepository':
172
raise errors.NoRepositoryPresent(self)
172
self._translate_error(err)
174
173
if response[0] != 'ok':
175
174
raise errors.UnexpectedSmartServerResponse(response)
176
175
if verb == 'BzrDir.find_repository':
362
361
#self._real_repository = self.bzrdir._real_bzrdir.open_repository()
363
362
self._set_real_repository(self.bzrdir._real_bzrdir.open_repository())
364
def _translate_error(self, err, **context):
365
self.bzrdir._translate_error(err, repository=self, **context)
365
367
def find_text_key_references(self):
366
368
"""Find the text key references within the repository.
404
406
response = self._client.call_expecting_body(
405
407
'Repository.get_revision_graph', path, revision_id)
406
408
except errors.ErrorFromSmartServer, err:
407
if err.error_verb == 'nosuchrevision':
408
raise NoSuchRevision(self, revision_id)
409
self._translate_error(err)
410
410
response_tuple, response_handler = response
411
411
if response_tuple[0] != 'ok':
412
412
raise errors.UnexpectedSmartServerResponse(response_tuple)
542
542
response = self._client.call('Repository.lock_write', path, token)
543
543
except errors.ErrorFromSmartServer, err:
544
if err.error_verb == 'LockContention':
545
raise errors.LockContention('(remote lock)')
546
elif err.error_verb == 'UnlockableTransport':
547
raise errors.UnlockableTransport(self.bzrdir.root_transport)
548
elif err.error_verb == 'LockFailed':
549
raise errors.LockFailed(err.error_args[0], err.error_args[1])
544
self._translate_error(err, token=token)
552
546
if response[0] == 'ok':
553
547
ok, token = response
625
619
response = self._client.call('Repository.unlock', path, token)
626
620
except errors.ErrorFromSmartServer, err:
627
if err.error_verb == 'TokenMismatch':
628
raise errors.TokenMismatch(token, '(remote token)')
621
self._translate_error(err, token=token)
630
622
if response == ('ok',):
824
816
self._ensure_real()
825
817
return self._real_repository.iter_files_bytes(desired_files)
820
def _fetch_order(self):
821
"""Decorate the real repository for now.
823
In the long term getting this back from the remote repository as part
824
of open would be more efficient.
827
return self._real_repository._fetch_order
830
def _fetch_uses_deltas(self):
831
"""Decorate the real repository for now.
833
In the long term getting this back from the remote repository as part
834
of open would be more efficient.
837
return self._real_repository._fetch_uses_deltas
840
def _fetch_reconcile(self):
841
"""Decorate the real repository for now.
843
In the long term getting this back from the remote repository as part
844
of open would be more efficient.
847
return self._real_repository._fetch_reconcile
827
849
def get_parent_map(self, keys):
828
850
"""See bzrlib.Graph.get_parent_map()."""
829
851
# Hack to build up the caching logic.
1292
1314
if self._lock_mode == 'r':
1293
1315
self._real_branch.lock_read()
1317
def _translate_error(self, err, **context):
1318
self.repository._translate_error(err, branch=self, **context)
1295
1320
def _clear_cached_state(self):
1296
1321
super(RemoteBranch, self)._clear_cached_state()
1297
1322
if self._real_branch is not None:
1361
1386
response = self._client.call(
1362
1387
'Branch.lock_write', path, branch_token, repo_token or '')
1363
1388
except errors.ErrorFromSmartServer, err:
1364
if err.error_verb == 'LockContention':
1365
raise errors.LockContention('(remote lock)')
1366
elif err.error_verb == 'TokenMismatch':
1367
raise errors.TokenMismatch(token, '(remote token)')
1368
elif err.error_verb == 'UnlockableTransport':
1369
raise errors.UnlockableTransport(self.bzrdir.root_transport)
1370
elif err.error_verb == 'ReadOnlyError':
1371
raise errors.ReadOnlyError(self)
1372
elif err.error_verb == 'LockFailed':
1373
raise errors.LockFailed(err.error_args[0], err.error_args[1])
1389
self._translate_error(err, token=token)
1375
1390
if response[0] != 'ok':
1376
1391
raise errors.UnexpectedSmartServerResponse(response)
1377
1392
ok, branch_token, repo_token = response
1422
1437
response = self._client.call('Branch.unlock', path, branch_token,
1423
1438
repo_token or '')
1424
1439
except errors.ErrorFromSmartServer, err:
1425
if err.error_verb == 'TokenMismatch':
1426
raise errors.TokenMismatch(
1427
str((branch_token, repo_token)), '(remote tokens)')
1440
self._translate_error(err, token=str((branch_token, repo_token)))
1429
1441
if response == ('ok',):
1431
1443
raise errors.UnexpectedSmartServerResponse(response)
1501
1513
path, self._lock_token, self._repo_lock_token, revision_id,
1502
1514
int(allow_diverged), int(allow_overwrite_descendant))
1503
1515
except errors.ErrorFromSmartServer, err:
1504
if err.error_verb == 'NoSuchRevision':
1505
raise NoSuchRevision(self, revision_id)
1506
elif err.error_verb == 'Diverged':
1507
raise errors.DivergedBranches(self, other_branch)
1516
self._translate_error(err, other_branch=other_branch)
1509
1517
self._clear_cached_state()
1510
1518
if len(response) != 3 and response[0] != 'ok':
1511
1519
raise errors.UnexpectedSmartServerResponse(response)
1520
1528
response = self._client.call('Branch.set_last_revision',
1521
1529
path, self._lock_token, self._repo_lock_token, revision_id)
1522
1530
except errors.ErrorFromSmartServer, err:
1523
if err.error_verb == 'NoSuchRevision':
1524
raise NoSuchRevision(self, revision_id)
1531
self._translate_error(err)
1526
1532
if response != ('ok',):
1527
1533
raise errors.UnexpectedSmartServerResponse(response)
1601
1607
self._last_revision_info_cache = revno, revision_id
1603
1609
except errors.ErrorFromSmartServer, err:
1604
if err.error_verb == 'NoSuchRevision':
1605
raise NoSuchRevision(self, err.error_args[0])
1610
self._translate_error(err)
1607
1611
if response == ('ok',):
1608
1612
self._clear_cached_state()
1609
1613
self._last_revision_info_cache = revno, revision_id
1687
1691
for tarinfo in tar:
1688
1692
tar.extract(tarinfo, to_dir)
1695
def _translate_error(err, **context):
1696
"""Translate an ErrorFromSmartServer into a more useful error.
1698
Possible context keys:
1707
return context[name]
1708
except KeyError, keyErr:
1709
mutter('Missing key %r in context %r', keyErr.args[0], context)
1711
if err.error_verb == 'NoSuchRevision':
1712
raise NoSuchRevision(find('branch'), err.error_args[0])
1713
elif err.error_verb == 'nosuchrevision':
1714
raise NoSuchRevision(find('repository'), err.error_args[0])
1715
elif err.error_tuple == ('nobranch',):
1716
raise errors.NotBranchError(path=find('bzrdir').root_transport.base)
1717
elif err.error_verb == 'norepository':
1718
raise errors.NoRepositoryPresent(find('bzrdir'))
1719
elif err.error_verb == 'LockContention':
1720
raise errors.LockContention('(remote lock)')
1721
elif err.error_verb == 'UnlockableTransport':
1722
raise errors.UnlockableTransport(find('bzrdir').root_transport)
1723
elif err.error_verb == 'LockFailed':
1724
raise errors.LockFailed(err.error_args[0], err.error_args[1])
1725
elif err.error_verb == 'TokenMismatch':
1726
raise errors.TokenMismatch(find('token'), '(remote token)')
1727
elif err.error_verb == 'Diverged':
1728
raise errors.DivergedBranches(find('branch'), find('other_branch'))
1729
elif err.error_verb == 'TipChangeRejected':
1730
raise errors.TipChangeRejected(err.error_args[0].decode('utf8'))