~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/bzrdir.py

  • Committer: Andrew Bennetts
  • Date: 2008-03-12 20:13:07 UTC
  • mfrom: (3267 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080312201307-ngd5bynt2nvhnlb7
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

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