256
248
def transform_fallback_locationHook(cls, branch, url):
257
249
"""Installed as the 'transform_fallback_location' Branch hook.
259
This method calls `transform_fallback_location` on the policy object
260
and either returns the url it provides or passes it back to
251
This method calls `transform_fallback_location` on the policy object and
252
either returns the url it provides or passes it back to
261
253
check_and_follow_branch_reference.
284
276
# spurious loop exceptions.
285
277
self._seen_urls = set()
287
def _open_dir(self, url):
288
"""Simple BzrDir.open clone that only uses specific probers.
290
:param url: URL to open
291
:return: ControlDir instance
293
def redirected(transport, e, redirection_notice):
294
self.policy.check_one_url(e.target)
295
redirected_transport = transport._redirected_to(
297
if redirected_transport is None:
298
raise errors.NotBranchError(e.source)
300
'%s is%s redirected to %s',
301
transport.base, e.permanently, redirected_transport.base)
302
return redirected_transport
304
def find_format(transport):
305
last_error = errors.NotBranchError(transport.base)
306
for prober_kls in self.probers:
307
prober = prober_kls()
309
return transport, prober.probe_transport(transport)
310
except errors.NotBranchError as e:
314
transport = get_transport(url)
315
transport, format = do_catching_redirections(
316
find_format, transport, redirected)
317
return format.open(transport)
319
279
def follow_reference(self, url):
320
280
"""Get the branch-reference value at the specified url.
322
282
This exists as a separate method only to be overriden in unit tests.
324
controldir = self._open_dir(url)
284
controldir = ControlDir.open(url, probers=self.probers)
325
285
return controldir.get_branch_reference()
327
def open(self, url, ignore_fallbacks=False):
328
288
"""Open the Bazaar branch at url, first checking it.
330
What is acceptable means is defined by the policy's `follow_reference`
331
and `check_one_url` methods.
290
What is acceptable means is defined by the policy's `follow_reference` and
291
`check_one_url` methods.
333
293
if not isinstance(url, str):
336
296
url = self.check_and_follow_branch_reference(url)
338
def open_branch(url, ignore_fallbacks):
339
dir = self._open_dir(url)
340
return dir.open_branch(ignore_fallbacks=ignore_fallbacks)
298
def open_branch(url):
299
dir = ControlDir.open(url, probers=self.probers)
300
return dir.open_branch()
341
301
return self.run_with_transform_fallback_location_hook_installed(
342
open_branch, url, ignore_fallbacks)
345
305
def open_only_scheme(allowed_scheme, url):