~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Robert Collins
  • Date: 2010-05-06 07:48:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506074822-0bsgf2j4h8jx0xkk
Added ``bzrlib.tests.matchers`` as a place to put matchers, along with
our first in-tree matcher. See the module docstring for details.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
27
27
    lock,
28
28
    lockdir,
29
29
    repository,
 
30
    repository as _mod_repository,
30
31
    revision,
31
32
    revision as _mod_revision,
 
33
    static_tuple,
32
34
    symbol_versioning,
33
35
)
34
36
from bzrlib.branch import BranchReferenceFormat
35
37
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
36
 
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
38
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
37
39
from bzrlib.errors import (
38
40
    NoSuchRevision,
39
41
    SmartProtocolError,
89
91
class RemoteBzrDir(BzrDir, _RpcHelper):
90
92
    """Control directory on a remote server, accessed via bzr:// or similar."""
91
93
 
92
 
    def __init__(self, transport, format, _client=None):
 
94
    def __init__(self, transport, format, _client=None, _force_probe=False):
93
95
        """Construct a RemoteBzrDir.
94
96
 
95
97
        :param _client: Private parameter for testing. Disables probing and the
99
101
        # this object holds a delegated bzrdir that uses file-level operations
100
102
        # to talk to the other side
101
103
        self._real_bzrdir = None
 
104
        self._has_working_tree = None
102
105
        # 1-shot cache for the call pattern 'create_branch; open_branch' - see
103
106
        # create_branch for details.
104
107
        self._next_open_branch_result = None
108
111
            self._client = client._SmartClient(medium)
109
112
        else:
110
113
            self._client = _client
111
 
            return
112
 
 
 
114
            if not _force_probe:
 
115
                return
 
116
 
 
117
        self._probe_bzrdir()
 
118
 
 
119
    def __repr__(self):
 
120
        return '%s(%r)' % (self.__class__.__name__, self._client)
 
121
 
 
122
    def _probe_bzrdir(self):
 
123
        medium = self._client._medium
113
124
        path = self._path_for_remote_call(self._client)
 
125
        if medium._is_remote_before((2, 1)):
 
126
            self._rpc_open(path)
 
127
            return
 
128
        try:
 
129
            self._rpc_open_2_1(path)
 
130
            return
 
131
        except errors.UnknownSmartMethod:
 
132
            medium._remember_remote_is_before((2, 1))
 
133
            self._rpc_open(path)
 
134
 
 
135
    def _rpc_open_2_1(self, path):
 
136
        response = self._call('BzrDir.open_2.1', path)
 
137
        if response == ('no',):
 
138
            raise errors.NotBranchError(path=self.root_transport.base)
 
139
        elif response[0] == 'yes':
 
140
            if response[1] == 'yes':
 
141
                self._has_working_tree = True
 
142
            elif response[1] == 'no':
 
143
                self._has_working_tree = False
 
144
            else:
 
145
                raise errors.UnexpectedSmartServerResponse(response)
 
146
        else:
 
147
            raise errors.UnexpectedSmartServerResponse(response)
 
148
 
 
149
    def _rpc_open(self, path):
114
150
        response = self._call('BzrDir.open', path)
115
151
        if response not in [('yes',), ('no',)]:
116
152
            raise errors.UnexpectedSmartServerResponse(response)
117
153
        if response == ('no',):
118
 
            raise errors.NotBranchError(path=transport.base)
 
154
            raise errors.NotBranchError(path=self.root_transport.base)
119
155
 
120
156
    def _ensure_real(self):
121
157
        """Ensure that there is a _real_bzrdir set.
123
159
        Used before calls to self._real_bzrdir.
124
160
        """
125
161
        if not self._real_bzrdir:
 
162
            if 'hpssvfs' in debug.debug_flags:
 
163
                import traceback
 
164
                warning('VFS BzrDir access triggered\n%s',
 
165
                    ''.join(traceback.format_stack()))
126
166
            self._real_bzrdir = BzrDir.open_from_transport(
127
167
                self.root_transport, _server_formats=False)
128
168
            self._format._network_name = \
204
244
        self._ensure_real()
205
245
        self._real_bzrdir.destroy_repository()
206
246
 
207
 
    def create_branch(self):
 
247
    def create_branch(self, name=None):
208
248
        # as per meta1 formats - just delegate to the format object which may
209
249
        # be parameterised.
210
 
        real_branch = self._format.get_branch_format().initialize(self)
 
250
        real_branch = self._format.get_branch_format().initialize(self,
 
251
            name=name)
211
252
        if not isinstance(real_branch, RemoteBranch):
212
 
            result = RemoteBranch(self, self.find_repository(), real_branch)
 
253
            result = RemoteBranch(self, self.find_repository(), real_branch,
 
254
                                  name=name)
213
255
        else:
214
256
            result = real_branch
215
257
        # BzrDir.clone_on_transport() uses the result of create_branch but does
221
263
        self._next_open_branch_result = result
222
264
        return result
223
265
 
224
 
    def destroy_branch(self):
 
266
    def destroy_branch(self, name=None):
225
267
        """See BzrDir.destroy_branch"""
226
268
        self._ensure_real()
227
 
        self._real_bzrdir.destroy_branch()
 
269
        self._real_bzrdir.destroy_branch(name=name)
228
270
        self._next_open_branch_result = None
229
271
 
230
272
    def create_workingtree(self, revision_id=None, from_branch=None):
249
291
    def _get_branch_reference(self):
250
292
        path = self._path_for_remote_call(self._client)
251
293
        medium = self._client._medium
252
 
        if not medium._is_remote_before((1, 13)):
 
294
        candidate_calls = [
 
295
            ('BzrDir.open_branchV3', (2, 1)),
 
296
            ('BzrDir.open_branchV2', (1, 13)),
 
297
            ('BzrDir.open_branch', None),
 
298
            ]
 
299
        for verb, required_version in candidate_calls:
 
300
            if required_version and medium._is_remote_before(required_version):
 
301
                continue
253
302
            try:
254
 
                response = self._call('BzrDir.open_branchV2', path)
255
 
                if response[0] not in ('ref', 'branch'):
256
 
                    raise errors.UnexpectedSmartServerResponse(response)
257
 
                return response
 
303
                response = self._call(verb, path)
258
304
            except errors.UnknownSmartMethod:
259
 
                medium._remember_remote_is_before((1, 13))
260
 
        response = self._call('BzrDir.open_branch', path)
261
 
        if response[0] != 'ok':
 
305
                if required_version is None:
 
306
                    raise
 
307
                medium._remember_remote_is_before(required_version)
 
308
            else:
 
309
                break
 
310
        if verb == 'BzrDir.open_branch':
 
311
            if response[0] != 'ok':
 
312
                raise errors.UnexpectedSmartServerResponse(response)
 
313
            if response[1] != '':
 
314
                return ('ref', response[1])
 
315
            else:
 
316
                return ('branch', '')
 
317
        if response[0] not in ('ref', 'branch'):
262
318
            raise errors.UnexpectedSmartServerResponse(response)
263
 
        if response[1] != '':
264
 
            return ('ref', response[1])
265
 
        else:
266
 
            return ('branch', '')
 
319
        return response
267
320
 
268
321
    def _get_tree_branch(self):
269
322
        """See BzrDir._get_tree_branch()."""
270
323
        return None, self.open_branch()
271
324
 
272
 
    def open_branch(self, _unsupported=False, ignore_fallbacks=False):
273
 
        if _unsupported:
 
325
    def open_branch(self, name=None, unsupported=False,
 
326
                    ignore_fallbacks=False):
 
327
        if unsupported:
274
328
            raise NotImplementedError('unsupported flag support not implemented yet.')
275
329
        if self._next_open_branch_result is not None:
276
330
            # See create_branch for details.
281
335
        if response[0] == 'ref':
282
336
            # a branch reference, use the existing BranchReference logic.
283
337
            format = BranchReferenceFormat()
284
 
            return format.open(self, _found=True, location=response[1],
285
 
                ignore_fallbacks=ignore_fallbacks)
 
338
            return format.open(self, name=name, _found=True,
 
339
                location=response[1], ignore_fallbacks=ignore_fallbacks)
286
340
        branch_format_name = response[1]
287
341
        if not branch_format_name:
288
342
            branch_format_name = None
289
343
        format = RemoteBranchFormat(network_name=branch_format_name)
290
344
        return RemoteBranch(self, self.find_repository(), format=format,
291
 
            setup_stacking=not ignore_fallbacks)
 
345
            setup_stacking=not ignore_fallbacks, name=name)
292
346
 
293
347
    def _open_repo_v1(self, path):
294
348
        verb = 'BzrDir.find_repository'
355
409
        else:
356
410
            raise errors.NoRepositoryPresent(self)
357
411
 
 
412
    def has_workingtree(self):
 
413
        if self._has_working_tree is None:
 
414
            self._ensure_real()
 
415
            self._has_working_tree = self._real_bzrdir.has_workingtree()
 
416
        return self._has_working_tree
 
417
 
358
418
    def open_workingtree(self, recommend_upgrade=True):
359
 
        self._ensure_real()
360
 
        if self._real_bzrdir.has_workingtree():
 
419
        if self.has_workingtree():
361
420
            raise errors.NotLocalUrl(self.root_transport)
362
421
        else:
363
422
            raise errors.NoWorkingTree(self.root_transport.base)
366
425
        """Return the path to be used for this bzrdir in a remote call."""
367
426
        return client.remote_path_from_transport(self.root_transport)
368
427
 
369
 
    def get_branch_transport(self, branch_format):
 
428
    def get_branch_transport(self, branch_format, name=None):
370
429
        self._ensure_real()
371
 
        return self._real_bzrdir.get_branch_transport(branch_format)
 
430
        return self._real_bzrdir.get_branch_transport(branch_format, name=name)
372
431
 
373
432
    def get_repository_transport(self, repository_format):
374
433
        self._ensure_real()
561
620
        return self._custom_format._fetch_reconcile
562
621
 
563
622
    def get_format_description(self):
564
 
        return 'bzr remote repository'
 
623
        self._ensure_real()
 
624
        return 'Remote: ' + self._custom_format.get_format_description()
565
625
 
566
626
    def __eq__(self, other):
567
627
        return self.__class__ is other.__class__
583
643
        return self._custom_format._serializer
584
644
 
585
645
 
586
 
class RemoteRepository(_RpcHelper):
 
646
class RemoteRepository(_RpcHelper, lock._RelockDebugMixin,
 
647
    bzrdir.ControlComponent):
587
648
    """Repository accessed over rpc.
588
649
 
589
650
    For the moment most operations are performed using local transport-backed
632
693
        # Additional places to query for data.
633
694
        self._fallback_repositories = []
634
695
 
 
696
    @property
 
697
    def user_transport(self):
 
698
        return self.bzrdir.user_transport
 
699
 
 
700
    @property
 
701
    def control_transport(self):
 
702
        # XXX: Normally you shouldn't directly get at the remote repository
 
703
        # transport, but I'm not sure it's worth making this method
 
704
        # optional -- mbp 2010-04-21
 
705
        return self.bzrdir.get_repository_transport(None)
 
706
        
635
707
    def __str__(self):
636
708
        return "%s(%s)" % (self.__class__.__name__, self.base)
637
709
 
845
917
        parents_provider = self._make_parents_provider(other_repository)
846
918
        return graph.Graph(parents_provider)
847
919
 
 
920
    @needs_read_lock
 
921
    def get_known_graph_ancestry(self, revision_ids):
 
922
        """Return the known graph for a set of revision ids and their ancestors.
 
923
        """
 
924
        st = static_tuple.StaticTuple
 
925
        revision_keys = [st(r_id).intern() for r_id in revision_ids]
 
926
        known_graph = self.revisions.get_known_graph_ancestry(revision_keys)
 
927
        return graph.GraphThunkIdsToKeys(known_graph)
 
928
 
848
929
    def gather_stats(self, revid=None, committers=None):
849
930
        """See Repository.gather_stats()."""
850
931
        path = self.bzrdir._path_for_remote_call(self._client)
910
991
    def is_write_locked(self):
911
992
        return self._lock_mode == 'w'
912
993
 
 
994
    def _warn_if_deprecated(self, branch=None):
 
995
        # If we have a real repository, the check will be done there, if we
 
996
        # don't the check will be done remotely.
 
997
        pass
 
998
 
913
999
    def lock_read(self):
914
1000
        # wrong eventually - want a local lock cache context
915
1001
        if not self._lock_mode:
 
1002
            self._note_lock('r')
916
1003
            self._lock_mode = 'r'
917
1004
            self._lock_count = 1
918
1005
            self._unstacked_provider.enable_cache(cache_misses=True)
938
1025
 
939
1026
    def lock_write(self, token=None, _skip_rpc=False):
940
1027
        if not self._lock_mode:
 
1028
            self._note_lock('w')
941
1029
            if _skip_rpc:
942
1030
                if self._lock_token is not None:
943
1031
                    if token != self._lock_token:
1046
1134
        else:
1047
1135
            raise errors.UnexpectedSmartServerResponse(response)
1048
1136
 
 
1137
    @only_raises(errors.LockNotHeld, errors.LockBroken)
1049
1138
    def unlock(self):
1050
1139
        if not self._lock_count:
1051
1140
            return lock.cant_unlock_not_held(self)
1151
1240
            # state, so always add a lock here. If a caller passes us a locked
1152
1241
            # repository, they are responsible for unlocking it later.
1153
1242
            repository.lock_read()
 
1243
        self._check_fallback_repository(repository)
1154
1244
        self._fallback_repositories.append(repository)
1155
1245
        # If self._real_repository was parameterised already (e.g. because a
1156
1246
        # _real_branch had its get_stacked_on_url method called), then the
1157
1247
        # repository to be added may already be in the _real_repositories list.
1158
1248
        if self._real_repository is not None:
1159
 
            fallback_locations = [repo.bzrdir.root_transport.base for repo in
 
1249
            fallback_locations = [repo.user_url for repo in
1160
1250
                self._real_repository._fallback_repositories]
1161
 
            if repository.bzrdir.root_transport.base not in fallback_locations:
 
1251
            if repository.user_url not in fallback_locations:
1162
1252
                self._real_repository.add_fallback_repository(repository)
1163
1253
 
 
1254
    def _check_fallback_repository(self, repository):
 
1255
        """Check that this repository can fallback to repository safely.
 
1256
 
 
1257
        Raise an error if not.
 
1258
 
 
1259
        :param repository: A repository to fallback to.
 
1260
        """
 
1261
        return _mod_repository.InterRepository._assert_same_model(
 
1262
            self, repository)
 
1263
 
1164
1264
    def add_inventory(self, revid, inv, parents):
1165
1265
        self._ensure_real()
1166
1266
        return self._real_repository.add_inventory(revid, inv, parents)
1167
1267
 
1168
1268
    def add_inventory_by_delta(self, basis_revision_id, delta, new_revision_id,
1169
 
                               parents):
 
1269
            parents, basis_inv=None, propagate_caches=False):
1170
1270
        self._ensure_real()
1171
1271
        return self._real_repository.add_inventory_by_delta(basis_revision_id,
1172
 
            delta, new_revision_id, parents)
 
1272
            delta, new_revision_id, parents, basis_inv=basis_inv,
 
1273
            propagate_caches=propagate_caches)
