~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Robert Collins
  • Date: 2009-02-13 00:52:18 UTC
  • mto: This revision was merged to the branch mainline in revision 4012.
  • Revision ID: robertc@robertcollins.net-20090213005218-yxrgiq7j1du2vldm
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
    do_catching_redirections,
65
65
    get_transport,
66
66
    local,
 
67
    remote as remote_transport,
67
68
    )
68
69
from bzrlib.weave import Weave
69
70
""")
1736
1737
                    mode=file_mode)
1737
1738
        finally:
1738
1739
            control_files.unlock()
1739
 
        return self.open(transport, _found=True)
 
1740
        # If we initialized using VFS methods on a RemoteTransport, return a
 
1741
        # Remote object: No need for it to be slower than necessary.
 
1742
        if isinstance(transport, remote_transport.RemoteTransport):
 
1743
            return self.open(transport)
 
1744
        else:
 
1745
            return self.open(transport, _found=True)
1740
1746
 
1741
1747
    def is_supported(self):
1742
1748
        """Is this format supported?
1781
1787
                raise AssertionError("%s was asked to open %s, but it seems to need "
1782
1788
                        "format %s" 
1783
1789
                        % (self, transport, found_format))
 
1790
            # Allow subclasses - use the found format.
 
1791
            self._supply_sub_formats_to(found_format)
 
1792
            return found_format._open(transport)
1784
1793
        return self._open(transport)
1785
1794
 
1786
1795
    def _open(self, transport):
1826
1835
        # Trim the newline
1827
1836
        return self.get_format_string().rstrip()
1828
1837
 
 
1838
    def _supply_sub_formats_to(self, other_format):
 
1839
        """Give other_format the same values for sub formats as this has.
 
1840
 
 
1841
        This method is expected to be used when parameterising a
 
1842
        RemoteBzrDirFormat instance with the parameters from a
 
1843
        BzrDirMetaFormat1 instance.
 
1844
 
 
1845
        :param other_format: other_format is a format which should be
 
1846
            compatible with whatever sub formats are supported by self.
 
1847
        :return: None.
 
1848
        """
 
1849
 
1829
1850
    @classmethod
1830
1851
    def unregister_format(klass, format):
1831
1852
        del klass._formats[format.get_format_string()]
2088
2109
        from bzrlib.repository import RepositoryFormat
2089
2110
        return RepositoryFormat.get_default_format()
2090
2111
 
2091
 
    def __set_repository_format(self, value):
 
2112
    def _set_repository_format(self, value):
2092
2113
        """Allow changing the repository format for metadir formats."""
2093
2114
        self._repository_format = value
2094
2115
 
2095
 
    repository_format = property(__return_repository_format, __set_repository_format)
 
2116
    repository_format = property(__return_repository_format,
 
2117
        _set_repository_format)
 
2118
 
 
2119
    def _supply_sub_formats_to(self, other_format):
 
2120
        """Give other_format the same values for sub formats as this has.
 
2121
 
 
2122
        This method is expected to be used when parameterising a
 
2123
        RemoteBzrDirFormat instance with the parameters from a
 
2124
        BzrDirMetaFormat1 instance.
 
2125
 
 
2126
        :param other_format: other_format is a format which should be
 
2127
            compatible with whatever sub formats are supported by self.
 
2128
        :return: None.
 
2129
        """
 
2130
        if getattr(self, '_repository_format', None) is not None:
 
2131
            other_format.repository_format = self.repository_format
 
2132
        if self._branch_format is not None:
 
2133
            other_format._branch_format = self._branch_format
 
2134
        if self._workingtree_format is not None:
 
2135
            other_format.workingtree_format = self.workingtree_format
2096
2136
 
2097
2137
    def __get_workingtree_format(self):
2098
2138
        if self._workingtree_format is None:
2679
2719
        response = client.call('BzrDirFormat.initialize', path)
2680
2720
        if response[0] != 'ok':
2681
2721
            raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2682
 
        return remote.RemoteBzrDir(transport)
 
2722
        return remote.RemoteBzrDir(transport, self)
2683
2723
 
2684
2724
    def _open(self, transport):
2685
 
        return remote.RemoteBzrDir(transport)
 
2725
        return remote.RemoteBzrDir(transport, self)
2686
2726
 
2687
2727
    def __eq__(self, other):
2688
2728
        if not isinstance(other, RemoteBzrDirFormat):
2689
2729
            return False
2690
2730
        return self.get_format_description() == other.get_format_description()
2691
2731
 
2692
 
    @property
2693
 
    def repository_format(self):
2694
 
        # Using a property to avoid early loading of remote
2695
 
        return remote.RemoteRepositoryFormat()
 
2732
    def __return_repository_format(self):
 
2733
        # Always return a RemoteRepositoryFormat object, but if a specific bzr
 
2734
        # repository format has been asked for, tell the RemoteRepositoryFormat
 
2735
        # that it should use that for init() etc.
 
2736
        result =  remote.RemoteRepositoryFormat()
 
2737
        custom_format = getattr(self, '_repository_format', None)
 
2738
        if custom_format:
 
2739
            # We will use the custom format to create repositories over the
 
2740
            # wire; expose its details like rich_root_data for code to query
 
2741
            result._custom_format = custom_format
 
2742
            result.rich_root_data = custom_format.rich_root_data
 
2743
        return result
 
2744
 
 
2745
    repository_format = property(__return_repository_format,
 
2746
        BzrDirMetaFormat1._set_repository_format) #.im_func)
2696
2747
 
2697
2748
 
2698
2749
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)