~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

(gz) Fix test failure on alpha by correcting format string for
 gc_chk_sha1_record (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from bzrlib import (
20
20
    bencode,
21
21
    branch,
22
 
    bzrdir as _mod_bzrdir,
 
22
    bzrdir,
23
23
    config,
24
24
    controldir,
25
25
    debug,
27
27
    graph,
28
28
    lock,
29
29
    lockdir,
 
30
    repository,
30
31
    repository as _mod_repository,
 
32
    revision,
31
33
    revision as _mod_revision,
32
34
    static_tuple,
33
35
    symbol_versioning,
34
36
    urlutils,
35
 
    vf_repository,
36
 
    )
 
37
)
37
38
from bzrlib.branch import BranchReferenceFormat, BranchWriteLockResult
 
39
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
38
40
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
39
41
from bzrlib.errors import (
40
42
    NoSuchRevision,
41
43
    SmartProtocolError,
42
44
    )
43
 
from bzrlib.i18n import gettext
44
45
from bzrlib.lockable_files import LockableFiles
45
46
from bzrlib.smart import client, vfs, repository as smart_repo
46
 
from bzrlib.smart.client import _SmartClient
47
 
from bzrlib.revision import NULL_REVISION
48
 
from bzrlib.repository import RepositoryWriteLockResult, _LazyListJoin
 
47
from bzrlib.revision import ensure_null, NULL_REVISION
 
48
from bzrlib.repository import RepositoryWriteLockResult
49
49
from bzrlib.trace import mutter, note, warning
50
50
 
51
51
 
52
 
_DEFAULT_SEARCH_DEPTH = 100
53
 
 
54
 
 
55
52
class _RpcHelper(object):
56
53
    """Mixin class that helps with issuing RPCs."""
57
54
 
92
89
    return format
93
90
 
94
91
 
95
 
# Note that RemoteBzrDirProber lives in bzrlib.bzrdir so bzrlib.remote
96
 
# does not have to be imported unless a remote format is involved.
97
 
 
98
 
class RemoteBzrDirFormat(_mod_bzrdir.BzrDirMetaFormat1):
99
 
    """Format representing bzrdirs accessed via a smart server"""
100
 
 
101
 
    supports_workingtrees = False
102
 
 
103
 
    def __init__(self):
104
 
        _mod_bzrdir.BzrDirMetaFormat1.__init__(self)
105
 
        # XXX: It's a bit ugly that the network name is here, because we'd
106
 
        # like to believe that format objects are stateless or at least
107
 
        # immutable,  However, we do at least avoid mutating the name after
108
 
        # it's returned.  See <https://bugs.launchpad.net/bzr/+bug/504102>
109
 
        self._network_name = None
110
 
 
111
 
    def __repr__(self):
112
 
        return "%s(_network_name=%r)" % (self.__class__.__name__,
113
 
            self._network_name)
114
 
 
115
 
    def get_format_description(self):
116
 
        if self._network_name:
117
 
            real_format = controldir.network_format_registry.get(self._network_name)
118
 
            return 'Remote: ' + real_format.get_format_description()
119
 
        return 'bzr remote bzrdir'
120
 
 
121
 
    def get_format_string(self):
122
 
        raise NotImplementedError(self.get_format_string)
123
 
 
124
 
    def network_name(self):
125
 
        if self._network_name:
126
 
            return self._network_name
127
 
        else:
128
 
            raise AssertionError("No network name set.")
129
 
 
130
 
    def initialize_on_transport(self, transport):
131
 
        try:
132
 
            # hand off the request to the smart server
133
 
            client_medium = transport.get_smart_medium()
134
 
        except errors.NoSmartMedium:
135
 
            # TODO: lookup the local format from a server hint.
136
 
            local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
137
 
            return local_dir_format.initialize_on_transport(transport)
138
 
        client = _SmartClient(client_medium)
139
 
        path = client.remote_path_from_transport(transport)
140
 
        try:
141
 
            response = client.call('BzrDirFormat.initialize', path)
142
 
        except errors.ErrorFromSmartServer, err:
143
 
            _translate_error(err, path=path)
144
 
        if response[0] != 'ok':
145
 
            raise errors.SmartProtocolError('unexpected response code %s' % (response,))
146
 
        format = RemoteBzrDirFormat()
147
 
        self._supply_sub_formats_to(format)
148
 
        return RemoteBzrDir(transport, format)
149
 
 
150
 
    def parse_NoneTrueFalse(self, arg):
151
 
        if not arg:
152
 
            return None
153
 
        if arg == 'False':
154
 
            return False
155
 
        if arg == 'True':
156
 
            return True
157
 
        raise AssertionError("invalid arg %r" % arg)
158
 
 
159
 
    def _serialize_NoneTrueFalse(self, arg):
160
 
        if arg is False:
161
 
            return 'False'
162
 
        if arg:
163
 
            return 'True'
164
 
        return ''
165
 
 
166
 
    def _serialize_NoneString(self, arg):
167
 
        return arg or ''
168
 
 
169
 
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
170
 
        create_prefix=False, force_new_repo=False, stacked_on=None,
171
 
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
172
 
        shared_repo=False):
173
 
        try:
174
 
            # hand off the request to the smart server
175
 
            client_medium = transport.get_smart_medium()
176
 
        except errors.NoSmartMedium:
177
 
            do_vfs = True
178
 
        else:
179
 
            # Decline to open it if the server doesn't support our required
180
 
            # version (3) so that the VFS-based transport will do it.
181
 
            if client_medium.should_probe():
182
 
                try:
183
 
                    server_version = client_medium.protocol_version()
184
 
                    if server_version != '2':
185
 
                        do_vfs = True
186
 
                    else:
187
 
                        do_vfs = False
188
 
                except errors.SmartProtocolError:
189
 
                    # Apparently there's no usable smart server there, even though
190
 
                    # the medium supports the smart protocol.
191
 
                    do_vfs = True
192
 
            else:
193
 
                do_vfs = False
194
 
        if not do_vfs:
195
 
            client = _SmartClient(client_medium)
196
 
            path = client.remote_path_from_transport(transport)
197
 
            if client_medium._is_remote_before((1, 16)):
198
 
                do_vfs = True
199
 
        if do_vfs:
200
 
            # TODO: lookup the local format from a server hint.