1173
1274
 
1174
1275
    def add_revision(self, rev_id, rev, inv=None, config=None):
1175
1276
        self._ensure_real()
1434
1535
        return self._real_repository.get_signature_text(revision_id)
1435
1536
 
1436
1537
    @needs_read_lock
1437
 
    def get_inventory_xml(self, revision_id):
1438
 
        self._ensure_real()
1439
 
        return self._real_repository.get_inventory_xml(revision_id)
1440
 
 
1441
 
    def deserialise_inventory(self, revision_id, xml):
1442
 
        self._ensure_real()
1443
 
        return self._real_repository.deserialise_inventory(revision_id, xml)
 
1538
    def _get_inventory_xml(self, revision_id):
 
1539
        self._ensure_real()
 
1540
        return self._real_repository._get_inventory_xml(revision_id)
1444
1541
 
1445
1542
    def reconcile(self, other=None, thorough=False):
1446
1543
        self._ensure_real()
1522
1619
        return self._real_repository.inventories
1523
1620
 
1524
1621
    @needs_write_lock
1525
 
    def pack(self, hint=None):
 
1622
    def pack(self, hint=None, clean_obsolete_packs=False):
1526
1623
        """Compress the data within the repository.
1527
1624
 
1528
1625
        This is not currently implemented within the smart server.
1529
1626
        """
