/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: 2009-03-06 03:55:27 UTC
  • mto: (4086.1.1 hpss-integration)
  • mto: This revision was merged to the branch mainline in revision 4087.
  • Revision ID: robertc@robertcollins.net-20090306035527-sm1gsd3nh3f2mxpa
Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.

Show diffs side-by-side

added added

removed removed

Lines of Context:
226
226
 
227
227
    def get_branch_reference(self):
228
228
        """See BzrDir.get_branch_reference()."""
 
229
        response = self._get_branch_reference()
 
230
        if response[0] == 'ref':
 
231
            return response[1]
 
232
        else:
 
233
            return None
 
234
 
 
235
    def _get_branch_reference(self):
229
236
        path = self._path_for_remote_call(self._client)
 
237
        medium = self._client._medium
 
238
        if not medium._is_remote_before((1, 13)):
 
239
            try:
 
240
                response = self._call('BzrDir.open_branchV2', path)
 
241
                if response[0] not in ('ref', 'branch'):
 
242
                    raise errors.UnexpectedSmartServerResponse(response)
 
243
                return response
 
244
            except errors.UnknownSmartMethod:
 
245
                pass
230
246
        response = self._call('BzrDir.open_branch', path)
231
 
        if response[0] == 'ok':
232
 
            if response[1] == '':
233
 
                # branch at this location.
234
 
                return None
235
 
            else:
236
 
                # a branch reference, use the existing BranchReference logic.
237
 
                return response[1]
 
247
        if response[0] != 'ok':
 
248
            raise errors.UnexpectedSmartServerResponse(response)
 
249
        if response[1] != '':
 
250
            return ('ref', response[1])
238
251
        else:
239
 
            raise errors.UnexpectedSmartServerResponse(response)
 
252
            return ('branch', '')
240
253
 
241
254
    def _get_tree_branch(self):
242
255
        """See BzrDir._get_tree_branch()."""
250
263
            result = self._next_open_branch_result
251
264
            self._next_open_branch_result = None
252
265
            return result
253
 
        reference_url = self.get_branch_reference()
254
 
        if reference_url is None:
255
 
            # branch at this location.
256
 
            return RemoteBranch(self, self.find_repository())
257
 
        else:
 
266
        response = self._get_branch_reference()
 
267
        if response[0] == 'ref':
258
268
            # a branch reference, use the existing BranchReference logic.
259
269
            format = BranchReferenceFormat()
260
270
            return format.open(self, _found=True, location=reference_url)
 
271
        branch_format_name = response[1]
 
272
        if not branch_format_name:
 
273
            branch_format_name = None
 
274
        format = RemoteBranchFormat(network_name=branch_format_name)
 
275
        return RemoteBranch(self, self.find_repository(), format=format)
261
276
 
262
277
    def _open_repo_v1(self, path):
263
278
        verb = 'BzrDir.find_repository'
1562
1577
 
1563
1578
class RemoteBranchFormat(branch.BranchFormat):
1564
1579
 
1565
 
    def __init__(self):
 
1580
    def __init__(self, network_name=None):
1566
1581
        super(RemoteBranchFormat, self).__init__()
1567
1582
        self._matchingbzrdir = RemoteBzrDirFormat()
1568
1583
        self._matchingbzrdir.set_branch_format(self)
1569
1584
        self._custom_format = None
 
1585
        self._network_name = network_name
1570
1586
 
1571
1587
    def __eq__(self, other):
1572
1588
        return (isinstance(other, RemoteBranchFormat) and
1573
1589
            self.__dict__ == other.__dict__)
1574
1590
 
 
1591
    def _ensure_real(self):
 
1592
        if self._custom_format is None:
 
1593
            self._custom_format = branch.network_format_registry.get(
 
1594
                self._network_name)
 
1595
 
1575
1596
    def get_format_description(self):
1576
1597
        return 'Remote BZR Branch'
1577
1598
 
1625
1646
        if response[0] != 'ok':