201
 
            local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
202
 
            self._supply_sub_formats_to(local_dir_format)
203
 
            return local_dir_format.initialize_on_transport_ex(transport,
204
 
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
205
 
                force_new_repo=force_new_repo, stacked_on=stacked_on,
206
 
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
207
 
                make_working_trees=make_working_trees, shared_repo=shared_repo,
208
 
                vfs_only=True)
209
 
        return self._initialize_on_transport_ex_rpc(client, path, transport,
210
 
            use_existing_dir, create_prefix, force_new_repo, stacked_on,
211
 
            stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
212
 
 
213
 
    def _initialize_on_transport_ex_rpc(self, client, path, transport,
214
 
        use_existing_dir, create_prefix, force_new_repo, stacked_on,
215
 
        stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
216
 
        args = []
217
 
        args.append(self._serialize_NoneTrueFalse(use_existing_dir))
218
 
        args.append(self._serialize_NoneTrueFalse(create_prefix))
219
 
        args.append(self._serialize_NoneTrueFalse(force_new_repo))
220
 
        args.append(self._serialize_NoneString(stacked_on))
221
 
        # stack_on_pwd is often/usually our transport
222
 
        if stack_on_pwd:
223
 
            try:
224
 
                stack_on_pwd = transport.relpath(stack_on_pwd)
225
 
                if not stack_on_pwd:
226
 
                    stack_on_pwd = '.'
227
 
            except errors.PathNotChild:
228
 
                pass
229
 
        args.append(self._serialize_NoneString(stack_on_pwd))
230
 
        args.append(self._serialize_NoneString(repo_format_name))
231
 
        args.append(self._serialize_NoneTrueFalse(make_working_trees))
232
 
        args.append(self._serialize_NoneTrueFalse(shared_repo))
233
 
        request_network_name = self._network_name or \
234
 
            _mod_bzrdir.BzrDirFormat.get_default_format().network_name()
235
 
        try:
236
 
            response = client.call('BzrDirFormat.initialize_ex_1.16',
237
 
                request_network_name, path, *args)
238
 
        except errors.UnknownSmartMethod:
239
 
            client._medium._remember_remote_is_before((1,16))
240
 
            local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
241
 
            self._supply_sub_formats_to(local_dir_format)
242
 
            return local_dir_format.initialize_on_transport_ex(transport,
243
 
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
244
 
                force_new_repo=force_new_repo, stacked_on=stacked_on,
245
 
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
246
 
                make_working_trees=make_working_trees, shared_repo=shared_repo,
247
 
                vfs_only=True)
248
 
        except errors.ErrorFromSmartServer, err:
249
 
            _translate_error(err, path=path)
250
 
        repo_path = response[0]
251
 
        bzrdir_name = response[6]
252
 
        require_stacking = response[7]
253
 
        require_stacking = self.parse_NoneTrueFalse(require_stacking)
254
 
        format = RemoteBzrDirFormat()
255
 
        format._network_name = bzrdir_name
256
 
        self._supply_sub_formats_to(format)
257
 
        bzrdir = RemoteBzrDir(transport, format, _client=client)
258
 
        if repo_path:
259
 
            repo_format = response_tuple_to_repo_format(response[1:])
260
 
            if repo_path == '.':
261
 
                repo_path = ''
262
 
            if repo_path:
263
 
                repo_bzrdir_format = RemoteBzrDirFormat()
264
 
                repo_bzrdir_format._network_name = response[5]
265
 
                repo_bzr = RemoteBzrDir(transport.clone(repo_path),
266
 
                    repo_bzrdir_format)
267
 
            else:
268
 
                repo_bzr = bzrdir
269
 
            final_stack = response[8] or None
270
 
            final_stack_pwd = response[9] or None
271
 
            if final_stack_pwd:
272
 
                final_stack_pwd = urlutils.join(
273
 
                    transport.base, final_stack_pwd)
274
 
            remote_repo = RemoteRepository(repo_bzr, repo_format)
275
 
            if len(response) > 10:
276
 
                # Updated server verb that locks remotely.
277
 
                repo_lock_token = response[10] or None
278
 
                remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
279
 
                if repo_lock_token:
280
 
                    remote_repo.dont_leave_lock_in_place()
281
 
            else:
282
 
                remote_repo.lock_write()
283
 
            policy = _mod_bzrdir.UseExistingRepository(remote_repo, final_stack,
284
 
                final_stack_pwd, require_stacking)
285
 
            policy.acquire_repository()
286
 
        else:
287
 
            remote_repo = None
288
 
            policy = None
289
 
        bzrdir._format.set_branch_format(self.get_branch_format())
290
 
        if require_stacking:
291
 
            # The repo has already been created, but we need to make sure that
292
 
            # we'll make a stackable branch.
293
 
            bzrdir._format.require_stacking(_skip_repo=True)
294
 
        return remote_repo, bzrdir, require_stacking, policy
295
 
 
296
 
    def _open(self, transport):
297
 
        return RemoteBzrDir(transport, self)
298
 
 
299
 
    def __eq__(self, other):
300
 
        if not isinstance(other, RemoteBzrDirFormat):
301
 
            return False
302
 
        return self.get_format_description() == other.get_format_description()
303
 
 
304
 
    def __return_repository_format(self):
305
 
        # Always return a RemoteRepositoryFormat object, but if a specific bzr
306
 
        # repository format has been asked for, tell the RemoteRepositoryFormat
307
 
        # that it should use that for init() etc.
308
 
        result = RemoteRepositoryFormat()
309
 
        custom_format = getattr(self, '_repository_format', None)
310
 
        if custom_format:
311
 
            if isinstance(custom_format, RemoteRepositoryFormat):
312
 
                return custom_format
313
 
            else:
314
 
                # We will use the custom format to create repositories over the
315
 
                # wire; expose its details like rich_root_data for code to
316
 
                # query
317
 
                result._custom_format = custom_format
318
 
        return result
319
 
 
320
 
    def get_branch_format(self):
321
 
        result = _mod_bzrdir.BzrDirMetaFormat1.get_branch_format(self)
322
 
        if not isinstance(result, RemoteBranchFormat):
323
 
            new_result = RemoteBranchFormat()
324
 
            new_result._custom_format = result
325
 
            # cache the result
326
 
            self.set_branch_format(new_result)
327
 
            result = new_result
328
 
        return result
329
 
 
330
 
    repository_format = property(__return_repository_format,
331
 
        _mod_bzrdir.BzrDirMetaFormat1._set_repository_format) #.im_func)
332
 
 
333
 
 
334
 
class RemoteBzrDir(_mod_bzrdir.BzrDir, _RpcHelper):
 
92
# Note: RemoteBzrDirFormat is in bzrdir.py
 
93
 
 
94
class RemoteBzrDir(BzrDir, _RpcHelper):
335
95
    """Control directory on a remote server, accessed via bzr:// or similar."""
336
96
 
337
97
    def __init__(self, transport, format, _client=None, _force_probe=False):
340
100
        :param _client: Private parameter for testing. Disables probing and the
341
101
            use of a real bzrdir.
342
102
        """
343
 
        _mod_bzrdir.BzrDir.__init__(self, transport, format)
 
103
        BzrDir.__init__(self, transport, format)
344
104
        # this object holds a delegated bzrdir that uses file-level operations
345
105
        # to talk to the other side
346
106
        self._real_bzrdir = None
406
166
                import traceback
407
167
                warning('VFS BzrDir access triggered\n%s',
408
168
                    ''.join(traceback.format_stack()))
409
 
            self._real_bzrdir = _mod_bzrdir.BzrDir.open_from_transport(
 
169
            self._real_bzrdir = BzrDir.open_from_transport(
410
170
                self.root_transport, _server_formats=False)
411
171
            self._format._network_name = \
412
172
                self._real_bzrdir._format.network_name()
418
178
        # Prevent aliasing problems in the next_open_branch_result cache.
419
179
        # See create_branch for rationale.
420
180
        self._next_open_branch_result = None
421
 
        return _mod_bzrdir.BzrDir.break_lock(self)
 
181
        return BzrDir.break_lock(self)
422
182
 
423
183
    def _vfs_cloning_metadir(self, require_stacking=False):
424
184
        self._ensure_real()
457
217
        branch_ref, branch_name = branch_info
458
218
        format = controldir.network_format_registry.get(control_name)
459
219
        if repo_name:
460
 
            format.repository_format = _mod_repository.network_format_registry.get(
 
220
            format.repository_format = repository.network_format_registry.get(
461
221
                repo_name)
462
222
        if branch_ref == 'ref':
463
223
            # XXX: we need possible_transports here to avoid reopening the
464
224
            # connection to the referenced location
465
 
            ref_bzrdir = _mod_bzrdir.BzrDir.open(branch_name)
 
225
            ref_bzrdir = BzrDir.open(branch_name)
466
226
            branch_format = ref_bzrdir.cloning_metadir().get_branch_format()
467
227
            format.set_branch_format(branch_format)
468
228
        elif branch_ref == 'branch':
487
247
        self._ensure_real()
488
248
        self._real_bzrdir.destroy_repository()
489
249
 
490
 
    def create_branch(self, name=None, repository=None,
491
 
                      append_revisions_only=None):
 
250
    def create_branch(self, name=None, repository=None):
492
251
        # as per meta1 formats - just delegate to the format object which may
493
252
        # be parameterised.
494
253
        real_branch = self._format.get_branch_format().initialize(self,
495
 
            name=name, repository=repository,
496
 
            append_revisions_only=append_revisions_only)
 
254
            name=name, repository=repository)
497
255
        if not isinstance(real_branch, RemoteBranch):
498
256
            if not isinstance(repository, RemoteRepository):
499
257
                raise AssertionError(
675
433
 
676
434
    def _path_for_remote_call(self, client):
677
435
        """Return the path to be used for this bzrdir in a remote call."""
678
 
        return urlutils.split_segment_parameters_raw(
679
 
            client.remote_path_from_transport(self.root_transport))[0]
 
436
        return client.remote_path_from_transport(self.root_transport)
680
437
 
681
438
    def get_branch_transport(self, branch_format, name=None):
682
439
        self._ensure_real()
708
465
        return RemoteBzrDirConfig(self)
709
466
 
710
467
 
711
 
class RemoteRepositoryFormat(vf_repository.VersionedFileRepositoryFormat):
 
468
class RemoteRepositoryFormat(repository.RepositoryFormat):
712
469
    """Format for repositories accessed over a _SmartClient.
713
470
 
714
471
    Instances of this repository are represented by RemoteRepository
729
486
    """
730
487
 
731
488
    _matchingbzrdir = RemoteBzrDirFormat()
732
 
    supports_full_versioned_files = True
733
 
    supports_leaving_lock = True
734
489
 
735
490
    def __init__(self):
736
 
        _mod_repository.RepositoryFormat.__init__(self)
 
491
        repository.RepositoryFormat.__init__(self)
737
492
        self._custom_format = None
738
493
        self._network_name = None
739
494
        self._creating_bzrdir = None
740
 
        self._revision_graph_can_have_wrong_parents = None
741
495
        self._supports_chks = None
742
496
        self._supports_external_lookups = None
743
497
        self._supports_tree_reference = None
744
 
        self._supports_funky_characters = None
745
 
        self._supports_nesting_repositories = None
746
498
        self._rich_root_data = None
747
499
 
748
500
    def __repr__(self):
777
529
        return self._supports_external_lookups
778
530
 
779
531
    @property
780
 
    def supports_funky_characters(self):
781
 
        if self._supports_funky_characters is None:
782
 
            self._ensure_real()
783
 
            self._supports_funky_characters = \
784
 
                self._custom_format.supports_funky_characters
785
 
        return self._supports_funky_characters
786
 
 
787
 
    @property
788
 
    def supports_nesting_repositories(self):
789
 
        if self._supports_nesting_repositories is None:
790
 
            self._ensure_real()
791
 
            self._supports_nesting_repositories = \
792
 
                self._custom_format.supports_nesting_repositories
793
 
        return self._supports_nesting_repositories
794
 
 
795
 
    @property
796
532
    def supports_tree_reference(self):
797
533
        if self._supports_tree_reference is None:
798
534
            self._ensure_real()
800
536
                self._custom_format.supports_tree_reference
801
537
        return self._supports_tree_reference
802
538
 
803
 
    @property
804
 
    def revision_graph_can_have_wrong_parents(self):
805
 
        if self._revision_graph_can_have_wrong_parents is None:
806
 
            self._ensure_real()
807
 
            self._revision_graph_can_have_wrong_parents = \
808
 
                self._custom_format.revision_graph_can_have_wrong_parents
809
 
        return self._revision_graph_can_have_wrong_parents
810
 
 
811
539
    def _vfs_initialize(self, a_bzrdir, shared):
812
540
        """Helper for common code in initialize."""
813
541
        if self._custom_format:
848
576
            network_name = self._network_name
849
577
        else:
850
578
            # Select the current bzrlib default and ask for that.
851
 
            reference_bzrdir_format = _mod_bzrdir.format_registry.get('default')()
 
579
            reference_bzrdir_format = bzrdir.format_registry.get('default')()
852
580
            reference_format = reference_bzrdir_format.repository_format
853
581
            network_name = reference_format.network_name()
854
582
        # 2) try direct creation via RPC
880
608
 
881
609
    def _ensure_real(self):
882
610
        if self._custom_format is None:
883
 
            self._custom_format = _mod_repository.network_format_registry.get(
 
611
            self._custom_format = repository.network_format_registry.get(
884
612
                self._network_name)
885
613
 
886
614
    @property
982
710
        # transport, but I'm not sure it's worth making this method
983
711
        # optional -- mbp 2010-04-21
984
712
        return self.bzrdir.get_repository_transport(None)
985
 
 
 
713
        
986
714
    def __str__(self):
987
715
        return "%s(%s)" % (self.__class__.__name__, self.base)
988
716
 
1096
824
    def find_text_key_references(self):
1097
825
        """Find the text key references within the repository.
1098
826
 
 
827
        :return: a dictionary mapping (file_id, revision_id) tuples to altered file-ids to an iterable of
 
828
        revision_ids. Each altered file-ids has the exact revision_ids that
 
829
        altered it listed explicitly.
1099
830
        :return: A dictionary mapping text keys ((fileid, revision_id) tuples)
1100
831
            to whether they were referred to by the inventory of the
1101
832
            revision_id that they contain. The inventory texts from all present
1119
850
        """Private method for using with old (< 1.2) servers to fallback."""
1120
851
        if revision_id is None:
1121
852
            revision_id = ''
1122
 
        elif _mod_revision.is_null(revision_id):
 
853
        elif revision.is_null(revision_id):
1123
854
            return {}
1124
855
 
1125
856
        path = self.bzrdir._path_for_remote_call(self._client)
1149
880
        return RemoteStreamSource(self, to_format)
1150
881
 
1151
882
    @needs_read_lock
1152
 
    def get_file_graph(self):
1153
 
        return graph.Graph(self.texts)
1154
 
 
1155
 
    @needs_read_lock
1156
883
    def has_revision(self, revision_id):
1157
884
        """True if this repository has a copy of the revision."""
1158
885
        # Copy of bzrlib.repository.Repository.has_revision
1210
937
        """See Repository.gather_stats()."""
1211
938
        path = self.bzrdir._path_for_remote_call(self._client)
1212
939
        # revid can be None to indicate no revisions, not just NULL_REVISION
1213
 
        if revid is None or _mod_revision.is_null(revid):
 
940
        if revid is None or revision.is_null(revid):
1214
941
            fmt_revid = ''
1215
942
        else:
1216
943
            fmt_revid = revid
1499
1226
 
1500
1227
    def get_commit_builder(self, branch, parents, config, timestamp=None,
1501
1228
                           timezone=None, committer=None, revprops=None,
1502
 
                           revision_id=None, lossy=False):
 
1229
                           revision_id=None):
1503
1230
        # FIXME: It ought to be possible to call this without immediately
1504
1231
        # triggering _ensure_real.  For now it's the easiest thing to do.
1505
1232
        self._ensure_real()
1506
1233
        real_repo = self._real_repository
1507
1234
        builder = real_repo.get_commit_builder(branch, parents,
1508
1235
                config, timestamp=timestamp, timezone=timezone,
1509
 
                committer=committer, revprops=revprops,
1510
 
                revision_id=revision_id, lossy=lossy)
 
1236
                committer=committer, revprops=revprops, revision_id=revision_id)
