/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/smart/bzrdir.py

  • Committer: Robert Collins
  • Date: 2009-02-19 07:28:37 UTC
  • mto: This revision was merged to the branch mainline in revision 4023.
  • Revision ID: robertc@robertcollins.net-20090219072837-vznmfrq7lz1grtti
Reduce the number of round trips required to create a repository over the network.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    SmartServerRequest,
25
25
    SuccessfulSmartServerResponse,
26
26
    )
 
27
from bzrlib.repository import network_format_registry
27
28
 
28
29
 
29
30
class SmartServerRequestOpenBzrDir(SmartServerRequest):
51
52
        return SuccessfulSmartServerResponse((answer,))
52
53
 
53
54
 
54
 
class SmartServerRequestFindRepository(SmartServerRequest):
 
55
class SmartServerRequestBzrDir(SmartServerRequest):
55
56
 
56
57
    def _boolean_to_yes_no(self, a_boolean):
57
58
        if a_boolean:
59
60
        else:
60
61
            return 'no'
61
62
 
 
63
    def _format_to_capabilities(self, repo_format):
 
64
        rich_root = self._boolean_to_yes_no(repo_format.rich_root_data)
 
65
        tree_ref = self._boolean_to_yes_no(
 
66
            repo_format.supports_tree_reference)
 
67
        external_lookup = self._boolean_to_yes_no(
 
68
            repo_format.supports_external_lookups)
 
69
        return rich_root, tree_ref, external_lookup
 
70
 
 
71
 
 
72
class SmartServerRequestCreateRepository(SmartServerRequestBzrDir):
 
73
 
 
74
    def do(self, path, network_name, shared):
 
75
        """Create a repository in the bzr dir at path.
 
76
        
 
77
        This operates precisely like 'bzrdir.create_repository'.
 
78
        
 
79
        If a bzrdir is not present, an exception is propogated
 
80
        rather than 'no branch' because these are different conditions (and
 
81
        this method should only be called after establishing that a bzr dir
 
82
        exists anyway).
 
83
 
 
84
        This is the initial version of this method introduced to the smart
 
85
        server for 1.13.
 
86
 
 
87
        :param path: The path to the bzrdir.
 
88
        :param network_name: The network name of the repository type to create.
 
89
        :param shared: The value to pass create_repository for the shared
 
90
            parameter.
 
91
        :return: (ok, rich_root, tree_ref, external_lookup, network_name)
 
92
        """
 
93
        bzrdir = BzrDir.open_from_transport(
 
94
            self.transport_from_client_path(path))
 
95
        shared = shared == 'True'
 
96
        format = network_format_registry.get(network_name)
 
97
        bzrdir.repository_format = format
 
98
        result = format.initialize(bzrdir, shared=shared)
 
99
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
 
100
            result._format)
 
101
        return SuccessfulSmartServerResponse(('ok', rich_root, tree_ref,
 
102
            external_lookup, result._format.network_name()))
 
103
 
 
104
 
 
105
class SmartServerRequestFindRepository(SmartServerRequestBzrDir):
 
106
 
62
107
    def _find(self, path):
63
108
        """try to find a repository from path upwards
64
109
        
81
126
            segments = ['..'] * len(relpath.split('/'))
82
127
        else:
83
128
            segments = []
84
 
        rich_root = self._boolean_to_yes_no(repository.supports_rich_root())
85
 
        tree_ref = self._boolean_to_yes_no(
86
 
            repository._format.supports_tree_reference)
87
 
        external_lookup = self._boolean_to_yes_no(
88
 
            repository._format.supports_external_lookups)
 
129
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
 
130
            repository._format)
89
131
        return '/'.join(segments), rich_root, tree_ref, external_lookup
90
132
 
91
133