1530
1627
        self._ensure_real()
1531
 
        return self._real_repository.pack(hint=hint)
 
1628
        return self._real_repository.pack(hint=hint, clean_obsolete_packs=clean_obsolete_packs)
1532
1629
 
1533
1630
    @property
1534
1631
    def revisions(self):
1956
2053
                self._network_name)
1957
2054
 
1958
2055
    def get_format_description(self):
1959
 
        return 'Remote BZR Branch'
 
2056
        self._ensure_real()
 
2057
        return 'Remote: ' + self._custom_format.get_format_description()
1960
2058
 
1961
2059
    def network_name(self):
1962
2060
        return self._network_name
1963
2061
 
1964
 
    def open(self, a_bzrdir, ignore_fallbacks=False):
1965
 
        return a_bzrdir.open_branch(ignore_fallbacks=ignore_fallbacks)
 
2062
    def open(self, a_bzrdir, name=None, ignore_fallbacks=False):
 
2063
        return a_bzrdir.open_branch(name=name, 
 
2064
            ignore_fallbacks=ignore_fallbacks)
1966
2065
 
1967
 
    def _vfs_initialize(self, a_bzrdir):
 
2066
    def _vfs_initialize(self, a_bzrdir, name):
1968
2067
        # Initialisation when using a local bzrdir object, or a non-vfs init