1511
1237
        return builder
1512
1238
 
1513
1239
    def add_fallback_repository(self, repository):
1521
1247
        # We need to accumulate additional repositories here, to pass them in
1522
1248
        # on various RPC's.
1523
1249
        #
1524
 
        # Make the check before we lock: this raises an exception.
1525
 
        self._check_fallback_repository(repository)
1526
1250
        if self.is_locked():
1527
1251
            # We will call fallback.unlock() when we transition to the unlocked
1528
1252
            # state, so always add a lock here. If a caller passes us a locked
1529
1253
            # repository, they are responsible for unlocking it later.
1530
1254
            repository.lock_read()
 
1255
        self._check_fallback_repository(repository)
1531
1256
        self._fallback_repositories.append(repository)
1532
1257
        # If self._real_repository was parameterised already (e.g. because a
1533
1258
        # _real_branch had its get_stacked_on_url method called), then the
1622
1347
    @needs_read_lock
1623
1348
    def search_missing_revision_ids(self, other,
1624
1349
            revision_id=symbol_versioning.DEPRECATED_PARAMETER,
1625
 
            find_ghosts=True, revision_ids=None, if_present_ids=None,
1626
 
            limit=None):
 
1350
            find_ghosts=True, revision_ids=None, if_present_ids=None):
