~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-06 20:45:48 UTC
  • mfrom: (4728.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20091006204548-bjnc3z4k256ppimz
MutableTree.has_changes() does not require a tree parameter anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008, 2009 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
# TODO: At some point, handle upgrades by just passing the whole request
18
 
# across to run on the server.
19
 
 
20
17
import bz2
21
18
 
22
19
from bzrlib import (
 
20
    bencode,
23
21
    branch,
24
22
    bzrdir,
 
23
    config,
25
24
    debug,
26
25
    errors,
27
26
    graph,
 
27
    lock,
28
28
    lockdir,
29
 
    pack,
30
29
    repository,
31
30
    revision,
 
31
    revision as _mod_revision,
32
32
    symbol_versioning,
33
 
    urlutils,
34
33
)
35
34
from bzrlib.branch import BranchReferenceFormat
36
35
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
43
42
from bzrlib.smart import client, vfs, repository as smart_repo
44
43
from bzrlib.revision import ensure_null, NULL_REVISION
45
44
from bzrlib.trace import mutter, note, warning
46
 
from bzrlib.util import bencode
47
45
 
48
46
 
49
47
class _RpcHelper(object):
61
59
        except errors.ErrorFromSmartServer, err:
62
60
            self._translate_error(err, **err_context)
63
61
 
 
62
    def _call_with_body_bytes(self, method, args, body_bytes, **err_context):
 
63
        try:
 
64
            return self._client.call_with_body_bytes(method, args, body_bytes)
 
65
        except errors.ErrorFromSmartServer, err:
 
66
            self._translate_error(err, **err_context)
 
67
 
64
68
    def _call_with_body_bytes_expecting_body(self, method, args, body_bytes,
65
69
                                             **err_context):
66
70
        try:
85
89
class RemoteBzrDir(BzrDir, _RpcHelper):
86
90
    """Control directory on a remote server, accessed via bzr:// or similar."""
87
91
 
88
 
    def __init__(self, transport, format, _client=None):
 
92
    def __init__(self, transport, format, _client=None, _force_probe=False):
89
93
        """Construct a RemoteBzrDir.
90
94
 
91
95
        :param _client: Private parameter for testing. Disables probing and the
95
99
        # this object holds a delegated bzrdir that uses file-level operations
96
100
        # to talk to the other side
97
101
        self._real_bzrdir = None
 
102
        self._has_working_tree = None
98
103
        # 1-shot cache for the call pattern 'create_branch; open_branch' - see
99
104
        # create_branch for details.
100
105
        self._next_open_branch_result = None
104
109
            self._client = client._SmartClient(medium)
105
110
        else:
106
111
            self._client = _client
107
 
            return
108
 
 
 
112
            if not _force_probe:
 
113
                return
 
114
 
 
115
        self._probe_bzrdir()
 
116
 
 
117
    def _probe_bzrdir(self):
 
118
        medium = self._client._medium
109
119
        path = self._path_for_remote_call(self._client)
 
120
        if medium._is_remote_before((2, 1)):
 
121
            self._rpc_open(path)
 
122
            return
 
123
        try:
 
124
            self._rpc_open_2_1(path)
 
125
            return
 
126
        except errors.UnknownSmartMethod:
 
127
            medium._remember_remote_is_before((2, 1))
 
128
            self._rpc_open(path)
 
129
 
 
130
    def _rpc_open_2_1(self, path):
 
131
        response = self._call('BzrDir.open_2.1', path)
 
132
        if response == ('no',):
 
133
            raise errors.NotBranchError(path=self.root_transport.base)
 
134
        elif response[0] == 'yes':
 
135
            if response[1] == 'yes':
 
136
                self._has_working_tree = True
 
137
            elif response[1] == 'no':
 
138
                self._has_working_tree = False
 
139
            else:
 
140
                raise errors.UnexpectedSmartServerResponse(response)
 
141
        else:
 
142
            raise errors.UnexpectedSmartServerResponse(response)
 
143
 
 
144
    def _rpc_open(self, path):
110
145
        response = self._call('BzrDir.open', path)
111
146
        if response not in [('yes',), ('no',)]:
112
147
            raise errors.UnexpectedSmartServerResponse(response)
113
148
        if response == ('no',):
114
 
            raise errors.NotBranchError(path=transport.base)
 
149
            raise errors.NotBranchError(path=self.root_transport.base)
115
150
 
116
151
    def _ensure_real(self):
117
152
        """Ensure that there is a _real_bzrdir set.
351
386
        else:
352
387
            raise errors.NoRepositoryPresent(self)
353
388
 
 
389
    def has_workingtree(self):
 
390
        if self._has_working_tree is None:
 
391
            self._ensure_real()
 
392
            self._has_working_tree = self._real_bzrdir.has_workingtree()
 
393
        return self._has_working_tree
 
394
 
354
395
    def open_workingtree(self, recommend_upgrade=True):
355
 
        self._ensure_real()
356
 
        if self._real_bzrdir.has_workingtree():
 
396
        if self.has_workingtree():
357
397
            raise errors.NotLocalUrl(self.root_transport)
358
398
        else:
359
399
            raise errors.NoWorkingTree(self.root_transport.base)
391
431
        return self._real_bzrdir.clone(url, revision_id=revision_id,
392
432
            force_new_repo=force_new_repo, preserve_stacking=preserve_stacking)
393
433
 
394
 
    def get_config(self):
395
 
        self._ensure_real()
396
 
        return self._real_bzrdir.get_config()
 
434
    def _get_config(self):
 
435
        return RemoteBzrDirConfig(self)
397
436
 
398
437
 
399
438
class RemoteRepositoryFormat(repository.RepositoryFormat):
423
462
        self._custom_format = None
424
463
        self._network_name = None
425
464
        self._creating_bzrdir = None
 
465
        self._supports_chks = None
426
466
        self._supports_external_lookups = None
427
467
        self._supports_tree_reference = None
428
468
        self._rich_root_data = None
429
469
 
 
470
    def __repr__(self):
 
471
        return "%s(_network_name=%r)" % (self.__class__.__name__,
 
472
            self._network_name)
 
473
 
430
474
    @property
431
475
    def fast_deltas(self):
432
476
        self._ensure_real()
440
484
        return self._rich_root_data
441
485
 
442
486
    @property
 
487
    def supports_chks(self):
 
488
        if self._supports_chks is None:
 
489
            self._ensure_real()
 
490
            self._supports_chks = self._custom_format.supports_chks
 
491
        return self._supports_chks
 
492
 
 
493
    @property
443
494
    def supports_external_lookups(self):
444
495
        if self._supports_external_lookups is None:
445
496
            self._ensure_real()
491
542
        # 1) get the network name to use.
492
543
        if self._custom_format:
493
544
            network_name = self._custom_format.network_name()
 
545
        elif self._network_name:
 
546
            network_name = self._network_name
494
547
        else:
495
548
            # Select the current bzrlib default and ask for that.
496
549
            reference_bzrdir_format = bzrdir.format_registry.get('default')()
549
602
    def __eq__(self, other):
550
603
        return self.__class__ is other.__class__
551
604
 
552
 
    def check_conversion_target(self, target_format):
553
 
        if self.rich_root_data and not target_format.rich_root_data:
554
 
            raise errors.BadConversionTarget(
555
 
                'Does not support rich root data.', target_format)
556
 
        if (self.supports_tree_reference and
557
 
            not getattr(target_format, 'supports_tree_reference', False)):
558
 
            raise errors.BadConversionTarget(
559
 
                'Does not support nested trees', target_format)
560
 
 
561
605
    def network_name(self):
562
606
        if self._network_name:
563
607
            return self._network_name
565
609
        return self._creating_repo._real_repository._format.network_name()
566
610
 
567
611
    @property
 
612
    def pack_compresses(self):
 
613
        self._ensure_real()
 
614
        return self._custom_format.pack_compresses
 
615
 
 
616
    @property
568
617
    def _serializer(self):
569
618
        self._ensure_real()
570
619
        return self._custom_format._serializer
602
651
        self._lock_token = None
603
652
        self._lock_count = 0
604
653
        self._leave_lock = False
 
654
        # Cache of revision parents; misses are cached during read locks, and
 
655
        # write locks when no _real_repository has been set.
605
656
        self._unstacked_provider = graph.CachingParentsProvider(
606
657
            get_parent_map=self._get_parent_map_rpc)
607
658
        self._unstacked_provider.disable_cache()
625
676
    def abort_write_group(self, suppress_errors=False):
626
677
        """Complete a write group on the decorated repository.
627
678
 
628
 
        Smart methods peform operations in a single step so this api
 
679
        Smart methods perform operations in a single step so this API
629
680
        is not really applicable except as a compatibility thunk
630
681
        for older plugins that don't use e.g. the CommitBuilder
631
682
        facility.
649
700
    def commit_write_group(self):
650
701
        """Complete a write group on the decorated repository.
651
702
 
652
 
        Smart methods peform operations in a single step so this api
 
703
        Smart methods perform operations in a single step so this API
653
704
        is not really applicable except as a compatibility thunk
654
705
        for older plugins that don't use e.g. the CommitBuilder
655
706
        facility.
665
716
        self._ensure_real()
666
717
        return self._real_repository.suspend_write_group()
667
718
 
 
719
    def get_missing_parent_inventories(self, check_for_missing_texts=True):
 
720
        self._ensure_real()
 
721
        return self._real_repository.get_missing_parent_inventories(
 
722
            check_for_missing_texts=check_for_missing_texts)
 
723
 
 
724
    def _get_rev_id_for_revno_vfs(self, revno, known_pair):
 
725
        self._ensure_real()
 
726
        return self._real_repository.get_rev_id_for_revno(
 
727
            revno, known_pair)
 
728
 
 
729
    def get_rev_id_for_revno(self, revno, known_pair):
 
730
        """See Repository.get_rev_id_for_revno."""
 
731
        path = self.bzrdir._path_for_remote_call(self._client)
 
732
        try:
 
733
            if self._client._medium._is_remote_before((1, 17)):
 
734
                return self._get_rev_id_for_revno_vfs(revno, known_pair)
 
735
            response = self._call(
 
736
                'Repository.get_rev_id_for_revno', path, revno, known_pair)
 
737
        except errors.UnknownSmartMethod:
 
738
            self._client._medium._remember_remote_is_before((1, 17))
 
739
            return self._get_rev_id_for_revno_vfs(revno, known_pair)
 
740
        if response[0] == 'ok':
 
741
            return True, response[1]
 
742
        elif response[0] == 'history-incomplete':
 
743
            known_pair = response[1:3]
 
744
            for fallback in self._fallback_repositories:
 
745
                found, result = fallback.get_rev_id_for_revno(revno, known_pair)
 
746
                if found:
 
747
                    return True, result
 
748
                else:
 
749
                    known_pair = result
 
750
            # Not found in any fallbacks
 
751
            return False, known_pair
 
752
        else:
 
753
            raise errors.UnexpectedSmartServerResponse(response)
 
754
 
668
755
    def _ensure_real(self):
669
756
        """Ensure that there is a _real_repository set.
670
757
 
679
766
        invocation. If in doubt chat to the bzr network team.
680
767
        """
681
768
        if self._real_repository is None:
 
769
            if 'hpssvfs' in debug.debug_flags:
 
770
                import traceback
 
771
                warning('VFS Repository access triggered\n%s',
 
772
                    ''.join(traceback.format_stack()))
 
773
            self._unstacked_provider.missing_keys.clear()
682
774
            self.bzrdir._ensure_real()
683
775
            self._set_real_repository(
684
776
                self.bzrdir._real_bzrdir.open_repository())
744
836
        """Return a source for streaming from this repository."""
745
837
        return RemoteStreamSource(self, to_format)
746
838
 
 
839
    @needs_read_lock
747
840
    def has_revision(self, revision_id):
748
 
        """See Repository.has_revision()."""
749
 
        if revision_id == NULL_REVISION:
750
 
            # The null revision is always present.
751
 
            return True
752
 
        path = self.bzrdir._path_for_remote_call(self._client)
753
 
        response = self._call('Repository.has_revision', path, revision_id)
754
 
        if response[0] not in ('yes', 'no'):
755
 
            raise errors.UnexpectedSmartServerResponse(response)
756
 
        if response[0] == 'yes':
757
 
            return True
758
 
        for fallback_repo in self._fallback_repositories:
759
 
            if fallback_repo.has_revision(revision_id):
760
 
                return True
761
 
        return False
 
841
        """True if this repository has a copy of the revision."""
 
842
        # Copy of bzrlib.repository.Repository.has_revision
 
843
        return revision_id in self.has_revisions((revision_id,))
762
844
 
 
845
    @needs_read_lock
763
846
    def has_revisions(self, revision_ids):
764
 
        """See Repository.has_revisions()."""
765
 
        # FIXME: This does many roundtrips, particularly when there are
766
 
        # fallback repositories.  -- mbp 20080905
767
 
        result = set()
768
 
        for revision_id in revision_ids:
769
 
            if self.has_revision(revision_id):
770
 
                result.add(revision_id)
 
847
        """Probe to find out the presence of multiple revisions.
 
848
 
 
849
        :param revision_ids: An iterable of revision_ids.
 
850
        :return: A set of the revision_ids that were present.
 
851
        """
 
852
        # Copy of bzrlib.repository.Repository.has_revisions
 
853
        parent_map = self.get_parent_map(revision_ids)
 
854
        result = set(parent_map)
 
855
        if _mod_revision.NULL_REVISION in revision_ids:
 
856
            result.add(_mod_revision.NULL_REVISION)
771
857
        return result
772
858
 
 
859
    def _has_same_fallbacks(self, other_repo):
 
860
        """Returns true if the repositories have the same fallbacks."""
 
861
        # XXX: copied from Repository; it should be unified into a base class
 
862
        # <https://bugs.edge.launchpad.net/bzr/+bug/401622>
 
863
        my_fb = self._fallback_repositories
 
864
        other_fb = other_repo._fallback_repositories
 
865
        if len(my_fb) != len(other_fb):
 
866
            return False
 
867
        for f, g in zip(my_fb, other_fb):
 
868
            if not f.has_same_location(g):
 
869
                return False
 
870
        return True
 
871
 
773
872
    def has_same_location(self, other):
 
873
        # TODO: Move to RepositoryBase and unify with the regular Repository
 
874
        # one; unfortunately the tests rely on slightly different behaviour at
 
875
        # present -- mbp 20090710
774
876
        return (self.__class__ is other.__class__ and
775
877
                self.bzrdir.transport.base == other.bzrdir.transport.base)
776
878
 
852
954
            self._unstacked_provider.enable_cache(cache_misses=True)
853
955
            if self._real_repository is not None:
854
956
                self._real_repository.lock_read()
 
957
            for repo in self._fallback_repositories:
 
958
                repo.lock_read()
855
959
        else:
856
960
            self._lock_count += 1
857
961
 
889
993
                self._leave_lock = False
890
994
            self._lock_mode = 'w'
891
995
            self._lock_count = 1
892
 
            self._unstacked_provider.enable_cache(cache_misses=False)
 
996
            cache_misses = self._real_repository is None
 
997
            self._unstacked_provider.enable_cache(cache_misses=cache_misses)
 
998
            for repo in self._fallback_repositories:
 
999
                # Writes don't affect fallback repos
 
1000
                repo.lock_read()
893
1001
        elif self._lock_mode == 'r':
894
1002
            raise errors.ReadOnlyError(self)
895
1003
        else:
921
1029
        if isinstance(repository, RemoteRepository):
922
1030
            raise AssertionError()
923
1031
        self._real_repository = repository
924
 
        # If the _real_repository has _fallback_repositories, clear them out,
925
 
        # because we want it to have the same set as this repository.  This is
926
 
        # reasonable to do because the fallbacks we clear here are from a
927
 
        # "real" branch, and we're about to replace them with the equivalents
928
 
        # from a RemoteBranch.
929
 
        self._real_repository._fallback_repositories = []
 
1032
        # three code paths happen here:
 
1033
        # 1) old servers, RemoteBranch.open() calls _ensure_real before setting
 
1034
        # up stacking. In this case self._fallback_repositories is [], and the
 
1035
        # real repo is already setup. Preserve the real repo and
 
1036
        # RemoteRepository.add_fallback_repository will avoid adding
 
1037
        # duplicates.
 
1038
        # 2) new servers, RemoteBranch.open() sets up stacking, and when
 
1039
        # ensure_real is triggered from a branch, the real repository to
 
1040
        # set already has a matching list with separate instances, but
 
1041
        # as they are also RemoteRepositories we don't worry about making the
 
1042
        # lists be identical.
 
1043
        # 3) new servers, RemoteRepository.ensure_real is triggered before
 
1044
        # RemoteBranch.ensure real, in this case we get a repo with no fallbacks
 
1045
        # and need to populate it.
 
1046
        if (self._fallback_repositories and
 
1047
            len(self._real_repository._fallback_repositories) !=
 
1048
            len(self._fallback_repositories)):
 
1049
            if len(self._real_repository._fallback_repositories):
 
1050
                raise AssertionError(
 
1051
                    "cannot cleanly remove existing _fallback_repositories")
930
1052
        for fb in self._fallback_repositories:
931
1053
            self._real_repository.add_fallback_repository(fb)
932
1054
        if self._lock_mode == 'w':
939
1061
    def start_write_group(self):
940
1062
        """Start a write group on the decorated repository.
941
1063
 
942
 
        Smart methods peform operations in a single step so this api
 
1064
        Smart methods perform operations in a single step so this API
943
1065
        is not really applicable except as a compatibility thunk
944
1066
        for older plugins that don't use e.g. the CommitBuilder
945
1067
        facility.
962
1084
 
963
1085
    def unlock(self):
964
1086
        if not self._lock_count:
965
 
            raise errors.LockNotHeld(self)
 
1087
            return lock.cant_unlock_not_held(self)
966
1088
        self._lock_count -= 1
967
1089
        if self._lock_count > 0:
968
1090
            return
982
1104
            # problem releasing the vfs-based lock.
983
1105
            if old_mode == 'w':
984
1106
                # Only write-locked repositories need to make a remote method
985
 
                # call to perfom the unlock.
 
1107
                # call to perform the unlock.
986
1108
                old_token = self._lock_token
987
1109
                self._lock_token = None
988
1110
                if not self._leave_lock:
989
1111
                    self._unlock(old_token)
 
1112
        # Fallbacks are always 'lock_read()' so we don't pay attention to
 
1113
        # self._leave_lock
 
1114
        for repo in self._fallback_repositories:
 
1115
            repo.unlock()
990
1116
 
991
1117
    def break_lock(self):
992
1118
        # should hand off to the network
1056
1182
        # We need to accumulate additional repositories here, to pass them in
1057
1183
        # on various RPC's.
1058
1184
        #
 
1185
        if self.is_locked():
 
1186
            # We will call fallback.unlock() when we transition to the unlocked
 
1187
            # state, so always add a lock here. If a caller passes us a locked
 
1188
            # repository, they are responsible for unlocking it later.
 
1189
            repository.lock_read()
1059
1190
        self._fallback_repositories.append(repository)
1060
1191
        # If self._real_repository was parameterised already (e.g. because a
1061
1192
        # _real_branch had its get_stacked_on_url method called), then the
1062
1193
        # repository to be added may already be in the _real_repositories list.
1063
1194
        if self._real_repository is not None:
1064
 
            if repository not in self._real_repository._fallback_repositories:
 
1195
            fallback_locations = [repo.bzrdir.root_transport.base for repo in
 
1196
                self._real_repository._fallback_repositories]
 
1197
            if repository.bzrdir.root_transport.base not in fallback_locations:
1065
1198
                self._real_repository.add_fallback_repository(repository)
1066
 
        else:
1067
 
            # They are also seen by the fallback repository.  If it doesn't
1068
 
            # exist yet they'll be added then.  This implicitly copies them.
1069
 
            self._ensure_real()
1070
1199
 
1071
1200
    def add_inventory(self, revid, inv, parents):
1072
1201
        self._ensure_real()
1088
1217
        self._ensure_real()
1089
1218
        return self._real_repository.get_inventory(revision_id)
1090
1219
 
1091
 
    def iter_inventories(self, revision_ids):
 
1220
    def iter_inventories(self, revision_ids, ordering=None):
1092
1221
        self._ensure_real()
1093
 
        return self._real_repository.iter_inventories(revision_ids)
 
1222
        return self._real_repository.iter_inventories(revision_ids, ordering)
1094
1223
 
1095
1224
    @needs_read_lock
1096
1225
    def get_revision(self, revision_id):
1160
1289
            raise errors.InternalBzrError(
1161
1290
                "May not fetch while in a write group.")
1162
1291
        # fast path same-url fetch operations
1163
 
        if self.has_same_location(source) and fetch_spec is None:
 
1292
        if (self.has_same_location(source)
 
1293
            and fetch_spec is None
 
1294
            and self._has_same_fallbacks(source)):
1164
1295
            # check that last_revision is in 'from' and then return a
1165
1296
            # no-operation.
1166
1297
            if (revision_id is not None and
1215
1346
            # in one go, and the user probably will have seen a warning about
1216
1347
            # the server being old anyhow.
1217
1348
            rg = self._get_revision_graph(None)
1218
 
            # There is an api discrepency between get_parent_map and
 
1349
            # There is an API discrepancy between get_parent_map and
1219
1350
            # get_revision_graph. Specifically, a "key:()" pair in
1220
1351
            # get_revision_graph just means a node has no parents. For
1221
1352
            # "get_parent_map" it means the node is a ghost. So fix up the
1271
1402
        # We don't need to send ghosts back to the server as a position to
1272
1403
        # stop either.
1273
1404
        stop_keys.difference_update(self._unstacked_provider.missing_keys)
 
1405
        key_count = len(parents_map)
 
1406
        if (NULL_REVISION in result_parents
 
1407
            and NULL_REVISION in self._unstacked_provider.missing_keys):
 
1408
            # If we pruned NULL_REVISION from the stop_keys because it's also
 
1409
            # in our cache of "missing" keys we need to increment our key count
 
1410
            # by 1, because the reconsitituted SearchResult on the server will
 
1411
            # still consider NULL_REVISION to be an included key.
 
1412
            key_count += 1
1274
1413
        included_keys = start_set.intersection(result_parents)
1275
1414
        start_set.difference_update(included_keys)
1276
 
        recipe = ('manual', start_set, stop_keys, len(parents_map))
 
1415
        recipe = ('manual', start_set, stop_keys, key_count)
1277
1416
        body = self._serialise_search_recipe(recipe)
1278
1417
        path = self.bzrdir._path_for_remote_call(self._client)
1279
1418
        for key in keys:
1370
1509
        return self._real_repository.get_revision_reconcile(revision_id)
1371
1510
 
1372
1511
    @needs_read_lock
1373
 
    def check(self, revision_ids=None):
 
1512
    def check(self, revision_ids=None, callback_refs=None, check_repo=True):
1374
1513
        self._ensure_real()
1375
 
        return self._real_repository.check(revision_ids=revision_ids)
 
1514
        return self._real_repository.check(revision_ids=revision_ids,
 
1515
            callback_refs=callback_refs, check_repo=check_repo)
1376
1516
 
1377
1517
    def copy_content_into(self, destination, revision_id=None):
1378
1518
        self._ensure_real()
1418
1558
        return self._real_repository.inventories
1419
1559
 
1420
1560
    @needs_write_lock
1421
 
    def pack(self):
 
1561
    def pack(self, hint=None):
1422
1562
        """Compress the data within the repository.
1423
1563
 
1424
1564
        This is not currently implemented within the smart server.
1425
1565
        """
1426
1566
        self._ensure_real()
1427
 
        return self._real_repository.pack()
 
1567
        return self._real_repository.pack(hint=hint)
1428
1568
 
1429
1569
    @property
1430
1570
    def revisions(self):
1518
1658
        self._ensure_real()
1519
1659
        return self._real_repository.revision_graph_can_have_wrong_parents()
1520
1660
 
1521
 
    def _find_inconsistent_revision_parents(self):
 
1661
    def _find_inconsistent_revision_parents(self, revisions_iterator=None):
1522
1662
        self._ensure_real()
1523
 
        return self._real_repository._find_inconsistent_revision_parents()
 
1663
        return self._real_repository._find_inconsistent_revision_parents(
 
1664
            revisions_iterator)
1524
1665
 
1525
1666
    def _check_for_inconsistent_revision_parents(self):
1526
1667
        self._ensure_real()
1532
1673
            providers.insert(0, other)
1533
1674
        providers.extend(r._make_parents_provider() for r in
1534
1675
                         self._fallback_repositories)
1535
 
        return graph._StackedParentsProvider(providers)
 
1676
        return graph.StackedParentsProvider(providers)
1536
1677
 
1537
1678
    def _serialise_search_recipe(self, recipe):
1538
1679
        """Serialise a graph search recipe.
1579
1720
 
1580
1721
    def insert_stream(self, stream, src_format, resume_tokens):
1581
1722
        target = self.target_repo
 
1723
        target._unstacked_provider.missing_keys.clear()
 
1724
        candidate_calls = [('Repository.insert_stream_1.19', (1, 19))]
1582
1725
        if target._lock_token:
1583
 
            verb = 'Repository.insert_stream_locked'
1584
 
            extra_args = (target._lock_token or '',)
1585
 
            required_version = (1, 14)
 
1726
            candidate_calls.append(('Repository.insert_stream_locked', (1, 14)))
 
1727
            lock_args = (target._lock_token or '',)
1586
1728
        else:
1587
 
            verb = 'Repository.insert_stream'
1588
 
            extra_args = ()
1589
 
            required_version = (1, 13)
 
1729
            candidate_calls.append(('Repository.insert_stream', (1, 13)))
 
1730
            lock_args = ()
1590
1731
        client = target._client
1591
1732
        medium = client._medium
1592
 
        if medium._is_remote_before(required_version):
1593
 
            # No possible way this can work.
1594
 
            return self._insert_real(stream, src_format, resume_tokens)
1595
1733
        path = target.bzrdir._path_for_remote_call(client)
1596
 
        if not resume_tokens:
1597
 
            # XXX: Ugly but important for correctness, *will* be fixed during
1598
 
            # 1.13 cycle. Pushing a stream that is interrupted results in a
1599
 
            # fallback to the _real_repositories sink *with a partial stream*.
1600
 
            # Thats bad because we insert less data than bzr expected. To avoid
1601
 
            # this we do a trial push to make sure the verb is accessible, and
1602
 
            # do not fallback when actually pushing the stream. A cleanup patch
1603
 
            # is going to look at rewinding/restarting the stream/partial
1604
 
            # buffering etc.
 
1734
        # Probe for the verb to use with an empty stream before sending the
 
1735
        # real stream to it.  We do this both to avoid the risk of sending a
 
1736
        # large request that is then rejected, and because we don't want to
 
1737
        # implement a way to buffer, rewind, or restart the stream.
 
1738
        found_verb = False
 
1739
        for verb, required_version in candidate_calls:
 
1740
            if medium._is_remote_before(required_version):
 
1741
                continue
 
1742
            if resume_tokens:
 
1743
                # We've already done the probing (and set _is_remote_before) on
 
1744
                # a previous insert.
 
1745
                found_verb = True
 
1746
                break
1605
1747
            byte_stream = smart_repo._stream_to_byte_stream([], src_format)
1606
1748
            try:
1607
1749
                response = client.call_with_body_stream(
1608
 
                    (verb, path, '') + extra_args, byte_stream)
 
1750
                    (verb, path, '') + lock_args, byte_stream)
