/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    lock,
28
28
    lockdir,
29
29
    repository,
 
30
    repository as _mod_repository,
30
31
    revision,
31
32
    revision as _mod_revision,
 
33
    static_tuple,
32
34
    symbol_versioning,
33
35
)
34
36
from bzrlib.branch import BranchReferenceFormat
242
244
        self._ensure_real()
243
245
        self._real_bzrdir.destroy_repository()
244
246
 
245
 
    def create_branch(self):
 
247
    def create_branch(self, name=None):
246
248
        # as per meta1 formats - just delegate to the format object which may
247
249
        # be parameterised.
248
 
        real_branch = self._format.get_branch_format().initialize(self)
 
250
        real_branch = self._format.get_branch_format().initialize(self,
 
251
            name=name)
249
252
        if not isinstance(real_branch, RemoteBranch):
250
 
            result = RemoteBranch(self, self.find_repository(), real_branch)
 
253
            result = RemoteBranch(self, self.find_repository(), real_branch,
 
254
                                  name=name)
251
255
        else:
252
256
            result = real_branch
253
257
        # BzrDir.clone_on_transport() uses the result of create_branch but does
259
263
        self._next_open_branch_result = result
260
264
        return result
261
265
 
262
 
    def destroy_branch(self):
 
266
    def destroy_branch(self, name=None):
263
267
        """See BzrDir.destroy_branch"""
264
268
        self._ensure_real()
265
 
        self._real_bzrdir.destroy_branch()
 
269
        self._real_bzrdir.destroy_branch(name=name)
266
270
        self._next_open_branch_result = None
267
271
 
268
272
    def create_workingtree(self, revision_id=None, from_branch=None):
318
322
        """See BzrDir._get_tree_branch()."""
319
323
        return None, self.open_branch()
320
324
 
321
 
    def open_branch(self, _unsupported=False, ignore_fallbacks=False):
322
 
        if _unsupported:
 
325
    def open_branch(self, name=None, unsupported=False,
 
326
                    ignore_fallbacks=False):
 
327
        if unsupported:
323
328
            raise NotImplementedError('unsupported flag support not implemented yet.')
324
329
        if self._next_open_branch_result is not None:
325
330
            # See create_branch for details.
330
335
        if response[0] == 'ref':
331
336
            # a branch reference, use the existing BranchReference logic.
332
337
            format = BranchReferenceFormat()
333
 
            return format.open(self, _found=True, location=response[1],
334
 
                ignore_fallbacks=ignore_fallbacks)
 
338
            return format.open(self, name=name, _found=True,
 
339
                location=response[1], ignore_fallbacks=ignore_fallbacks)
335
340
        branch_format_name = response[1]
336
341
        if not branch_format_name:
337
342
            branch_format_name = None
338
343
        format = RemoteBranchFormat(network_name=branch_format_name)
339
344
        return RemoteBranch(self, self.find_repository(), format=format,
340
 
            setup_stacking=not ignore_fallbacks)
 
345
            setup_stacking=not ignore_fallbacks, name=name)
341
346
 
342
347
    def _open_repo_v1(self, path):
343
348
        verb = 'BzrDir.find_repository'
420
425
        """Return the path to be used for this bzrdir in a remote call."""
421
426
        return client.remote_path_from_transport(self.root_transport)
422
427
 
423
 
    def get_branch_transport(self, branch_format):
 
428
    def get_branch_transport(self, branch_format, name=None):
424
429
        self._ensure_real()
425
 
        return self._real_bzrdir.get_branch_transport(branch_format)
 
430
        return self._real_bzrdir.get_branch_transport(branch_format, name=name)
426
431
 
427
432
    def get_repository_transport(self, repository_format):
428
433
        self._ensure_real()
638
643
        return self._custom_format._serializer
639
644
 
640
645
 
641
 
class RemoteRepository(_RpcHelper, lock._RelockDebugMixin):
 
646
class RemoteRepository(_RpcHelper, lock._RelockDebugMixin,
 
647
    bzrdir.ControlComponent):
642
648
    """Repository accessed over rpc.
643
649
 
644
650
    For the moment most operations are performed using local transport-backed
687
693
        # Additional places to query for data.
688
694
        self._fallback_repositories = []
689
695
 
 
696
    @property
 
697
    def user_transport(self):
 
698
        return self.bzrdir.user_transport
 
699
 
 
700
    @property
 
701
    def control_transport(self):
 
702
        # XXX: Normally you shouldn't directly get at the remote repository
 
703
        # transport, but I'm not sure it's worth making this method
 
704
        # optional -- mbp 2010-04-21
 
705
        return self.bzrdir.get_repository_transport(None)
 
706
        
690
707
    def __str__(self):
691
708
        return "%s(%s)" % (self.__class__.__name__, self.base)
692
709
 
900
917
        parents_provider = self._make_parents_provider(other_repository)
901
918
        return graph.Graph(parents_provider)
902
919
 
 
920
    @needs_read_lock
 
921
    def get_known_graph_ancestry(self, revision_ids):
 
922
        """Return the known graph for a set of revision ids and their ancestors.
 