1627
1351
        """Return the revision ids that other has that this does not.
1628
1352
 
1629
1353
        These are returned in topological order.
1640
1364
                    'revision_ids is mutually exclusive with revision_id')
1641
1365
            if revision_id is not None:
1642
1366
                revision_ids = [revision_id]
1643
 
        inter_repo = _mod_repository.InterRepository.get(other, self)
 
1367
        inter_repo = repository.InterRepository.get(other, self)
1644
1368
        return inter_repo.search_missing_revision_ids(
1645
1369
            find_ghosts=find_ghosts, revision_ids=revision_ids,
1646
 
            if_present_ids=if_present_ids, limit=limit)
 
1370
            if_present_ids=if_present_ids)
1647
1371
 
1648
1372
    def fetch(self, source, revision_id=None, find_ghosts=False,
1649
1373
            fetch_spec=None):
1662
1386
            # check that last_revision is in 'from' and then return a
1663
1387
            # no-operation.
1664
1388
            if (revision_id is not None and
1665
 
                not _mod_revision.is_null(revision_id)):
 
1389
                not revision.is_null(revision_id)):
1666
1390
                self.get_revision(revision_id)
1667
1391
            return 0, []
1668
1392
        # if there is no specific appropriate InterRepository, this will get
1669
1393
        # the InterRepository base class, which raises an
1670
1394
        # IncompatibleRepositories when asked to fetch.
1671
 
        inter = _mod_repository.InterRepository.get(source, self)
 
1395
        inter = repository.InterRepository.get(source, self)
1672
1396
        return inter.fetch(revision_id=revision_id,
1673
1397
            find_ghosts=find_ghosts, fetch_spec=fetch_spec)
1674
1398
 
1677
1401
        self._real_repository.create_bundle(target, base, fileobj, format)
1678
1402
 
1679
1403
    @needs_read_lock
1680
 
    @symbol_versioning.deprecated_method(
1681
 
        symbol_versioning.deprecated_in((2, 4, 0)))
1682
1404
    def get_ancestry(self, revision_id, topo_sorted=True):
1683
1405
        self._ensure_real()
1684
1406
        return self._real_repository.get_ancestry(revision_id, topo_sorted)
1698
1420
        self._ensure_real()
1699
1421
        return self._real_repository.iter_files_bytes(desired_files)
1700
1422
 
1701
 
    def get_cached_parent_map(self, revision_ids):
1702
 
        """See bzrlib.CachingParentsProvider.get_cached_parent_map"""
1703
 
        return self._unstacked_provider.get_cached_parent_map(revision_ids)
1704
 
 
1705
1423
    def get_parent_map(self, revision_ids):
1706
1424
        """See bzrlib.Graph.get_parent_map()."""
1707
1425
        return self._make_parents_provider().get_parent_map(revision_ids)
1765
1483
        if parents_map is None:
1766
1484
            # Repository is not locked, so there's no cache.
1767
1485
            parents_map = {}
1768
 
        if _DEFAULT_SEARCH_DEPTH <= 0:
1769
 
            (start_set, stop_keys,
1770
 
             key_count) = graph.search_result_from_parent_map(
1771
 
                parents_map, self._unstacked_provider.missing_keys)
1772
 
        else:
1773
 
            (start_set, stop_keys,
1774
 
             key_count) = graph.limited_search_result_from_parent_map(
1775
 
                parents_map, self._unstacked_provider.missing_keys,
1776
 
                keys, depth=_DEFAULT_SEARCH_DEPTH)
 
1486
        # start_set is all the keys in the cache
 
1487
        start_set = set(parents_map)
 
1488
        # result set is all the references to keys in the cache
 
1489
        result_parents = set()
 
1490
        for parents in parents_map.itervalues():
 
1491
            result_parents.update(parents)
 
1492
        stop_keys = result_parents.difference(start_set)
 
1493
        # We don't need to send ghosts back to the server as a position to
 
1494
        # stop either.
 
1495
        stop_keys.difference_update(self._unstacked_provider.missing_keys)
 
1496
        key_count = len(parents_map)
 
1497
        if (NULL_REVISION in result_parents
 
1498
            and NULL_REVISION in self._unstacked_provider.missing_keys):
 
1499
            # If we pruned NULL_REVISION from the stop_keys because it's also
 
1500
            # in our cache of "missing" keys we need to increment our key count
 
1501
            # by 1, because the reconsitituted SearchResult on the server will
 
1502
            # still consider NULL_REVISION to be an included key.
 
1503
            key_count += 1
 
1504
        included_keys = start_set.intersection(result_parents)
 
1505
        start_set.difference_update(included_keys)
1777
1506
        recipe = ('manual', start_set, stop_keys, key_count)
1778
1507
        body = self._serialise_search_recipe(recipe)
1779
1508
        path = self.bzrdir._path_for_remote_call(self._client)
1883
1612
        from bzrlib import osutils
1884
1613
        import tarfile
1885
1614
        # TODO: Maybe a progress bar while streaming the tarball?
1886
 
        note(gettext("Copying repository content as tarball..."))
 
1615
        note("Copying repository content as tarball...")
1887
1616
        tar_file = self._get_tarball('bz2')
1888
1617
        if tar_file is None:
1889
1618
            return None
1894
1623
            tmpdir = osutils.mkdtemp()
1895
1624
            try:
1896
1625
                _extract_tar(tar, tmpdir)
1897
 
                tmp_bzrdir = _mod_bzrdir.BzrDir.open(tmpdir)
 
1626
                tmp_bzrdir = BzrDir.open(tmpdir)
1898
1627
                tmp_repo = tmp_bzrdir.open_repository()
1899
1628
                tmp_repo.copy_content_into(destination, revision_id)
1900
1629
            finally:
1985
1714
    def supports_rich_root(self):
1986
1715
        return self._format.rich_root_data
1987
1716
 
1988
 
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
1989
1717
    def iter_reverse_revision_history(self, revision_id):
1990
1718
        self._ensure_real()
1991
1719
        return self._real_repository.iter_reverse_revision_history(revision_id)
2012
1740
        return self._real_repository.item_keys_introduced_by(revision_ids,
2013
1741
            _files_pb=_files_pb)
2014
1742
 
 
1743
    def revision_graph_can_have_wrong_parents(self):
 
1744
        # The answer depends on the remote repo format.
 
1745
        self._ensure_real()
 
1746
        return self._real_repository.revision_graph_can_have_wrong_parents()
 
1747
 
2015
1748
    def _find_inconsistent_revision_parents(self, revisions_iterator=None):
2016
1749
        self._ensure_real()
2017
1750
        return self._real_repository._find_inconsistent_revision_parents(
2025
1758
        providers = [self._unstacked_provider]
2026
1759
        if other is not None:
2027
1760
            providers.insert(0, other)
2028
 
        return graph.StackedParentsProvider(_LazyListJoin(
2029
 
            providers, self._fallback_repositories))
 
1761
        providers.extend(r._make_parents_provider() for r in
 
1762
                         self._fallback_repositories)
 
1763
        return graph.StackedParentsProvider(providers)
2030
1764
 
2031
1765
    def _serialise_search_recipe(self, recipe):
2032
1766
        """Serialise a graph search recipe.