1609
1751
            except errors.UnknownSmartMethod:
1610
1752
                medium._remember_remote_is_before(required_version)
1611
 
                return self._insert_real(stream, src_format, resume_tokens)
 
1753
            else:
 
1754
                found_verb = True
 
1755
                break
 
1756
        if not found_verb:
 
1757
            # Have to use VFS.
 
1758
            return self._insert_real(stream, src_format, resume_tokens)
 
1759
        self._last_inv_record = None
 
1760
        self._last_substream = None
 
1761
        if required_version < (1, 19):
 
1762
            # Remote side doesn't support inventory deltas.  Wrap the stream to
 
1763
            # make sure we don't send any.  If the stream contains inventory
 
1764
            # deltas we'll interrupt the smart insert_stream request and
 
1765
            # fallback to VFS.
 
1766
            stream = self._stop_stream_if_inventory_delta(stream)
1612
1767
        byte_stream = smart_repo._stream_to_byte_stream(
1613
1768
            stream, src_format)
1614
1769
        resume_tokens = ' '.join(resume_tokens)
1615
1770
        response = client.call_with_body_stream(
1616
 
            (verb, path, resume_tokens) + extra_args, byte_stream)
 
1771
            (verb, path, resume_tokens) + lock_args, byte_stream)
1617
1772
        if response[0][0] not in ('ok', 'missing-basis'):
