Merge lp:~jelmer/brz/fix-redirects into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/fix-redirects
Merge into: lp:brz
Diff against target: 112 lines (+25/-16)
2 files modified
breezy/transport/__init__.py (+20/-14)
breezy/transport/http/__init__.py (+5/-2)
To merge this branch: bzr merge lp:~jelmer/brz/fix-redirects
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+373052@code.launchpad.net

Commit message

Raise an informational message when unable to interpret redirect.

Description of the change

Raise an informational message when unable to interpret redirect.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/transport/__init__.py'
2--- breezy/transport/__init__.py 2019-02-09 03:23:20 +0000
3+++ breezy/transport/__init__.py 2019-09-21 14:46:19 +0000
4@@ -31,19 +31,8 @@
5 import errno
6 import sys
7
8-from ..lazy_import import lazy_import
9-lazy_import(globals(), """
10 from stat import S_ISDIR
11
12-from breezy import (
13- errors,
14- location as _mod_location,
15- osutils,
16- ui,
17- urlutils,
18- )
19-""")
20-
21 from ..sixish import (
22 BytesIO,
23 PY3,
24@@ -53,8 +42,12 @@
25 mutter,
26 )
27 from .. import (
28+ errors,
29 hooks,
30 registry,
31+ osutils,
32+ ui,
33+ urlutils,
34 )
35
36
37@@ -96,6 +89,16 @@
38 return result
39
40
41+class UnusableRedirect(errors.BzrError):
42+
43+ _fmt = ("Unable to follow redirect from %(source)s to %(target)s: "
44+ "%(reason)s.")
45+
46+ def __init__(self, source, target, reason):
47+ super(UnusableRedirect, self).__init__(
48+ source=source, target=target, reason=reason)
49+
50+
51 class TransportListRegistry(registry.Registry):
52 """A registry which simplifies tracking available Transports.
53
54@@ -1235,11 +1238,13 @@
55 The redirection can be handled only if the relpath involved is not
56 renamed by the redirection.
57
58- :returns: A transport or None.
59+ :returns: A transport
60+ :raise UnusableRedirect: when redirection can not be provided
61 """
62 # This returns None by default, meaning the transport can't handle the
63 # redirection.
64- return None
65+ raise UnusableRedirect(
66+ source, target, "transport does not support redirection")
67
68
69 class _SharedConnection(object):
70@@ -1569,8 +1574,9 @@
71 """
72 if base is None:
73 base = '.'
74+ from ..location import location_to_url
75 return get_transport_from_url(
76- _mod_location.location_to_url(base, purpose=purpose),
77+ location_to_url(base, purpose=purpose),
78 possible_transports)
79
80
81
82=== modified file 'breezy/transport/http/__init__.py'
83--- breezy/transport/http/__init__.py 2019-08-11 16:27:38 +0000
84+++ breezy/transport/http/__init__.py 2019-09-21 14:46:19 +0000
85@@ -81,6 +81,7 @@
86 from ...trace import mutter
87 from ...transport import (
88 ConnectedTransport,
89+ UnusableRedirect,
90 )
91
92
93@@ -2500,7 +2501,8 @@
94 The redirection can be handled only if the relpath involved is not
95 renamed by the redirection.
96
97- :returns: A transport or None.
98+ :returns: A transport
99+ :raise UnusableRedirect: when the URL can not be reinterpreted
100 """
101 parsed_source = self._split_url(source)
102 parsed_target = self._split_url(target)
103@@ -2511,7 +2513,8 @@
104 if not parsed_target.path.endswith(excess_tail):
105 # The final part of the url has been renamed, we can't handle the
106 # redirection.
107- return None
108+ raise UnusableRedirect(
109+ source, target, "final part of the url was renamed")
110
111 target_path = parsed_target.path
112 if excess_tail:

Subscribers

People subscribed via source and target branches