2056
1790
            raise errors.UnexpectedSmartServerResponse(response)
2057
1791
 
2058
1792
 
2059
 
class RemoteStreamSink(vf_repository.StreamSink):
 
1793
class RemoteStreamSink(repository.StreamSink):
2060
1794
 
2061
1795
    def _insert_real(self, stream, src_format, resume_tokens):
2062
1796
        self.target_repo._ensure_real()
2163
1897
        self._last_substream and self._last_stream so that the stream can be
2164
1898
        resumed by _resume_stream_with_vfs.
2165
1899
        """
2166
 
 
 
1900
                    
2167
1901
        stream_iter = iter(stream)
2168
1902
        for substream_kind, substream in stream_iter:
2169
1903
            if substream_kind == 'inventory-deltas':
2172
1906
                return
2173
1907
            else:
2174
1908
                yield substream_kind, substream
2175
 
 
2176
 
 
2177
 
class RemoteStreamSource(vf_repository.StreamSource):
 
1909
            
 
1910
 
 
1911
class RemoteStreamSource(repository.StreamSource):
2178
1912
    """Stream data from a remote server."""
2179
1913
 
2180
1914
    def get_stream(self, search):
2363
2097
        return a_bzrdir.open_branch(name=name, 
2364
2098
            ignore_fallbacks=ignore_fallbacks)
2365
2099
 
2366
 
    def _vfs_initialize(self, a_bzrdir, name, append_revisions_only):
 
2100
    def _vfs_initialize(self, a_bzrdir, name):
2367
2101
        # Initialisation when using a local bzrdir object, or a non-vfs init
2368
2102
        # method is not available on the server.
2369
2103
        # self._custom_format is always set - the start of initialize ensures
2371
2105
        if isinstance(a_bzrdir, RemoteBzrDir):
2372
2106
            a_bzrdir._ensure_real()
2373
2107
            result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
2374
 
                name, append_revisions_only=append_revisions_only)
 
2108
                name)
2375
2109
        else:
2376
2110
            # We assume the bzrdir is parameterised; it may not be.
2377
 
            result = self._custom_format.initialize(a_bzrdir, name,
2378
 
                append_revisions_only=append_revisions_only)
 
2111
            result = self._custom_format.initialize(a_bzrdir, name)
2379
2112
        if (isinstance(a_bzrdir, RemoteBzrDir) and
2380
2113
            not isinstance(result, RemoteBranch)):
2381
2114
            result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result,
2382
2115
                                  name=name)
2383
2116
        return result
2384
2117
 
2385
 
    def initialize(self, a_bzrdir, name=None, repository=None,
2386
 
                   append_revisions_only=None):
 
2118
    def initialize(self, a_bzrdir, name=None, repository=None):
2387
2119
        # 1) get the network name to use.
2388
2120
        if self._custom_format:
2389
2121
            network_name = self._custom_format.network_name()
2390
2122
        else:
2391
2123
            # Select the current bzrlib default and ask for that.
2392
 
            reference_bzrdir_format = _mod_bzrdir.format_registry.get('default')()
 
2124
            reference_bzrdir_format = bzrdir.format_registry.get('default')()
2393
2125
            reference_format = reference_bzrdir_format.get_branch_format()
2394
2126
            self._custom_format = reference_format
2395
2127
            network_name = reference_format.network_name()
2396
2128
        # Being asked to create on a non RemoteBzrDir:
2397
2129
        if not isinstance(a_bzrdir, RemoteBzrDir):
2398
 
            return self._vfs_initialize(a_bzrdir, name=name,
2399
 
                append_revisions_only=append_revisions_only)
 
2130
            return self._vfs_initialize(a_bzrdir, name=name)
2400
2131
        medium = a_bzrdir._client._medium
2401
2132
        if medium._is_remote_before((1, 13)):
2402
 
            return self._vfs_initialize(a_bzrdir, name=name,
2403
 
                append_revisions_only=append_revisions_only)
 
2133
            return self._vfs_initialize(a_bzrdir, name=name)
2404
2134
        # Creating on a remote bzr dir.
2405
2135
        # 2) try direct creation via RPC
2406
2136
        path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
2413
2143
        except errors.UnknownSmartMethod:
2414
2144
            # Fallback - use vfs methods
2415
2145
            medium._remember_remote_is_before((1, 13))
2416
 
            return self._vfs_initialize(a_bzrdir, name=name,
2417
 
                    append_revisions_only=append_revisions_only)
 
2146
            return self._vfs_initialize(a_bzrdir, name=name)
2418
2147
        if response[0] != 'ok':
2419
2148
            raise errors.UnexpectedSmartServerResponse(response)
2420
2149
        # Turn the response into a RemoteRepository object.
2422
2151
        repo_format = response_tuple_to_repo_format(response[3:])
2423
2152
        repo_path = response[2]
2424
2153
        if repository is not None:
2425
 
            remote_repo_url = urlutils.join(a_bzrdir.user_url, repo_path)
 
2154
            remote_repo_url = urlutils.join(medium.base, repo_path)
2426
2155
            url_diff = urlutils.relative_url(repository.user_url,
2427
2156
                    remote_repo_url)
2428
2157
            if url_diff != '.':
2429
2158
                raise AssertionError(
2430
2159
                    'repository.user_url %r does not match URL from server '
2431
2160
                    'response (%r + %r)'
2432
 
                    % (repository.user_url, a_bzrdir.user_url, repo_path))
 
2161
                    % (repository.user_url, medium.base, repo_path))
2433
2162
            remote_repo = repository
2434
2163
        else:
2435
2164
            if repo_path == '':
2441
2170
            remote_repo = RemoteRepository(repo_bzrdir, repo_format)
2442
2171
        remote_branch = RemoteBranch(a_bzrdir, remote_repo,
2443
2172
            format=format, setup_stacking=False, name=name)
2444
 
        if append_revisions_only:
2445
 
            remote_branch.set_append_revisions_only(append_revisions_only)
2446
2173
        # XXX: We know this is a new branch, so it must have revno 0, revid
2447
2174
        # NULL_REVISION. Creating the branch locked would make this be unable
2448
2175
        # to be wrong; here its simply very unlikely to be wrong. RBC 20090225
2467
2194
        self._ensure_real()
2468
2195
        return self._custom_format.supports_set_append_revisions_only()
2469
2196
 
2470
 
    def _use_default_local_heads_to_fetch(self):
2471
 
        # If the branch format is a metadir format *and* its heads_to_fetch
2472
 
        # implementation is not overridden vs the base class, we can use the
2473
 
        # base class logic rather than use the heads_to_fetch RPC.  This is
2474
 
        # usually cheaper in terms of net round trips, as the last-revision and
2475
 
        # tags info fetched is cached and would be fetched anyway.
2476
 
        self._ensure_real()
2477
 
        if isinstance(self._custom_format, branch.BranchFormatMetadir):
2478
 
            branch_class = self._custom_format._branch_class()
2479
 
            heads_to_fetch_impl = branch_class.heads_to_fetch.im_func
2480
 
            if heads_to_fetch_impl is branch.Branch.heads_to_fetch.im_func:
2481
 
                return True
2482
 
        return False
2483
2197
 
2484
2198
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2485
2199
    """Branch stored on a server accessed by HPSS RPC.
