/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 breezy/directory_service.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 05:10:44 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7294.
  • Revision ID: jelmer@jelmer.uk-20190304051044-vph4s8p9qvpy2qe9
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
    name and URL, and return a URL.
68
68
    """
69
69
 
70
 
    def dereference(self, url):
 
70
    def dereference(self, url, purpose=None):
71
71
        """Dereference a supplied URL if possible.
72
72
 
73
73
        URLs that match a registered directory service prefix are looked up in
77
77
        requires further dereferencing.
78
78
 
79
79
        :param url: The URL to dereference
 
80
        :param purpose: Purpose of the URL ('read', 'write' or None - if not declared)
80
81
        :return: The dereferenced URL if applicable, the input URL otherwise.
81
82
        """
82
83
        match = self.get_prefix(url)
83
84
        if match is None:
84
85
            return url
85
86
        service, name = match
86
 
        return service().look_up(name, url)
 
87
        directory = service()
 
88
        try:
 
89
            return directory.look_up(name, url, purpose=purpose)
 
90
        except TypeError:
 
91
            # Compatibility for plugins written for Breezy < 3.0.0
 
92
            return directory.look_up(name, url)
87
93
 
88
94
 
89
95
directories = DirectoryServiceRegistry()
90
96
 
91
97
 
92
 
class AliasDirectory(object):
 
98
class Directory(object):
 
99
    """Abstract directory lookup class."""
 
100
 
 
101
    def look_up(self, name, url, purpose=None):
 
102
        """Look up an entry in a directory.
 
103
 
 
104
        :param name: Directory name
 
105
        :param url: The URL to dereference
 
106
        :param purpose: Purpose of the URL ('read', 'write' or None - if not declared)
 
107
        :return: The dereferenced URL if applicable, the input URL otherwise.
 
108
        """
 
109
        raise NotImplementedError(self.look_up)
 
110
 
 
111
 
 
112
class AliasDirectory(Directory):
93
113
    """Directory lookup for locations associated with a branch.
94
114
 
95
115
    :parent, :submit, :public, :push, :this, and :bound are currently
110
130
    branch_aliases.register('this', lambda b: b.base,
111
131
                            help="This branch.")
112
132
 
113
 
    def look_up(self, name, url):
 
133
    def look_up(self, name, url, purpose=None):
114
134
        branch = _mod_branch.Branch.open_containing('.')[0]
115
135
        parts = url.split('/', 1)
116
136
        if len(parts) == 2:
156
176
                     'Easy access to remembered branch locations')
157
177
 
158
178
 
159
 
class ColocatedDirectory(object):
 
179
class ColocatedDirectory(Directory):
160
180
    """Directory lookup for colocated branches.
161
181
 
162
182
    co:somename will resolve to the colocated branch with "somename" in
163
183
    the current directory.
164
184
    """
165
185
 
166
 
    def look_up(self, name, url):
 
186
    def look_up(self, name, url, purpose=None):
167
187
        dir = _mod_controldir.ControlDir.open_containing('.')[0]
168
 
        return urlutils.join_segment_parameters(dir.user_url,
169
 
                                                {"branch": urlutils.escape(name)})
 
188
        return urlutils.join_segment_parameters(
 
189
            dir.user_url, {"branch": urlutils.escape(name)})
170
190
 
171
191
 
172
192
directories.register('co:', ColocatedDirectory,