/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: Jelmer Vernooij
  • Date: 2010-03-21 21:39:33 UTC
  • mfrom: (5102 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5143.
  • Revision ID: jelmer@samba.org-20100321213933-fexeh9zcoz8oaju2
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
115
115
 
116
116
        self._probe_bzrdir()
117
117
 
 
118
    def __repr__(self):
 
119
        return '%s(%r)' % (self.__class__.__name__, self._client)
 
120
 
118
121
    def _probe_bzrdir(self):
119
122
        medium = self._client._medium
120
123
        path = self._path_for_remote_call(self._client)
240
243
        self._ensure_real()
241
244
        self._real_bzrdir.destroy_repository()
242
245
 
243
 
    def create_branch(self):
 
246
    def create_branch(self, name=None):
244
247
        # as per meta1 formats - just delegate to the format object which may
245
248
        # be parameterised.
246
 
        real_branch = self._format.get_branch_format().initialize(self)
 
249
        real_branch = self._format.get_branch_format().initialize(self,
 
250
            name=name)
247
251
        if not isinstance(real_branch, RemoteBranch):
248
 
            result = RemoteBranch(self, self.find_repository(), real_branch)
 
252
            result = RemoteBranch(self, self.find_repository(), real_branch,
 
253
                                  name=name)
249
254
        else:
250
255
            result = real_branch
251
256
        # BzrDir.clone_on_transport() uses the result of create_branch but does
257
262
        self._next_open_branch_result = result
258
263
        return result
259
264
 
260
 
    def destroy_branch(self):
 
265
    def destroy_branch(self, name=None):
261
266
        """See BzrDir.destroy_branch"""
262
267
        self._ensure_real()
263
 
        self._real_bzrdir.destroy_branch()
 
268
        self._real_bzrdir.destroy_branch(name=name)
264
269
        self._next_open_branch_result = None
265
270
 
266
271
    def create_workingtree(self, revision_id=None, from_branch=None):
285
290
    def _get_branch_reference(self):
286
291
        path = self._path_for_remote_call(self._client)
287
292
        medium = self._client._medium
288
 
        if not medium._is_remote_before((1, 13)):
 
293
        candidate_calls = [
 
294
            ('BzrDir.open_branchV3', (2, 1)),
 
295
            ('BzrDir.open_branchV2', (1, 13)),
 
296
            ('BzrDir.open_branch', None),
 
297
            ]
 
298
        for verb, required_version in candidate_calls:
 
299
            if required_version and medium._is_remote_before(required_version):
 
300
                continue
289
301
            try:
290
 
                response = self._call('BzrDir.open_branchV2', path)
291
 
                if response[0] not in ('ref', 'branch'):
292
 
                    raise errors.UnexpectedSmartServerResponse(response)
293
 
                return response
 
302
                response = self._call(verb, path)
294
303
            except errors.UnknownSmartMethod:
295
 
                medium._remember_remote_is_before((1, 13))
296
 
        response = self._call('BzrDir.open_branch', path)
297
 
        if response[0] != 'ok':
 
304
                if required_version is None:
 
305
                    raise
 
306
                medium._remember_remote_is_before(required_version)
 
307
            else:
 
308
                break
 
309
        if verb == 'BzrDir.open_branch':
 
310
            if response[0] != 'ok':
 
311
                raise errors.UnexpectedSmartServerResponse(response)
 
312
            if response[1] != '':
 
313
                return ('ref', response[1])
 
314
            else:
 
315
                return ('branch', '')
 
316
        if response[0] not in ('ref', 'branch'):
298
317
            raise errors.UnexpectedSmartServerResponse(response)
299
 
        if response[1] != '':
300
 
            return ('ref', response[1])
301
 
        else:
302
 
            return ('branch', '')
 
318
        return response
303
319
 
304
320
    def _get_tree_branch(self):
305
321
        """See BzrDir._get_tree_branch()."""
306
322
        return None, self.open_branch()
307
323
 
308
 
    def open_branch(self, _unsupported=False, ignore_fallbacks=False):
309
 
        if _unsupported:
 
324
    def open_branch(self, name=None, unsupported=False,
 
325
                    ignore_fallbacks=False):
 
326
        if unsupported:
310
327
            raise NotImplementedError('unsupported flag support not implemented yet.')
311
328
        if self._next_open_branch_result is not None:
312
329
            # See create_branch for details.
317
334
        if response[0] == 'ref':
318
335
            # a branch reference, use the existing BranchReference logic.
319
336
            format = BranchReferenceFormat()
320
 
            return format.open(self, _found=True, location=response[1],
321
 
                ignore_fallbacks=ignore_fallbacks)
 
337
            return format.open(self, name=name, _found=True,
 
338
                location=response[1], ignore_fallbacks=ignore_fallbacks)
322
339
        branch_format_name = response[1]
323
340
        if not branch_format_name:
324
341
            branch_format_name = None
325
342
        format = RemoteBranchFormat(network_name=branch_format_name)
326
343
        return RemoteBranch(self, self.find_repository(), format=format,
327
 
            setup_stacking=not ignore_fallbacks)
 
344
            setup_stacking=not ignore_fallbacks, name=name)
