/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: Andrew Bennetts
  • Date: 2008-03-27 06:10:18 UTC
  • mfrom: (3309 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3320.
  • Revision ID: andrew.bennetts@canonical.com-20080327061018-dxztpxyv6yoeg3am
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 
54
54
class SmartServerRequestFindRepository(SmartServerRequest):
55
55
 
56
 
    def do(self, path):
 
56
    def _boolean_to_yes_no(self, a_boolean):
 
57
        if a_boolean:
 
58
            return 'yes'
 
59
        else:
 
60
            return 'no'
 
61
 
 
62
    def _find(self, path):
57
63
        """try to find a repository from path upwards
58
64
        
59
65
        This operates precisely like 'bzrdir.find_repository'.
60
66
        
61
 
        If a bzrdir is not present, an exception is propogated
62
 
        rather than 'no branch' because these are different conditions.
63
 
 
64
 
        :return: norepository or ok, relpath.
 
67
        :return: (relpath, rich_root, tree_ref, external_lookup) flags. All are
 
68
            strings, relpath is a / prefixed path, and the other three are
 
69
            either 'yes' or 'no'.
 
70
        :raises errors.NoRepositoryPresent: When there is no repository
 
71
            present.
65
72
        """
66
73
        bzrdir = BzrDir.open_from_transport(
67
74
            self.transport_from_client_path(path))
68
 
        try:
69
 
            repository = bzrdir.find_repository()
70
 
            # the relpath of the bzrdir in the found repository gives us the 
71
 
            # path segments to pop-out.
72
 
            relpath = repository.bzrdir.root_transport.relpath(
73
 
                bzrdir.root_transport.base)
74
 
            if len(relpath):
75
 
                segments = ['..'] * len(relpath.split('/'))
76
 
            else:
77
 
                segments = []
78
 
            if repository.supports_rich_root():
79
 
                rich_root = 'yes'
80
 
            else:
81
 
                rich_root = 'no'
82
 
            if repository._format.supports_tree_reference:
83
 
                tree_ref = 'yes'
84
 
            else:
85
 
                tree_ref = 'no'
86
 
            return SuccessfulSmartServerResponse(('ok', '/'.join(segments), rich_root, tree_ref))
 
75
        repository = bzrdir.find_repository()
 
76
        # the relpath of the bzrdir in the found repository gives us the 
 
77
        # path segments to pop-out.
 
78
        relpath = repository.bzrdir.root_transport.relpath(
 
79
            bzrdir.root_transport.base)
 
80
        if len(relpath):
 
81
            segments = ['..'] * len(relpath.split('/'))
 
82
        else:
 
83
            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)
 
89
        return '/'.join(segments), rich_root, tree_ref, external_lookup
 
90
 
 
91
 
 
92
class SmartServerRequestFindRepositoryV1(SmartServerRequestFindRepository):
 
93
 
 
94
    def do(self, path):
 
95
        """try to find a repository from path upwards
 
96
        
 
97
        This operates precisely like 'bzrdir.find_repository'.
 
98
        
 
99
        If a bzrdir is not present, an exception is propogated
 
100
        rather than 'no branch' because these are different conditions.
 
101
 
 
102
        This is the initial version of this method introduced with the smart
 
103
        server. Modern clients will try the V2 method that adds support for the
 
104
        supports_external_lookups attribute.
 
105
 
 
106
        :return: norepository or ok, relpath.
 
107
        """
 
108
        try:
 
109
            path, rich_root, tree_ref, external_lookup = self._find(path)
 
110
            return SuccessfulSmartServerResponse(('ok', path, rich_root, tree_ref))
 
111
        except errors.NoRepositoryPresent:
 
112
            return FailedSmartServerResponse(('norepository', ))
 
113
 
 
114
 
 
115
class SmartServerRequestFindRepositoryV2(SmartServerRequestFindRepository):
 
116
 
 
117
    def do(self, path):
 
118
        """try to find a repository from path upwards
 
119
        
 
120
        This operates precisely like 'bzrdir.find_repository'.
 
121
        
 
122
        If a bzrdir is not present, an exception is propogated
 
123
        rather than 'no branch' because these are different conditions.
 
124
 
 
125
        This is the second edition of this method introduced in bzr 1.3, which
 
126
        returns information about the supports_external_lookups format
 
127
        attribute too.
 
128
 
 
129
        :return: norepository or ok, relpath.
 
130
        """
 
131
        try:
 
132
            path, rich_root, tree_ref, external_lookup = self._find(path)
 
133
            return SuccessfulSmartServerResponse(
 
134
                ('ok', path, rich_root, tree_ref, external_lookup))
87
135
        except errors.NoRepositoryPresent:
88
136
            return FailedSmartServerResponse(('norepository', ))
89
137