1618
1773
            raise errors.UnexpectedSmartServerResponse(response)
 
1774
        if self._last_substream is not None:
 
1775
            # The stream included an inventory-delta record, but the remote
 
1776
            # side isn't new enough to support them.  So we need to send the
 
1777
            # rest of the stream via VFS.
 
1778
            self.target_repo.refresh_data()
 
1779
            return self._resume_stream_with_vfs(response, src_format)
1619
1780
        if response[0][0] == 'missing-basis':
1620
1781
            tokens, missing_keys = bencode.bdecode_as_tuple(response[0][1])
1621
1782
            resume_tokens = tokens
1622
 
            return resume_tokens, missing_keys
 
1783
            return resume_tokens, set(missing_keys)
1623
1784
        else:
1624
1785
            self.target_repo.refresh_data()
1625
1786
            return [], set()
1626
1787
 
 
1788
    def _resume_stream_with_vfs(self, response, src_format):
 
1789
        """Resume sending a stream via VFS, first resending the record and
 
1790
        substream that couldn't be sent via an insert_stream verb.
 
1791
        """
 
1792
        if response[0][0] == 'missing-basis':
 
1793
            tokens, missing_keys = bencode.bdecode_as_tuple(response[0][1])
 
1794
            # Ignore missing_keys, we haven't finished inserting yet
 