328
345
 
329
346
    def _open_repo_v1(self, path):
330
347
        verb = 'BzrDir.find_repository'
407
424
        """Return the path to be used for this bzrdir in a remote call."""
408
425
        return client.remote_path_from_transport(self.root_transport)
409
426
 
410
 
    def get_branch_transport(self, branch_format):
 
427
    def get_branch_transport(self, branch_format, name=None):
411
428
        self._ensure_real()
412
 
        return self._real_bzrdir.get_branch_transport(branch_format)
 
429
        return self._real_bzrdir.get_branch_transport(branch_format, name=name)
413
430
 
414
431
    def get_repository_transport(self, repository_format):
415
432
        self._ensure_real()
1225
1242
        return self._real_repository.add_inventory(revid, inv, parents)
1226
1243
 
1227
1244
    def add_inventory_by_delta(self, basis_revision_id, delta, new_revision_id,
1228
 
                               parents):
 
1245
            parents, basis_inv=None, propagate_caches=False):
1229
1246
        self._ensure_real()
1230
1247
        return self._real_repository.add_inventory_by_delta(basis_revision_id,
1231
 
            delta, new_revision_id, parents)
 
1248
            delta, new_revision_id, parents, basis_inv=basis_inv,
 
1249
            propagate_caches=propagate_caches)
1232
1250
 
1233
1251
    def add_revision(self, rev_id, rev, inv=None, config=None):
1234
1252
        self._ensure_real()
1493
1511
        return self._real_repository.get_signature_text(revision_id)
1494
1512
 
1495
1513
    @needs_read_lock
1496
 
    def get_inventory_xml(self, revision_id):
1497
 
        self._ensure_real()
1498
 
        return self._real_repository.get_inventory_xml(revision_id)
1499
 
 
1500
 
    def deserialise_inventory(self, revision_id, xml):
1501
 
        self._ensure_real()
1502
 
        return self._real_repository.deserialise_inventory(revision_id, xml)
 
1514
    def _get_inventory_xml(self, revision_id):
 
1515
        self._ensure_real()
 
1516
        return self._real_repository._get_inventory_xml(revision_id)
1503
1517
 
1504
1518
    def reconcile(self, other=None, thorough=False):
1505
1519
        self._ensure_real()
2021
2035
    def network_name(self):
2022
2036
        return self._network_name
2023
2037
 
2024
 
    def open(self, a_bzrdir, ignore_fallbacks=False):
2025
 
        return a_bzrdir.open_branch(ignore_fallbacks=ignore_fallbacks)
 
2038
    def open(self, a_bzrdir, name=None, ignore_fallbacks=False):
 
2039
        return a_bzrdir.open_branch(name=name, 
 
2040
            ignore_fallbacks=ignore_fallbacks)
2026
2041
 
2027
 
    def _vfs_initialize(self, a_bzrdir):
 
2042
    def _vfs_initialize(self, a_bzrdir, name):
2028
2043
        # Initialisation when using a local bzrdir object, or a non-vfs init
2029
2044
        # method is not available on the server.
2030
2045
        # self._custom_format is always set - the start of initialize ensures
2031
2046
        # that.
2032
2047
        if isinstance(a_bzrdir, RemoteBzrDir):
2033
2048
            a_bzrdir._ensure_real()
2034
 
            result = self._custom_format.initialize(a_bzrdir._real_bzrdir)
 
2049
            result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
 
2050
                name)
2035
2051
        else:
2036
2052
            # We assume the bzrdir is parameterised; it may not be.
2037
 
            result = self._custom_format.initialize(a_bzrdir)
 
2053
            result = self._custom_format.initialize(a_bzrdir, name)
2038
2054
        if (isinstance(a_bzrdir, RemoteBzrDir) and
2039
2055
            not isinstance(result, RemoteBranch)):
2040
 
            result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result)
 
2056
            result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result,
 
2057
                                  name=name)
2041
2058
        return result
2042
2059
 
2043
 
    def initialize(self, a_bzrdir):
 
2060
    def initialize(self, a_bzrdir, name=None):
2044
2061
        # 1) get the network name to use.
2045
2062
        if self._custom_format:
2046
2063
            network_name = self._custom_format.network_name()
2052
2069
            network_name = reference_format.network_name()