1626
1647
            raise errors.UnexpectedSmartServerResponse(response)
1627
1648
        # Turn the response into a RemoteRepository object.
1628
 
        format = RemoteBranchFormat()
1629
 
        format._network_name = response[1]
 
1649
        format = RemoteBranchFormat(network_name=response[1])
1630
1650
        repo_format = response_tuple_to_repo_format(response[3:])
1631
1651
        if response[2] == '':
1632
1652
            repo_bzrdir = a_bzrdir
1643
1663
        remote_branch._last_revision_info_cache = 0, NULL_REVISION
1644
1664
        return remote_branch
1645
1665
 
 
1666
    def make_tags(self, branch):
 
1667
        self._ensure_real()
 
1668
        return self._custom_format.make_tags(branch)
 
1669
 
1646
1670
    def supports_tags(self):
1647
1671
        # Remote branches might support tags, but we won't know until we
1648
1672
        # access the real remote branch.
1649
 
        return True
 
1673
        self._ensure_real()
 
1674
        return self._custom_format.supports_tags()
1650
1675
 
1651
1676
 
1652
1677
class RemoteBranch(branch.Branch, _RpcHelper):
1711
1736
            if real_branch is not None:
1712
1737
                self._format._network_name = \
1713
1738
                    self._real_branch._format.network_name()
1714
 
            #else:
1715
 
            #    # XXX: Need to get this from BzrDir.open_branch's return value.
1716
 
            #    self._ensure_real()
1717
 
            #    self._format._network_name = \
1718
 
            #        self._real_branch._format.network_name()
1719
1739
        else:
1720
1740
            self._format = format
 
1741
        if not self._format._network_name:
 
1742
            # Did not get from open_branchV2 - old server.
 
1743
            self._ensure_real()
 
1744
            self._format._network_name = \
 
1745
                self._real_branch._format.network_name()
 
1746
        self.tags = self._format.make_tags(self)
1721
1747
        # The base class init is not called, so we duplicate this:
1722
1748
        hooks = branch.Branch.hooks['open']
1723
1749
        for hook in hooks:
1848
1874
            raise errors.UnexpectedSmartServerResponse(response)
1849
1875
        return response[1]
1850
1876
 
 
1877
    def _vfs_get_tags_bytes(self):
 
1878
        self._ensure_real()
 
1879
        return self._real_branch._get_tags_bytes()
 
1880
 
 
1881
    def _get_tags_bytes(self):
 
1882
        medium = self._client._medium
 
1883
        if medium._is_remote_before((1, 13)):
 
1884
            return self._vfs_get_tags_bytes()
 
1885
        try:
 
1886
            response = self._call('Branch.get_tags_bytes', self._remote_path())
 
1887
        except errors.UnknownSmartMethod:
 
1888
            return self._vfs_get_tags_bytes()
 
1889
        return response[0]
 
1890
 
1851
1891
    def lock_read(self):
1852
1892
        self.repository.lock_read()
1853
1893
        if not self._lock_mode:
1907
1947
            self.repository.lock_write(self._repo_lock_token)
1908
1948
        return self._lock_token or None
1909
1949
 
 
1950
    def _set_tags_bytes(self, bytes):
 
1951
        self._ensure_real()
 
1952
        return self._real_branch._set_tags_bytes(bytes)
 
1953
 
1910
1954
    def _unlock(self, branch_token, repo_token):
1911
1955
        err_context = {'token': str((branch_token, repo_token))}
1912
1956
        response = self._call(
2150
2194
        self.set_revision_history(self._lefthand_history(revision_id,
2151
2195
            last_rev=last_rev,other_branch=other_branch))
2152
2196
 
2153
 
    @property
2154
 
    def tags(self):
2155
 
        self._ensure_real()
2156
 
        return self._real_branch.tags
2157
 
 
2158
2197
    def set_push_location(self, location):
2159
2198
        self._ensure_real()
2160
2199
        return self._real_branch.set_push_location(location)