67
67
name and URL, and return a URL.
70
def dereference(self, url):
70
def dereference(self, url, purpose=None):
71
71
"""Dereference a supplied URL if possible.
73
73
URLs that match a registered directory service prefix are looked up in
77
77
requires further dereferencing.
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.
82
83
match = self.get_prefix(url)
85
86
service, name = match
86
return service().look_up(name, url)
89
return directory.look_up(name, url, purpose=purpose)
91
# Compatibility for plugins written for Breezy < 3.0.0
92
return directory.look_up(name, url)
89
95
directories = DirectoryServiceRegistry()
92
class AliasDirectory(object):
98
class Directory(object):
99
"""Abstract directory lookup class."""
101
def look_up(self, name, url, purpose=None):
102
"""Look up an entry in a directory.
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.
109
raise NotImplementedError(self.look_up)
112
class AliasDirectory(Directory):
93
113
"""Directory lookup for locations associated with a branch.
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.")
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')
159
class ColocatedDirectory(object):
179
class ColocatedDirectory(Directory):
160
180
"""Directory lookup for colocated branches.
162
182
co:somename will resolve to the colocated branch with "somename" in
163
183
the current directory.
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
188
return urlutils.join_segment_parameters(
169
189
dir.user_url, {"branch": urlutils.escape(name)})