1969
2068
        # method is not available on the server.
1970
2069
        # self._custom_format is always set - the start of initialize ensures
1971
2070
        # that.
1972
2071
        if isinstance(a_bzrdir, RemoteBzrDir):
1973
2072
            a_bzrdir._ensure_real()
1974
 
            result = self._custom_format.initialize(a_bzrdir._real_bzrdir)
 
2073
            result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
 
2074
                name)
1975
2075
        else:
1976
2076
            # We assume the bzrdir is parameterised; it may not be.
1977
 
            result = self._custom_format.initialize(a_bzrdir)
 
2077
            result = self._custom_format.initialize(a_bzrdir, name)
1978
2078
        if (isinstance(a_bzrdir, RemoteBzrDir) and
1979
2079
            not isinstance(result, RemoteBranch)):
1980
 
            result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result)
 
2080
            result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result,
 
2081
                                  name=name)
1981
2082
        return result
1982
2083
 
1983
 
    def initialize(self, a_bzrdir):
 
2084
    def initialize(self, a_bzrdir, name=None):
1984
2085
        # 1) get the network name to use.
1985
2086
        if self._custom_format:
1986
2087
            network_name = self._custom_format.network_name()
1992
2093
            network_name = reference_format.network_name()
1993
2094
        # Being asked to create on a non RemoteBzrDir:
1994
2095
        if not isinstance(a_bzrdir, RemoteBzrDir):
1995
 
            return self._vfs_initialize(a_bzrdir)
 
2096
            return self._vfs_initialize(a_bzrdir, name=name)
1996
2097
        medium = a_bzrdir._client._medium
1997
2098
        if medium._is_remote_before((1, 13)):
1998
 
            return self._vfs_initialize(a_bzrdir)
 
2099
            return self._vfs_initialize(a_bzrdir, name=name)
1999
2100
        # Creating on a remote bzr dir.
2000
2101
        # 2) try direct creation via RPC
2001
2102
        path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
 
2103
        if name is not None:
 
2104
            # XXX JRV20100304: Support creating colocated branches
 
2105
            raise errors.NoColocatedBranchSupport(self)
2002
2106
        verb = 'BzrDir.create_branch'
2003
2107
        try:
2004
2108
            response = a_bzrdir._call(verb, path, network_name)
2005
2109
        except errors.UnknownSmartMethod:
2006
2110
            # Fallback - use vfs methods
2007
2111
            medium._remember_remote_is_before((1, 13))
2008
 
            return self._vfs_initialize(a_bzrdir)
 
2112
            return self._vfs_initialize(a_bzrdir, name=name)
2009
2113
        if response[0] != 'ok':
2010
2114
            raise errors.UnexpectedSmartServerResponse(response)
2011
2115
        # Turn the response into a RemoteRepository object.
2019
2123
                a_bzrdir._client)
2020
2124
        remote_repo = RemoteRepository(repo_bzrdir, repo_format)
2021
2125
        remote_branch = RemoteBranch(a_bzrdir, remote_repo,
2022
 
            format=format, setup_stacking=False)
 
2126
            format=format, setup_stacking=False, name=name)
2023
2127
        # XXX: We know this is a new branch, so it must have revno 0, revid