923
        """
 
924
        st = static_tuple.StaticTuple
 
925
        revision_keys = [st(r_id).intern() for r_id in revision_ids]
 
926
        known_graph = self.revisions.get_known_graph_ancestry(revision_keys)
 
927
        return graph.GraphThunkIdsToKeys(known_graph)
 
928
 
903
929
    def gather_stats(self, revid=None, committers=None):
904
930
        """See Repository.gather_stats()."""
905
931
        path = self.bzrdir._path_for_remote_call(self._client)
1214
1240
            # state, so always add a lock here. If a caller passes us a locked
1215
1241
            # repository, they are responsible for unlocking it later.
1216
1242
            repository.lock_read()
 
1243
        self._check_fallback_repository(repository)
1217
1244
        self._fallback_repositories.append(repository)
1218
1245
        # If self._real_repository was parameterised already (e.g. because a
1219
1246
        # _real_branch had its get_stacked_on_url method called), then the
1220
1247
        # repository to be added may already be in the _real_repositories list.
1221
1248
        if self._real_repository is not None:
1222
 
            fallback_locations = [repo.bzrdir.root_transport.base for repo in
 
1249
            fallback_locations = [repo.user_url for repo in
1223
1250
                self._real_repository._fallback_repositories]
1224
 
            if repository.bzrdir.root_transport.base not in fallback_locations:
 
1251
            if repository.user_url not in fallback_locations:
1225
1252
                self._real_repository.add_fallback_repository(repository)
1226
1253
 
 
1254
    def _check_fallback_repository(self, repository):
 
1255
        """Check that this repository can fallback to repository safely.
 
1256
 
 
1257
        Raise an error if not.
 
1258
 
 
1259
        :param repository: A repository to fallback to.
 
1260
        """
 
1261
        return _mod_repository.InterRepository._assert_same_model(
 
1262
            self, repository)
 
1263
 
1227
1264
    def add_inventory(self, revid, inv, parents):
1228
1265
        self._ensure_real()
1229
1266
        return self._real_repository.add_inventory(revid, inv, parents)
1230
1267
 
1231
1268
    def add_inventory_by_delta(self, basis_revision_id, delta, new_revision_id,
1232
 
                               parents):
 
1269
            parents, basis_inv=None, propagate_caches=False):
1233
1270
        self._ensure_real()
1234
1271
        return self._real_repository.add_inventory_by_delta(basis_revision_id,
1235
 
            delta, new_revision_id, parents)
 
1272
            delta, new_revision_id, parents, basis_inv=basis_inv,
 
1273
            propagate_caches=propagate_caches)
1236
1274
 
1237
1275
    def add_revision(self, rev_id, rev, inv=None, config=None):
1238
1276
        self._ensure_real()
1501
1539
        self._ensure_real()
1502
1540
        return self._real_repository._get_inventory_xml(revision_id)
1503
1541
 
1504
 
    def _deserialise_inventory(self, revision_id, xml):
1505
 
        self._ensure_real()
1506
 
        return self._real_repository._deserialise_inventory(revision_id, xml)
1507
 
 
1508
1542
    def reconcile(self, other=None, thorough=False):
1509
1543
        self._ensure_real()
1510
1544
        return self._real_repository.reconcile(other=other, thorough=thorough)
1585
1619
        return self._real_repository.inventories
1586
1620
 
1587
1621
    @needs_write_lock
1588
 
    def pack(self, hint=None):
 
1622
    def pack(self, hint=None, clean_obsolete_packs=False):
1589
1623
        """Compress the data within the repository.
1590
1624
 
1591
1625
        This is not currently implemented within the smart server.
