254
248
def transform_fallback_locationHook(cls, branch, url):
255
249
"""Installed as the 'transform_fallback_location' Branch hook.
257
This method calls `transform_fallback_location` on the policy object
258
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
259
253
check_and_follow_branch_reference.
282
276
# spurious loop exceptions.
283
277
self._seen_urls = set()
285
def _open_dir(self, url):
286
"""Simple BzrDir.open clone that only uses specific probers.
288
:param url: URL to open
289
:return: ControlDir instance
291
def redirected(transport, e, redirection_notice):
292
self.policy.check_one_url(e.target)
293
redirected_transport = transport._redirected_to(
295
if redirected_transport is None:
296
raise errors.NotBranchError(e.source)
298
'%s is%s redirected to %s',
299
transport.base, e.permanently, redirected_transport.base)
300
return redirected_transport
302
def find_format(transport):
303
last_error = errors.NotBranchError(transport.base)
304
for prober_kls in self.probers:
305
prober = prober_kls()
307
return transport, prober.probe_transport(transport)
308
except errors.NotBranchError as e:
312
transport = get_transport(url)
313
transport, format = do_catching_redirections(
314
find_format, transport, redirected)
315
return format.open(transport)
317
279
def follow_reference(self, url):
318
280
"""Get the branch-reference value at the specified url.
320
282
This exists as a separate method only to be overriden in unit tests.
322
controldir = self._open_dir(url)
284
controldir = ControlDir.open(url, probers=self.probers)
323
285
return controldir.get_branch_reference()
325
def open(self, url, ignore_fallbacks=False):
326
288
"""Open the Bazaar branch at url, first checking it.
328
What is acceptable means is defined by the policy's `follow_reference`
329
and `check_one_url` methods.
290
What is acceptable means is defined by the policy's `follow_reference` and
291
`check_one_url` methods.
331
293
if not isinstance(url, str):
334
296
url = self.check_and_follow_branch_reference(url)
336
def open_branch(url, ignore_fallbacks):
337
dir = self._open_dir(url)
338
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()
339
301
return self.run_with_transform_fallback_location_hook_installed(
340
open_branch, url, ignore_fallbacks)
343
305
def open_only_scheme(allowed_scheme, url):