1795
        else:
 
1796
            tokens = []
 
1797
        def resume_substream():
 
1798
            # Yield the substream that was interrupted.
 
1799
            for record in self._last_substream:
 
1800
                yield record
 
1801
            self._last_substream = None
 
1802
        def resume_stream():
 
1803
            # Finish sending the interrupted substream
 
1804
            yield ('inventory-deltas', resume_substream())
 
1805
            # Then simply continue sending the rest of the stream.
 
1806
            for substream_kind, substream in self._last_stream:
 
1807
                yield substream_kind, substream
 
1808
        return self._insert_real(resume_stream(), src_format, tokens)
 
1809
 
 
1810
    def _stop_stream_if_inventory_delta(self, stream):
 
1811
        """Normally this just lets the original stream pass-through unchanged.
 
1812
 
 
1813
        However if any 'inventory-deltas' substream occurs it will stop
 
1814
        streaming, and store the interrupted substream and stream in
 
1815
        self._last_substream and self._last_stream so that the stream can be
 
1816
        resumed by _resume_stream_with_vfs.
 
1817
        """
 
1818
                    
 
1819
        stream_iter = iter(stream)
 
1820
        for substream_kind, substream in stream_iter:
 
1821
            if substream_kind == 'inventory-deltas':
 
1822
                self._last_substream = substream
 