2643
2357
                self.bzrdir, self._client)
2644
2358
        return self._control_files
2645
2359
 
2646
 
    def _get_checkout_format(self, lightweight=False):
 
2360
    def _get_checkout_format(self):
2647
2361
        self._ensure_real()
2648
 
        if lightweight:
2649
 
            format = RemoteBzrDirFormat()
2650
 
            self.bzrdir._format._supply_sub_formats_to(format)
2651
 
            format.workingtree_format = self._real_branch._get_checkout_format(
2652
 
                lightweight=lightweight).workingtree_format
2653
 
            return format
2654
 
        else:
2655
 
            return self._real_branch._get_checkout_format(lightweight=False)
 
2362
        return self._real_branch._get_checkout_format()
2656
2363
 
2657
2364
    def get_physical_lock_status(self):
2658
2365
        """See Branch.get_physical_lock_status()."""
2691
2398
            self._is_stacked = False
2692
2399
        else:
2693
2400
            self._is_stacked = True
2694
 
 
 
2401
        
2695
2402
    def _vfs_get_tags_bytes(self):
2696
2403
        self._ensure_real()
2697
2404
        return self._real_branch._get_tags_bytes()
2879
2586
            missing_parent = parent_map[missing_parent]
2880
2587
        raise errors.RevisionNotPresent(missing_parent, self.repository)
