/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-02-09 02:59:15 UTC
  • mto: This revision was merged to the branch mainline in revision 7286.
  • Revision ID: jelmer@jelmer.uk-20190209025915-dckbtruqe0zrd3dq
Add purpose argument.

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 ('push', 'pull' 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
        return service().look_up(name, url, purpose=purpose)
87
88
 
88
89
 
89
90
directories = DirectoryServiceRegistry()
90
91
 
91
92
 
92
 
class AliasDirectory(object):
 
93
class Directory(object):
 
94
    """Abstract directory lookup class."""
 
95
 
 
96
    def look_up(self, name, url, purpose=None):
 
97
        """Look up an entry in a directory.
 
98
 
 
99
        :param name: Directory name
 
100
        :param url: The URL to dereference
 
101
        :param purpose: Purpose of the URL ('push', 'pull' or None - if not declared)
 
102
        :return: The dereferenced URL if applicable, the input URL otherwise.
 
103
        """
 
104
        raise NotImplementedError(self.look_up)
 
105
 
 
106
 
 
107
class AliasDirectory(Directory):
93
108
    """Directory lookup for locations associated with a branch.
94
109
 
95
110
    :parent, :submit, :public, :push, :this, and :bound are currently
110
125
    branch_aliases.register('this', lambda b: b.base,
111
126
                            help="This branch.")
112
127
 
113
 
    def look_up(self, name, url):
 
128
    def look_up(self, name, url, purpose=None):
114
129
        branch = _mod_branch.Branch.open_containing('.')[0]
115
130
        parts = url.split('/', 1)
116
131
        if len(parts) == 2:
156
171
                     'Easy access to remembered branch locations')
157
172
 
158
173
 
159
 
class ColocatedDirectory(object):
 
174
class ColocatedDirectory(Directory):
160
175
    """Directory lookup for colocated branches.
161
176
 
162
177
    co:somename will resolve to the colocated branch with "somename" in
163
178
    the current directory.
164
179
    """
165
180
 
166
 
    def look_up(self, name, url):
 
181
    def look_up(self, name, url, purpose=None):
167
182
        dir = _mod_controldir.ControlDir.open_containing('.')[0]
168
183
        return urlutils.join_segment_parameters(dir.user_url,
169
184
                                                {"branch": urlutils.escape(name)})