1823
                self._last_stream = stream_iter
 
1824
                return
 
1825
            else:
 
1826
                yield substream_kind, substream
 
1827
            
1627
1828
 
1628
1829
class RemoteStreamSource(repository.StreamSource):
1629
1830
    """Stream data from a remote server."""
1632
1833
        if (self.from_repository._fallback_repositories and
1633
1834
            self.to_format._fetch_order == 'topological'):
1634
1835
            return self._real_stream(self.from_repository, search)
1635
 
        return self.missing_parents_chain(search, [self.from_repository] +
1636
 
            self.from_repository._fallback_repositories)
 
1836
        sources = []
 
1837
        seen = set()
 
1838
        repos = [self.from_repository]
 
1839
        while repos:
 
1840
            repo = repos.pop(0)
 
1841
            if repo in seen:
 
1842
                continue
 
1843
            seen.add(repo)
 
1844
            repos.extend(repo._fallback_repositories)
 
1845
            sources.append(repo)
 
1846
        return self.missing_parents_chain(search, sources)
 
1847
 
 
1848
    def get_stream_for_missing_keys(self, missing_keys):
 
1849
        self.from_repository._ensure_real()
 
1850
        real_repo = self.from_repository._real_repository
 
1851
        real_source = real_repo._get_source(self.to_format)
 