1592
1626
        """
1593
1627
        self._ensure_real()
1594
 
        return self._real_repository.pack(hint=hint)
 
1628
        return self._real_repository.pack(hint=hint, clean_obsolete_packs=clean_obsolete_packs)
1595
1629
 
1596
1630
    @property
1597
1631
    def revisions(self):
2025
2059
    def network_name(self):
2026
2060
        return self._network_name
2027
2061
 
2028
 
    def open(self, a_bzrdir, ignore_fallbacks=False):
2029
 
        return a_bzrdir.open_branch(ignore_fallbacks=ignore_fallbacks)
 
2062
    def open(self, a_bzrdir, name=None, ignore_fallbacks=False):
 
2063
        return a_bzrdir.open_branch(name=name, 
 
2064
            ignore_fallbacks=ignore_fallbacks)
2030
2065
 
2031
 
    def _vfs_initialize(self, a_bzrdir):
 
2066
    def _vfs_initialize(self, a_bzrdir, name):
2032
2067
        # Initialisation when using a local bzrdir object, or a non-vfs init
2033
2068
        # method is not available on the server.
2034
2069
        # self._custom_format is always set - the start of initialize ensures
2035
2070
        # that.
2036
2071
        if isinstance(a_bzrdir, RemoteBzrDir):
2037
2072
            a_bzrdir._ensure_real()
2038
 
            result = self._custom_format.initialize(a_bzrdir._real_bzrdir)
 
2073
            result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
 
2074
                name)
2039
2075
        else:
2040
2076
            # We assume the bzrdir is parameterised; it may not be.
2041
 
            result = self._custom_format.initialize(a_bzrdir)
 
2077
            result = self._custom_format.initialize(a_bzrdir, name)
2042
2078
        if (isinstance(a_bzrdir, RemoteBzrDir) and
2043
2079
            not isinstance(result, RemoteBranch)):
2044
 
            result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result)
 
2080
            result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result,
 
2081
                                  name=name)
2045
2082
        return result
2046
2083
 
2047
 
    def initialize(self, a_bzrdir):
 
2084
    def initialize(self, a_bzrdir, name=None):
2048
2085
        # 1) get the network name to use.
2049
2086
        if self._custom_format:
2050
2087
            network_name = self._custom_format.network_name()
2056
2093
            network_name = reference_format.network_name()
2057
2094
        # Being asked to create on a non RemoteBzrDir:
2058
2095
        if not isinstance(a_bzrdir, RemoteBzrDir):
2059
 
            return self._vfs_initialize(a_bzrdir)
 
2096
            return self._vfs_initialize(a_bzrdir, name=name)
2060
2097
        medium = a_bzrdir._client._medium
2061
2098
        if medium._is_remote_before((1, 13)):
2062
 
            return self._vfs_initialize(a_bzrdir)
 
2099
            return self._vfs_initialize(a_bzrdir, name=name)
2063
2100
        # Creating on a remote bzr dir.
2064
2101
        # 2) try direct creation via RPC
2065
2102
        path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
 
2103
        if name is not None:
 
2104
            # XXX JRV20100304: Support creating colocated branches
 
2105
            raise errors.NoColocatedBranchSupport(self)
2066
2106
        verb = 'BzrDir.create_branch'
2067
2107
        try:
2068
2108
            response = a_bzrdir._call(verb, path, network_name)
2069
2109
        except errors.UnknownSmartMethod:
2070
2110
            # Fallback - use vfs methods
2071
2111
            medium._remember_remote_is_before((1, 13))
2072
 
            return self._vfs_initialize(a_bzrdir)
 
2112
            return self._vfs_initialize(a_bzrdir, name=name)
2073
2113
        if response[0] != 'ok':
2074
2114
            raise errors.UnexpectedSmartServerResponse(response)
2075
2115
        # Turn the response into a RemoteRepository object.
2083
2123
                a_bzrdir._client)
2084
2124
        remote_repo = RemoteRepository(repo_bzrdir, repo_format)
2085
2125
        remote_branch = RemoteBranch(a_bzrdir, remote_repo,
2086
 
            format=format, setup_stacking=False)
 
2126
            format=format, setup_stacking=False, name=name)
2087
2127
        # XXX: We know this is a new branch, so it must have revno 0, revid
2088
2128
        # NULL_REVISION. Creating the branch locked would make this be unable
2089
2129
        # to be wrong; here its simply very unlikely to be wrong. RBC 20090225
2116
2156
    """
2117
2157
 
2118
2158
    def __init__(self, remote_bzrdir, remote_repository, real_branch=None,
2119
 
        _client=None, format=None, setup_stacking=True):
 
2159
        _client=None, format=None, setup_stacking=True, name=None):
2120
2160
        """Create a RemoteBranch instance.
2121
2161
 
2122
2162
        :param real_branch: An optional local implementation of the branch
2128
2168
        :param setup_stacking: If True make an RPC call to determine the
2129
2169
            stacked (or not) status of the branch. If False assume the branch
2130
2170
            is not stacked.
 
2171
        :param name: Colocated branch name
2131
2172
        """
2132
2173
        # We intentionally don't call the parent class's __init__, because it
2133
2174
        # will try to assign to self.tags, which is a property in this subclass.
2152
2193
            self._real_branch = None
2153
2194
        # Fill out expected attributes of branch for bzrlib API users.
2154
2195
        self._clear_cached_state()
2155
 
        self.base = self.bzrdir.root_transport.base
 
2196
        # TODO: deprecate self.base in favor of user_url
 
2197
        self.base = self.bzrdir.user_url
 
2198
        self._name = name
2156
2199
        self._control_files = None
2157
2200
        self._lock_mode = None
2158
2201
        self._lock_token = None
2223
2266
                    'to use vfs implementation')
2224
2267
            self.bzrdir._ensure_real()
2225
2268
            self._real_branch = self.bzrdir._real_bzrdir.open_branch(
2226
 
                ignore_fallbacks=self._real_ignore_fallbacks)
 
2269
                ignore_fallbacks=self._real_ignore_fallbacks, name=self._name)
2227
2270
            if self.repository._real_repository is None:
2228
2271
                # Give the remote repository the matching real repo.
2229
2272
                real_repo = self._real_branch.repository