2881
2588
 
2882
 
    def _read_last_revision_info(self):
 
2589
    def _last_revision_info(self):
2883
2590
        response = self._call('Branch.last_revision_info', self._remote_path())
2884
2591
        if response[0] != 'ok':
2885
2592
            raise SmartProtocolError('unexpected response code %s' % (response,))
2948
2655
            raise errors.UnexpectedSmartServerResponse(response)
2949
2656
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
2950
2657
 
2951
 
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
2952
2658
    @needs_write_lock
2953
2659
    def set_revision_history(self, rev_history):
2954
 
        """See Branch.set_revision_history."""
2955
 
        self._set_revision_history(rev_history)
2956
 
 
2957
 
    @needs_write_lock
2958
 
    def _set_revision_history(self, rev_history):
2959
2660
        # Send just the tip revision of the history; the server will generate
2960
2661
        # the full history from that.  If the revision doesn't exist in this
2961
2662
        # branch, NoSuchRevision will be raised.
3019
2720
            _override_hook_target=self, **kwargs)
3020
2721
 
3021
2722
    @needs_read_lock
3022
 
    def push(self, target, overwrite=False, stop_revision=None, lossy=False):
 
2723
    def push(self, target, overwrite=False, stop_revision=None):
3023
2724
        self._ensure_real()
3024
2725
        return self._real_branch.push(
3025
 
            target, overwrite=overwrite, stop_revision=stop_revision, lossy=lossy,
 
2726
            target, overwrite=overwrite, stop_revision=stop_revision,
3026
2727
            _override_hook_source_branch=self)
3027
2728
 
3028
2729
    def is_locked(self):
3038
2739
        # XXX: These should be returned by the set_last_revision_info verb
3039
2740
        old_revno, old_revid = self.last_revision_info()
3040
2741
        self._run_pre_change_branch_tip_hooks(revno, revision_id)
3041
 
        if not revision_id or not isinstance(revision_id, basestring):
3042
 
            raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
 
2742
        revision_id = ensure_null(revision_id)
3043
2743
        try:
3044
2744
            response = self._call('Branch.set_last_revision_info',
3045
2745
                self._remote_path(), self._lock_token, self._repo_lock_token,
3074
2774
            except errors.UnknownSmartMethod:
3075
2775
                medium._remember_remote_is_before((1, 6))
3076
2776
        self._clear_cached_state_of_remote_branch_only()
3077
 
        self._set_revision_history(self._lefthand_history(revision_id,
 
2777
        self.set_revision_history(self._lefthand_history(revision_id,
3078
2778
            last_rev=last_rev,other_branch=other_branch))
3079
2779
 
3080
2780
    def set_push_location(self, location):
3081
2781
        self._ensure_real()
3082
2782
        return self._real_branch.set_push_location(location)
3083
2783
 
3084
 
    def heads_to_fetch(self):
3085
 
        if self._format._use_default_local_heads_to_fetch():
3086
 
            # We recognise this format, and its heads-to-fetch implementation
3087
 
            # is the default one (tip + tags).  In this case it's cheaper to
3088
 
            # just use the default implementation rather than a special RPC as
3089
 
            # the tip and tags data is cached.
3090
 
            return branch.Branch.heads_to_fetch(self)
3091
 
        medium = self._client._medium
3092
 
        if medium._is_remote_before((2, 4)):
3093
 
            return self._vfs_heads_to_fetch()
3094
 
        try:
3095
 
            return self._rpc_heads_to_fetch()
3096
 
        except errors.UnknownSmartMethod:
3097
 
            medium._remember_remote_is_before((2, 4))
3098
 
            return self._vfs_heads_to_fetch()
3099
 
 
3100
 
    def _rpc_heads_to_fetch(self):
3101
 
        response = self._call('Branch.heads_to_fetch', self._remote_path())
3102
 
        if len(response) != 2:
3103
 
            raise errors.UnexpectedSmartServerResponse(response)
3104
 
        must_fetch, if_present_fetch = response
3105
 
        return set(must_fetch), set(if_present_fetch)
3106
 
 
3107
 
    def _vfs_heads_to_fetch(self):
3108
 
        self._ensure_real()
3109
 
        return self._real_branch.heads_to_fetch()
3110
 
 
3111
2784
 
3112
2785
class RemoteConfig(object):
3113
2786
    """A Config that reads and writes from smart verbs.
3127
2800
        """
3128
2801
        try:
3129
2802
            configobj = self._get_configobj()
3130
 
            section_obj = None
3131
2803
            if section is None:
3132
2804
                section_obj = configobj
3133
2805
            else:
3134
2806
                try:
3135
2807
                    section_obj = configobj[section]
3136
2808
                except KeyError:
3137
 
                    pass
3138
 
            if section_obj is None:
3139
 
                value = default
3140
 
            else:
3141
 
                value = section_obj.get(name, default)
 
2809
                    return default
 
2810
            return section_obj.get(name, default)
3142
2811
        except errors.UnknownSmartMethod:
3143
 
            value = self._vfs_get_option(name, section, default)
3144
 
        for hook in config.OldConfigHooks['get']:
3145
 
            hook(self, name, value)
3146
 
        return value
 
2812
            return self._vfs_get_option(name, section, default)
3147
2813
 
3148
2814
    def _response_to_configobj(self, response):
3149
2815
        if len(response[0]) and response[0][0] != 'ok':
3150
2816
            raise errors.UnexpectedSmartServerResponse(response)
3151
2817
        lines = response[1].read_body_bytes().splitlines()
3152
 
        conf = config.ConfigObj(lines, encoding='utf-8')
3153
 
        for hook in config.OldConfigHooks['load']:
3154
 
            hook(self)
3155
 
        return conf
 
2818
        return config.ConfigObj(lines, encoding='utf-8')
3156
2819
 
3157
2820
 
3158
2821
class RemoteBranchConfig(RemoteConfig):
3310
2973
                    'Missing key %r in context %r', key_err.args[0], context)
3311
2974
                raise err
3312
2975
 
3313
 
    if err.error_verb == 'NoSuchRevision':
 
2976
    if err.error_verb == 'IncompatibleRepositories':
 
2977
        raise errors.IncompatibleRepositories(err.error_args[0],
 
2978
            err.error_args[1], err.error_args[2])
 
2979
    elif err.error_verb == 'NoSuchRevision':
3314
2980
        raise NoSuchRevision(find('branch'), err.error_args[0])
3315
2981
    elif err.error_verb == 'nosuchrevision':
3316
2982
        raise NoSuchRevision(find('repository'), err.error_args[0])
3323
2989
            detail=extra)
3324
2990
    elif err.error_verb == 'norepository':
3325
2991
        raise errors.NoRepositoryPresent(find('bzrdir'))
 
2992
    elif err.error_verb == 'LockContention':
 
2993
        raise errors.LockContention('(remote lock)')
3326
2994
    elif err.error_verb == 'UnlockableTransport':
3327
2995
        raise errors.UnlockableTransport(find('bzrdir').root_transport)
 
2996
    elif err.error_verb == 'LockFailed':
 
2997
        raise errors.LockFailed(err.error_args[0], err.error_args[1])
3328
2998
    elif err.error_verb == 'TokenMismatch':
3329
2999
        raise errors.TokenMismatch(find('token'), '(remote token)')
3330
3000
    elif err.error_verb == 'Diverged':
3331
3001
        raise errors.DivergedBranches(find('branch'), find('other_branch'))
 
3002
    elif err.error_verb == 'TipChangeRejected':
 
3003
        raise errors.TipChangeRejected(err.error_args[0].decode('utf8'))
 
3004
    elif err.error_verb == 'UnstackableBranchFormat':
 
3005
        raise errors.UnstackableBranchFormat(*err.error_args)
 
3006
    elif err.error_verb == 'UnstackableRepositoryFormat':
 
3007
        raise errors.UnstackableRepositoryFormat(*err.error_args)
3332
3008
    elif err.error_verb == 'NotStacked':
3333
3009
        raise errors.NotStacked(branch=find('branch'))
3334
3010
    elif err.error_verb == 'PermissionDenied':
3344
3020
    elif err.error_verb == 'NoSuchFile':
3345
3021
        path = get_path()
3346
3022
        raise errors.NoSuchFile(path)
3347
 
    _translate_error_without_context(err)
3348
 
 
3349
 
 
3350
 
def _translate_error_without_context(err):
3351
 
    """Translate any ErrorFromSmartServer values that don't require context"""
3352
 
    if err.error_verb == 'IncompatibleRepositories':
3353
 
        raise errors.IncompatibleRepositories(err.error_args[0],
3354
 
            err.error_args[1], err.error_args[2])
3355
 
    elif err.error_verb == 'LockContention':
3356
 
        raise errors.LockContention('(remote lock)')
3357
 
    elif err.error_verb == 'LockFailed':
3358
 
        raise errors.LockFailed(err.error_args[0], err.error_args[1])
3359
 
    elif err.error_verb == 'TipChangeRejected':
3360
 
        raise errors.TipChangeRejected(err.error_args[0].decode('utf8'))
3361
 
    elif err.error_verb == 'UnstackableBranchFormat':
3362
 
        raise errors.UnstackableBranchFormat(*err.error_args)
3363
 
    elif err.error_verb == 'UnstackableRepositoryFormat':
3364
 
        raise errors.UnstackableRepositoryFormat(*err.error_args)
3365
3023
    elif err.error_verb == 'FileExists':
3366
3024
        raise errors.FileExists(err.error_args[0])
3367
3025
    elif err.error_verb == 'DirectoryNotEmpty':
3386
3044
            raise UnicodeEncodeError(encoding, val, start, end, reason)
3387
3045
    elif err.error_verb == 'ReadOnlyError':
3388
3046
        raise errors.TransportNotPossible('readonly transport')
3389
 
    elif err.error_verb == 'MemoryError':
3390
 
        raise errors.BzrError("remote server out of memory\n"
3391
 
            "Retry non-remotely, or contact the server admin for details.")
3392
3047
    raise errors.UnknownErrorFromSmartServer(err)