1852
        return real_source.get_stream_for_missing_keys(missing_keys)
1637
1853
 
1638
1854
    def _real_stream(self, repo, search):
1639
1855
        """Get a stream for search from repo.
1646
1862
        """
1647
1863
        source = repo._get_source(self.to_format)
1648
1864
        if isinstance(source, RemoteStreamSource):
1649
 
            return repository.StreamSource.get_stream(source, search)
 
1865
            repo._ensure_real()
 
1866
            source = repo._real_repository._get_source(self.to_format)
1650
1867
        return source.get_stream(search)
1651
1868
 
1652
1869
    def _get_stream(self, repo, search):
1669
1886
            return self._real_stream(repo, search)
1670
1887
        client = repo._client
1671
1888
        medium = client._medium
1672
 
        if medium._is_remote_before((1, 13)):
1673
 
            # streaming was added in 1.13
1674
 
            return self._real_stream(repo, search)
1675
1889
        path = repo.bzrdir._path_for_remote_call(client)
1676
 
        try:
1677
 
            search_bytes = repo._serialise_search_result(search)
1678
 
            response = repo._call_with_body_bytes_expecting_body(
1679
 
                'Repository.get_stream',
1680
 
                (path, self.to_format.network_name()), search_bytes)
1681
 
            response_tuple, response_handler = response
1682
 
        except errors.UnknownSmartMethod:
1683
 
            medium._remember_remote_is_before((1,13))
 
1890
        search_bytes = repo._serialise_search_result(search)
 
1891
        args = (path, self.to_format.network_name())
 
1892
        candidate_verbs = [
 
1893
            ('Repository.get_stream_1.19', (1, 19)),
 
1894
            ('Repository.get_stream', (1, 13))]
 
1895
        found_verb = False
 
1896
        for verb, version in candidate_verbs:
 
1897
            if medium._is_remote_before(version):
 
1898
                continue
 
1899
            try:
 
1900
                response = repo._call_with_body_bytes_expecting_body(
 
1901
                    verb, args, search_bytes)
 
1902
            except errors.UnknownSmartMethod:
 
1903
                medium._remember_remote_is_before(version)
 
1904
            else:
 
1905
                response_tuple, response_handler = response
 
1906
                found_verb = True
 
1907
                break
 
1908
        if not found_verb:
1684
1909
            return self._real_stream(repo, search)
1685
1910
        if response_tuple[0] != 'ok':
1686
1911
            raise errors.UnexpectedSmartServerResponse(response_tuple)
1698
1923
        :param search: The overall search to satisfy with streams.
1699
1924
        :param sources: A list of Repository objects to query.
1700
1925
        """
1701
 
        self.serialiser = self.to_format._serializer
 
1926
        self.from_serialiser = self.from_repository._format._serializer
1702
1927
        self.seen_revs = set()
1703
1928
        self.referenced_revs = set()
1704
1929
        # If there are heads in the search, or the key count is > 0, we are not
1721
1946
    def missing_parents_rev_handler(self, substream):
1722
1947
        for content in substream:
1723
1948
            revision_bytes = content.get_bytes_as('fulltext')
1724
 
            revision = self.serialiser.read_revision_from_string(revision_bytes)
 
1949
            revision = self.from_serialiser.read_revision_from_string(
 
1950
                revision_bytes)
1725
1951
            self.seen_revs.add(content.key[-1])
1726
1952
            self.referenced_revs.update(revision.parent_ids)
1727
1953
            yield content
1850
2076
        self._ensure_real()
1851
2077
        return self._custom_format.supports_stacking()
1852
2078
 
 
2079
    def supports_set_append_revisions_only(self):
 
2080
        self._ensure_real()
 
2081
        return self._custom_format.supports_set_append_revisions_only()
 
2082
 
1853
2083
 
1854
2084
class RemoteBranch(branch.Branch, _RpcHelper):
1855
2085
    """Branch stored on a server accessed by HPSS RPC.
1874
2104
        # We intentionally don't call the parent class's __init__, because it
1875
2105
        # will try to assign to self.tags, which is a property in this subclass.
1876
2106
        # And the parent's __init__ doesn't do much anyway.
1877
 
        self._revision_id_to_revno_cache = None
1878
 
        self._partial_revision_id_to_revno_cache = {}
1879
 
        self._revision_history_cache = None
1880
 
        self._last_revision_info_cache = None
1881
 
        self._merge_sorted_revisions_cache = None
1882
2107
        self.bzrdir = remote_bzrdir
1883
2108
        if _client is not None:
1884
2109
            self._client = _client
1897
2122
            self._real_branch.repository = self.repository
1898
2123
        else:
1899
2124
            self._real_branch = None
1900
 
        # Fill out expected attributes of branch for bzrlib api users.
 
2125
        # Fill out expected attributes of branch for bzrlib API users.
 
2126
        self._clear_cached_state()
1901
2127
        self.base = self.bzrdir.root_transport.base
1902
2128
        self._control_files = None
1903
2129
        self._lock_mode = None
1915
2141
                    self._real_branch._format.network_name()
1916
2142
        else:
1917
2143
            self._format = format
 
2144
        # when we do _ensure_real we may need to pass ignore_fallbacks to the
 
2145
        # branch.open_branch method.
 
2146
        self._real_ignore_fallbacks = not setup_stacking
1918
2147
        if not self._format._network_name:
1919
2148
            # Did not get from open_branchV2 - old server.
1920
2149
            self._ensure_real()
1925
2154
        hooks = branch.Branch.hooks['open']
1926
2155
        for hook in hooks:
1927
2156
            hook(self)
 
2157
        self._is_stacked = False
1928
2158
        if setup_stacking:
1929
2159
            self._setup_stacking()
1930
2160
 
1936
2166
        except (errors.NotStacked, errors.UnstackableBranchFormat,
1937
2167
            errors.UnstackableRepositoryFormat), e:
1938
2168
            return
1939
 
        # it's relative to this branch...
1940
 
        fallback_url = urlutils.join(self.base, fallback_url)
1941
 
        transports = [self.bzrdir.root_transport]
1942
 
        stacked_on = branch.Branch.open(fallback_url,
1943
 
                                        possible_transports=transports)