2024
2128
        # NULL_REVISION. Creating the branch locked would make this be unable
2025
2129
        # to be wrong; here its simply very unlikely to be wrong. RBC 20090225
2045
2149
        return self._custom_format.supports_set_append_revisions_only()
2046
2150
 
2047
2151
 
2048
 
class RemoteBranch(branch.Branch, _RpcHelper):
 
2152
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2049
2153
    """Branch stored on a server accessed by HPSS RPC.
2050
2154
 
2051
2155
    At the moment most operations are mapped down to simple file operations.
2052
2156
    """
2053
2157
 
2054
2158
    def __init__(self, remote_bzrdir, remote_repository, real_branch=None,
2055
 
        _client=None, format=None, setup_stacking=True):
 
2159
        _client=None, format=None, setup_stacking=True, name=None):
2056
2160
        """Create a RemoteBranch instance.
2057
2161
 
2058
2162
        :param real_branch: An optional local implementation of the branch
2064
2168
        :param setup_stacking: If True make an RPC call to determine the
2065
2169
            stacked (or not) status of the branch. If False assume the branch
2066
2170
            is not stacked.
 
2171
        :param name: Colocated branch name
2067
2172
        """
2068
2173
        # We intentionally don't call the parent class's __init__, because it
2069
2174
        # will try to assign to self.tags, which is a property in this subclass.
2088
2193
            self._real_branch = None
2089
2194
        # Fill out expected attributes of branch for bzrlib API users.
2090
2195
        self._clear_cached_state()
2091
 
        self.base = self.bzrdir.root_transport.base
 
2196
        # TODO: deprecate self.base in favor of user_url
 
2197
        self.base = self.bzrdir.user_url
 
2198
        self._name = name
2092
2199
        self._control_files = None
2093
2200
        self._lock_mode = None
2094
2201
        self._lock_token = None
2159
2266
                    'to use vfs implementation')
2160
2267
            self.bzrdir._ensure_real()
2161
2268
            self._real_branch = self.bzrdir._real_bzrdir.open_branch(
2162
 
                ignore_fallbacks=self._real_ignore_fallbacks)
 
2269
                ignore_fallbacks=self._real_ignore_fallbacks, name=self._name)
2163
2270
            if self.repository._real_repository is None:
2164
2271
                # Give the remote repository the matching real repo.
2165
2272
                real_repo = self._real_branch.repository
2282
2389
    def lock_read(self):
2283
2390
        self.repository.lock_read()
2284
2391
        if not self._lock_mode:
 
2392
            self._note_lock('r')
2285
2393
            self._lock_mode = 'r'
2286
2394
            self._lock_count = 1
2287
2395
            if self._real_branch is not None:
2307
2415
 
2308
2416
    def lock_write(self, token=None):
2309
2417
        if not self._lock_mode:
 
2418
            self._note_lock('w')
2310
2419
            # Lock the branch and repo in one remote call.
2311
2420
            remote_tokens = self._remote_lock_write(token)
2312
2421
            self._lock_token, self._repo_lock_token = remote_tokens
2347
2456
            return
2348
2457
        raise errors.UnexpectedSmartServerResponse(response)
2349
2458
 
 
2459
    @only_raises(errors.LockNotHeld, errors.LockBroken)
2350
2460
    def unlock(self):
2351
2461
        try:
2352
2462
            self._lock_count -= 1
2770
2880
        raise NoSuchRevision(find('branch'), err.error_args[0])
2771
2881
    elif err.error_verb == 'nosuchrevision':
2772
2882
        raise NoSuchRevision(find('repository'), err.error_args[0])
2773
 
    elif err.error_tuple == ('nobranch',):
2774
 
        raise errors.NotBranchError(path=find('bzrdir').root_transport.base)
 
2883
    elif err.error_verb == 'nobranch':
 
2884
        if len(err.error_args) >= 1:
 
2885
            extra = err.error_args[0]
 
2886
        else:
 
2887
            extra = None
 
2888
        raise errors.NotBranchError(path=find('bzrdir').root_transport.base,
 
2889
            detail=extra)
2775
2890
    elif err.error_verb == 'norepository':
2776
2891
        raise errors.NoRepositoryPresent(find('bzrdir'))
2777
2892
    elif err.error_verb == 'LockContention':