2053
2070
        # Being asked to create on a non RemoteBzrDir:
2054
2071
        if not isinstance(a_bzrdir, RemoteBzrDir):
2055
 
            return self._vfs_initialize(a_bzrdir)
 
2072
            return self._vfs_initialize(a_bzrdir, name=name)
2056
2073
        medium = a_bzrdir._client._medium
2057
2074
        if medium._is_remote_before((1, 13)):
2058
 
            return self._vfs_initialize(a_bzrdir)
 
2075
            return self._vfs_initialize(a_bzrdir, name=name)
2059
2076
        # Creating on a remote bzr dir.
2060
2077
        # 2) try direct creation via RPC
2061
2078
        path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
 
2079
        if name is not None:
 
2080
            # XXX JRV20100304: Support creating colocated branches
 
2081
            raise errors.NoColocatedBranchSupport(self)
2062
2082
        verb = 'BzrDir.create_branch'
2063
2083
        try:
2064
2084
            response = a_bzrdir._call(verb, path, network_name)
2065
2085
        except errors.UnknownSmartMethod:
2066
2086
            # Fallback - use vfs methods
2067
2087
            medium._remember_remote_is_before((1, 13))
2068
 
            return self._vfs_initialize(a_bzrdir)
 
2088
            return self._vfs_initialize(a_bzrdir, name=name)
2069
2089
        if response[0] != 'ok':
2070
2090
            raise errors.UnexpectedSmartServerResponse(response)
2071
2091
        # Turn the response into a RemoteRepository object.
2079
2099
                a_bzrdir._client)
2080
2100
        remote_repo = RemoteRepository(repo_bzrdir, repo_format)
2081
2101
        remote_branch = RemoteBranch(a_bzrdir, remote_repo,
2082
 
            format=format, setup_stacking=False)
 
2102
            format=format, setup_stacking=False, name=name)
2083
2103
        # XXX: We know this is a new branch, so it must have revno 0, revid
2084
2104
        # NULL_REVISION. Creating the branch locked would make this be unable
2085
2105
        # to be wrong; here its simply very unlikely to be wrong. RBC 20090225
2112
2132
    """
2113
2133
 
2114
2134
    def __init__(self, remote_bzrdir, remote_repository, real_branch=None,
2115
 
        _client=None, format=None, setup_stacking=True):
 
2135
        _client=None, format=None, setup_stacking=True, name=None):
2116
2136
        """Create a RemoteBranch instance.
2117
2137
 
2118
2138
        :param real_branch: An optional local implementation of the branch
2124
2144
        :param setup_stacking: If True make an RPC call to determine the
2125
2145
            stacked (or not) status of the branch. If False assume the branch
2126
2146
            is not stacked.
 
2147
        :param name: Colocated branch name
2127
2148
        """
2128
2149
        # We intentionally don't call the parent class's __init__, because it
2129
2150
        # will try to assign to self.tags, which is a property in this subclass.
2149
2170
        # Fill out expected attributes of branch for bzrlib API users.
2150
2171
        self._clear_cached_state()
2151
2172
        self.base = self.bzrdir.root_transport.base
 
2173
        self._name = name
2152
2174
        self._control_files = None
2153
2175
        self._lock_mode = None
2154
2176
        self._lock_token = None
2219
2241
                    'to use vfs implementation')
2220
2242
            self.bzrdir._ensure_real()
2221
2243
            self._real_branch = self.bzrdir._real_bzrdir.open_branch(
2222
 
                ignore_fallbacks=self._real_ignore_fallbacks)
 
2244
                ignore_fallbacks=self._real_ignore_fallbacks, name=self._name)
2223
2245
            if self.repository._real_repository is None:
2224
2246
                # Give the remote repository the matching real repo.
2225
2247
                real_repo = self._real_branch.repository
2833
2855
        raise NoSuchRevision(find('branch'), err.error_args[0])
2834
2856
    elif err.error_verb == 'nosuchrevision':
2835
2857
        raise NoSuchRevision(find('repository'), err.error_args[0])
2836
 
    elif err.error_tuple == ('nobranch',):
2837
 
        raise errors.NotBranchError(path=find('bzrdir').root_transport.base)
 
2858
    elif err.error_verb == 'nobranch':
 
2859
        if len(err.error_args) >= 1:
 
2860
            extra = err.error_args[0]
 
2861
        else:
 
2862
            extra = None
 
2863
        raise errors.NotBranchError(path=find('bzrdir').root_transport.base,
 
2864
            detail=extra)
2838
2865
    elif err.error_verb == 'norepository':
2839
2866
        raise errors.NoRepositoryPresent(find('bzrdir'))
2840
2867
    elif err.error_verb == 'LockContention':