1944
 
        self.repository.add_fallback_repository(stacked_on.repository)
 
2169
        self._is_stacked = True
 
2170
        self._activate_fallback_location(fallback_url)
 
2171
 
 
2172
    def _get_config(self):
 
2173
        return RemoteBranchConfig(self)
1945
2174
 
1946
2175
    def _get_real_transport(self):
1947
2176
        # if we try vfs access, return the real branch's vfs transport
1965
2194
                raise AssertionError('smart server vfs must be enabled '
1966
2195
                    'to use vfs implementation')
1967
2196
            self.bzrdir._ensure_real()
1968
 
            self._real_branch = self.bzrdir._real_bzrdir.open_branch()
 
2197
            self._real_branch = self.bzrdir._real_bzrdir.open_branch(
 
2198
                ignore_fallbacks=self._real_ignore_fallbacks)
1969
2199
            if self.repository._real_repository is None:
1970
2200
                # Give the remote repository the matching real repo.
1971
2201
                real_repo = self._real_branch.repository
2045
2275
            raise errors.UnexpectedSmartServerResponse(response)
2046
2276
        return response[1]
2047
2277
 
 
2278
    def set_stacked_on_url(self, url):
 
2279
        branch.Branch.set_stacked_on_url(self, url)
 
2280
        if not url:
 
2281
            self._is_stacked = False
 
2282
        else:
 
2283
            self._is_stacked = True
 
2284
        
2048
2285
    def _vfs_get_tags_bytes(self):
2049
2286
        self._ensure_real()
2050
2287
        return self._real_branch._get_tags_bytes()
2060
2297
            return self._vfs_get_tags_bytes()
2061
2298
        return response[0]
2062
2299
 
 
2300
    def _vfs_set_tags_bytes(self, bytes):
 
2301
        self._ensure_real()
 
2302
        return self._real_branch._set_tags_bytes(bytes)
 
2303
 
 
2304
    def _set_tags_bytes(self, bytes):
 
2305
        medium = self._client._medium
 
2306
        if medium._is_remote_before((1, 18)):
 
2307
            self._vfs_set_tags_bytes(bytes)
 
2308
            return
 
2309
        try:
 
2310
            args = (
 
2311
                self._remote_path(), self._lock_token, self._repo_lock_token)
 
2312
            response = self._call_with_body_bytes(
 
2313
                'Branch.set_tags_bytes', args, bytes)
 
2314
        except errors.UnknownSmartMethod:
 
2315
            medium._remember_remote_is_before((1, 18))
 
2316
            self._vfs_set_tags_bytes(bytes)
 
2317
 
2063
2318
    def lock_read(self):
2064
2319
        self.repository.lock_read()
2065
2320
        if not self._lock_mode:
2119
2374
            self.repository.lock_write(self._repo_lock_token)
2120
2375
        return self._lock_token or None
2121
2376
 
2122
 
    def _set_tags_bytes(self, bytes):
2123
 
        self._ensure_real()
2124
 
        return self._real_branch._set_tags_bytes(bytes)
2125
 
 
2126
2377
    def _unlock(self, branch_token, repo_token):
2127
2378
        err_context = {'token': str((branch_token, repo_token))}
2128
2379
        response = self._call(
2150
2401
                    self._real_branch.unlock()
2151
2402
                if mode != 'w':
2152
2403
                    # Only write-locked branched need to make a remote method
2153
 
                    # call to perfom the unlock.
 
2404
                    # call to perform the unlock.
2154
2405
                    return
2155
2406
                if not self._lock_token:
2156
2407
                    raise AssertionError('Locked, but no token!')
2177
2428
            raise NotImplementedError(self.dont_leave_lock_in_place)
2178
2429
        self._leave_lock = False
2179
2430
 
 
2431
    def get_rev_id(self, revno, history=None):
 
2432
        if revno == 0:
 
2433
            return _mod_revision.NULL_REVISION
 
2434
        last_revision_info = self.last_revision_info()
 
2435
        ok, result = self.repository.get_rev_id_for_revno(
 
2436
            revno, last_revision_info)
 
2437
        if ok:
 
2438
            return result
 
2439
        missing_parent = result[1]
 
2440
        # Either the revision named by the server is missing, or its parent
 
2441
        # is.  Call get_parent_map to determine which, so that we report a
 
2442
        # useful error.
 
2443
        parent_map = self.repository.get_parent_map([missing_parent])
 
2444
        if missing_parent in parent_map:
 
2445
            missing_parent = parent_map[missing_parent]
 
2446
        raise errors.RevisionNotPresent(missing_parent, self.repository)
 
2447
 
2180
2448
    def _last_revision_info(self):
2181
2449
        response = self._call('Branch.last_revision_info', self._remote_path())
2182
2450
        if response[0] != 'ok':
2187
2455
 
2188
2456
    def _gen_revision_history(self):
2189
2457
        """See Branch._gen_revision_history()."""
 
2458
        if self._is_stacked:
 
2459
            self._ensure_real()
 
2460
            return self._real_branch._gen_revision_history()
2190
2461
        response_tuple, response_handler = self._call_expecting_body(
2191
2462
            'Branch.revision_history', self._remote_path())
2192
2463
        if response_tuple[0] != 'ok':
2277
2548
        self._ensure_real()
2278
2549
        return self._real_branch._get_parent_location()
2279
2550
 
2280
 
    def set_parent(self, url):
2281
 
        self._ensure_real()
2282
 
        return self._real_branch.set_parent(url)
2283
 
 
2284
2551
    def _set_parent_location(self, url):
2285
 
        # Used by tests, to poke bad urls into branch configurations
2286
 
        if url is None:
2287
 
            self.set_parent(url)
2288
 
        else:
2289
 
            self._ensure_real()
2290
 
            return self._real_branch._set_parent_location(url)
2291
 
 
2292
 
    def set_stacked_on_url(self, stacked_location):
2293
 
        """Set the URL this branch is stacked against.
2294
 
 
2295
 
        :raises UnstackableBranchFormat: If the branch does not support
2296
 
            stacking.
2297
 
        :raises UnstackableRepositoryFormat: If the repository does not support
2298
 
            stacking.
2299
 
        """
 
2552
        medium = self._client._medium
 
2553
        if medium._is_remote_before((1, 15)):
 
2554
            return self._vfs_set_parent_location(url)
 
2555
        try:
 
2556
            call_url = url or ''
 
2557
            if type(call_url) is not str:
 
2558
                raise AssertionError('url must be a str or None (%s)' % url)
 
2559
            response = self._call('Branch.set_parent_location',
 
2560
                self._remote_path(), self._lock_token, self._repo_lock_token,
 
2561
                call_url)
 
2562
        except errors.UnknownSmartMethod:
 
2563
            medium._remember_remote_is_before((1, 15))
 
2564
            return self._vfs_set_parent_location(url)
 
2565
        if response != ():
 
2566
            raise errors.UnexpectedSmartServerResponse(response)
 
2567
 
 
2568
    def _vfs_set_parent_location(self, url):
2300
2569
        self._ensure_real()
2301
 
        return self._real_branch.set_stacked_on_url(stacked_location)
 
2570
        return self._real_branch._set_parent_location(url)
2302
2571
 
2303
2572
    @needs_write_lock
2304
2573
    def pull(self, source, overwrite=False, stop_revision=None,
2372
2641
        return self._real_branch.set_push_location(location)
2373
2642
 
2374
2643
 
 
2644
class RemoteConfig(object):
 
2645
    """A Config that reads and writes from smart verbs.
 
2646
 
 
2647
    It is a low-level object that considers config data to be name/value pairs
 
2648
    that may be associated with a section. Assigning meaning to the these
 
2649
    values is done at higher levels like bzrlib.config.TreeConfig.
 
2650
    """
 
2651
 
 
2652
    def get_option(self, name, section=None, default=None):
 
2653
        """Return the value associated with a named option.
 
2654
 
 
2655
        :param name: The name of the value
 
2656
        :param section: The section the option is in (if any)
 
2657
        :param default: The value to return if the value is not set
 
2658
        :return: The value or default value
 
2659
        """
 
2660
        try:
 
2661
            configobj = self._get_configobj()
 
2662
            if section is None:
 
2663
                section_obj = configobj
 
2664
            else:
 
2665
                try:
 
2666
                    section_obj = configobj[section]
 
2667
                except KeyError:
 
2668
                    return default
 
2669
            return section_obj.get(name, default)
 
2670
        except errors.UnknownSmartMethod:
 
2671
            return self._vfs_get_option(name, section, default)
 
2672
 
 
2673
    def _response_to_configobj(self, response):
 
2674
        if len(response[0]) and response[0][0] != 'ok':
 
2675
            raise errors.UnexpectedSmartServerResponse(response)
 
2676
        lines = response[1].read_body_bytes().splitlines()
 
2677
        return config.ConfigObj(lines, encoding='utf-8')
 
2678
 
 
2679
 
 
2680
class RemoteBranchConfig(RemoteConfig):
 
2681
    """A RemoteConfig for Branches."""
 
2682
 
 
2683
    def __init__(self, branch):
 
2684
        self._branch = branch
 
2685
 
 
2686
    def _get_configobj(self):
 
2687
        path = self._branch._remote_path()
 
2688
        response = self._branch._client.call_expecting_body(
 
2689
            'Branch.get_config_file', path)
 
2690
        return self._response_to_configobj(response)
 
2691
 
 
2692
    def set_option(self, value, name, section=None):
 
2693
        """Set the value associated with a named option.
 
2694
 
 
2695
        :param value: The value to set
 
2696
        :param name: The name of the value to set
 
2697
        :param section: The section the option is in (if any)
 
2698
        """
 
2699
        medium = self._branch._client._medium
 
2700
        if medium._is_remote_before((1, 14)):
 
2701
            return self._vfs_set_option(value, name, section)
 
2702
        try:
 
2703
            path = self._branch._remote_path()
 
2704
            response = self._branch._client.call('Branch.set_config_option',
 
2705
                path, self._branch._lock_token, self._branch._repo_lock_token,
 
2706
                value.encode('utf8'), name, section or '')
 
2707
        except errors.UnknownSmartMethod:
 
2708
            medium._remember_remote_is_before((1, 14))
 
2709
            return self._vfs_set_option(value, name, section)
 
2710
        if response != ():
 
2711
            raise errors.UnexpectedSmartServerResponse(response)
 
2712
 
 
2713
    def _real_object(self):
 
2714
        self._branch._ensure_real()
 
2715
        return self._branch._real_branch
 
2716
 
 
2717
    def _vfs_set_option(self, value, name, section=None):
 
2718
        return self._real_object()._get_config().set_option(
 
2719
            value, name, section)
 
2720
 
 
2721
 
 
2722
class RemoteBzrDirConfig(RemoteConfig):
 
2723
    """A RemoteConfig for BzrDirs."""
 
2724
 
 
2725
    def __init__(self, bzrdir):
 
2726
        self._bzrdir = bzrdir
 
2727
 
 
2728
    def _get_configobj(self):
 
2729
        medium = self._bzrdir._client._medium
 
2730
        verb = 'BzrDir.get_config_file'
 
2731
        if medium._is_remote_before((1, 15)):
 
2732
            raise errors.UnknownSmartMethod(verb)
 
2733
        path = self._bzrdir._path_for_remote_call(self._bzrdir._client)
 
2734
        response = self._bzrdir._call_expecting_body(
 
2735
            verb, path)
 
2736
        return self._response_to_configobj(response)
 
2737
 
 
2738
    def _vfs_get_option(self, name, section, default):
 
2739
        return self._real_object()._get_config().get_option(
 
2740
            name, section, default)
 
2741
 
 
2742
    def set_option(self, value, name, section=None):
 
2743
        """Set the value associated with a named option.
 
2744
 
 
2745
        :param value: The value to set
 
2746
        :param name: The name of the value to set
 
2747
        :param section: The section the option is in (if any)
 
2748
        """
 
2749
        return self._real_object()._get_config().set_option(
 
2750
            value, name, section)
 
2751
 
 
2752
    def _real_object(self):
 
2753
        self._bzrdir._ensure_real()
 
2754
        return self._bzrdir._real_bzrdir
 
2755
 
 
2756
 
 
2757
 
2375
2758
def _extract_tar(tar, to_dir):
2376
2759
    """Extract all the contents of a tarfile object.
2377
2760
 
2415
2798
                    'Missing key %r in context %r', key_err.args[0], context)
2416
2799
                raise err
2417
2800
 
2418
 
    if err.error_verb == 'NoSuchRevision':
 
2801
    if err.error_verb == 'IncompatibleRepositories':
 
2802
        raise errors.IncompatibleRepositories(err.error_args[0],
 
2803
            err.error_args[1], err.error_args[2])
 
2804
    elif err.error_verb == 'NoSuchRevision':
2419
2805
        raise NoSuchRevision(find('branch'), err.error_args[0])
2420
2806
    elif err.error_verb == 'nosuchrevision':
2421
2807
        raise NoSuchRevision(find('repository'), err.error_args[0])