Merge lp:~jelmer/brz/prober-features 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/prober-features
Merge into: lp:brz
Diff against target: 249 lines (+65/-25)
9 files modified
breezy/bzr/__init__.py (+9/-1)
breezy/controldir.py (+21/-21)
breezy/git/__init__.py (+13/-1)
breezy/plugins/cvs/__init__.py (+4/-0)
breezy/plugins/darcs/__init__.py (+4/-0)
breezy/plugins/mtn/__init__.py (+4/-0)
breezy/tests/test_controldir.py (+4/-0)
breezy/tests/test_remote.py (+1/-2)
doc/en/release-notes/brz-3.1.txt (+5/-0)
To merge this branch: bzr merge lp:~jelmer/brz/prober-features
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+375187@code.launchpad.net

Commit message

Add an optional priority method for probers.

Description of the change

Add an optional priority method for probers.

This allows decreasing the priority of certain kinds of probers that we only
want to run as a last resort - e.g. probing for Monotone or CVS.

Use this to replace the previous register_server_prober() method, which
essentially helped provide two priorities.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bzr/__init__.py'
2--- breezy/bzr/__init__.py 2018-11-19 22:05:30 +0000
3+++ breezy/bzr/__init__.py 2019-11-06 01:42:18 +0000
4@@ -32,6 +32,10 @@
5 """The known .bzr formats."""
6
7 @classmethod
8+ def priority(klass, transport):
9+ return 10
10+
11+ @classmethod
12 def probe_transport(klass, transport):
13 """Return the .bzrdir style format present in a directory."""
14 try:
15@@ -69,6 +73,10 @@
16 """Prober for remote servers that provide a Bazaar smart server."""
17
18 @classmethod
19+ def priority(klass, transport):
20+ return -10
21+
22+ @classmethod
23 def probe_transport(klass, transport):
24 """Return a RemoteBzrDirFormat object if it looks possible."""
25 try:
26@@ -99,7 +107,7 @@
27 return [RemoteBzrDirFormat()]
28
29
30-controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
31+controldir.ControlDirFormat.register_prober(RemoteBzrProber)
32
33 # Register bzr formats
34 BzrProber.formats.register_lazy(
35
36=== modified file 'breezy/controldir.py'
37--- breezy/controldir.py 2019-06-27 00:17:42 +0000
38+++ breezy/controldir.py 2019-11-06 01:42:18 +0000
39@@ -1028,12 +1028,6 @@
40 _default_format = None
41 """The default format used for new control directories."""
42
43- _server_probers = []
44- """The registered server format probers, e.g. RemoteBzrProber.
45-
46- This is a list of Prober-derived classes.
47- """
48-
49 _probers = []
50 """The registered format probers, e.g. BzrProber.
51
52@@ -1124,24 +1118,13 @@
53 """
54 klass._probers.remove(prober)
55
56- @classmethod
57- def register_server_prober(klass, prober):
58- """Register a control format prober for client-server environments.
59-
60- These probers will be used before ones registered with
61- register_prober. This gives implementations that decide to the
62- chance to grab it before anything looks at the contents of the format
63- file.
64- """
65- klass._server_probers.append(prober)
66-
67 def __str__(self):
68 # Trim the newline
69 return self.get_format_description().rstrip()
70
71 @classmethod
72 def all_probers(klass):
73- return klass._server_probers + klass._probers
74+ return klass._probers
75
76 @classmethod
77 def known_formats(klass):
78@@ -1156,7 +1139,9 @@
79 def find_format(klass, transport, probers=None):
80 """Return the format present at transport."""
81 if probers is None:
82- probers = klass.all_probers()
83+ probers = sorted(
84+ klass.all_probers(),
85+ key=lambda prober: prober.priority(transport))
86 for prober_kls in probers:
87 prober = prober_kls()
88 try:
89@@ -1276,8 +1261,8 @@
90 probers that detect .bzr/ directories and Bazaar smart servers,
91 respectively.
92
93- Probers should be registered using the register_server_prober or
94- register_prober methods on ControlDirFormat.
95+ Probers should be registered using the register_prober methods on
96+ ControlDirFormat.
97 """
98
99 def probe_transport(self, transport):
100@@ -1301,6 +1286,21 @@
101 """
102 raise NotImplementedError(klass.known_formats)
103
104+ @classmethod
105+ def priority(klass, transport):
106+ """Priority of this prober.
107+
108+ A lower value means the prober gets checked first.
109+
110+ Other conventions:
111+
112+ -10: This is a "server" prober
113+ 0: No priority set
114+ 10: This is a regular file-based prober
115+ 100: This is a prober for an unsupported format
116+ """
117+ return 0
118+
119
120 class ControlDirFormatInfo(object):
121
122
123=== modified file 'breezy/git/__init__.py'
124--- breezy/git/__init__.py 2019-11-02 23:19:18 +0000
125+++ breezy/git/__init__.py 2019-11-06 01:42:18 +0000
126@@ -104,6 +104,10 @@
127
128 class LocalGitProber(Prober):
129
130+ @classmethod
131+ def priority(klass, transport):
132+ return 10
133+
134 def probe_transport(self, transport):
135 try:
136 external_url = transport.external_url()
137@@ -150,6 +154,14 @@
138
139 class RemoteGitProber(Prober):
140
141+ @classmethod
142+ def priority(klass, transport):
143+ # This is a surprisingly good heuristic to determine whether this
144+ # prober is more likely to succeed than the Bazaar one.
145+ if 'git' in transport.base:
146+ return -15
147+ return -10
148+
149 def probe_http_transport(self, transport):
150 # This function intentionally doesn't use any of the support code under
151 # breezy.git, since it's called for every repository that's
152@@ -221,7 +233,7 @@
153
154
155 ControlDirFormat.register_prober(LocalGitProber)
156-ControlDirFormat._server_probers.append(RemoteGitProber)
157+ControlDirFormat.register_prober(RemoteGitProber)
158
159 register_transport_proto(
160 'git://', help="Access using the Git smart server protocol.")
161
162=== modified file 'breezy/plugins/cvs/__init__.py'
163--- breezy/plugins/cvs/__init__.py 2018-11-11 04:08:32 +0000
164+++ breezy/plugins/cvs/__init__.py 2019-11-06 01:42:18 +0000
165@@ -67,6 +67,10 @@
166 class CVSProber(controldir.Prober):
167
168 @classmethod
169+ def priority(klass, transport):
170+ return 100
171+
172+ @classmethod
173 def probe_transport(klass, transport):
174 # little ugly, but works
175 # try a manual probe first, its a little faster perhaps ?
176
177=== modified file 'breezy/plugins/darcs/__init__.py'
178--- breezy/plugins/darcs/__init__.py 2019-10-13 16:49:05 +0000
179+++ breezy/plugins/darcs/__init__.py 2019-11-06 01:42:18 +0000
180@@ -74,6 +74,10 @@
181 class DarcsProber(controldir.Prober):
182
183 @classmethod
184+ def priority(klass, transport):
185+ return 100
186+
187+ @classmethod
188 def probe_transport(klass, transport):
189 if transport.has('_darcs'):
190 return DarcsDirFormat()
191
192=== modified file 'breezy/plugins/mtn/__init__.py'
193--- breezy/plugins/mtn/__init__.py 2018-11-11 04:08:32 +0000
194+++ breezy/plugins/mtn/__init__.py 2019-11-06 01:42:18 +0000
195@@ -67,6 +67,10 @@
196 class MonotoneProber(controldir.Prober):
197
198 @classmethod
199+ def priority(klass, transport):
200+ return 100
201+
202+ @classmethod
203 def probe_transport(klass, transport):
204 """Our format is present if the transport has a '_MTN/' subdir."""
205 if transport.has('_MTN'):
206
207=== modified file 'breezy/tests/test_controldir.py'
208--- breezy/tests/test_controldir.py 2019-06-03 21:45:21 +0000
209+++ breezy/tests/test_controldir.py 2019-11-06 01:42:18 +0000
210@@ -104,6 +104,10 @@
211 super(TestProber, self).setUp()
212 self.prober = self.prober_cls()
213
214+ def test_priority(self):
215+ transport = self.get_transport(".")
216+ self.assertIsInstance(self.prober.priority(transport), int)
217+
218 def test_probe_transport_empty(self):
219 transport = self.get_transport(".")
220 self.assertRaises(errors.NotBranchError,
221
222=== modified file 'breezy/tests/test_remote.py'
223--- breezy/tests/test_remote.py 2019-06-01 02:04:54 +0000
224+++ breezy/tests/test_remote.py 2019-11-06 01:42:18 +0000
225@@ -133,8 +133,7 @@
226 def test_find_correct_format(self):
227 """Should open a RemoteBzrDir over a RemoteTransport"""
228 fmt = BzrDirFormat.find_format(self.transport)
229- self.assertTrue(RemoteBzrProber
230- in controldir.ControlDirFormat._server_probers)
231+ self.assertIn(RemoteBzrProber, controldir.ControlDirFormat._probers)
232 self.assertIsInstance(fmt, RemoteBzrDirFormat)
233
234 def test_open_detected_smart_format(self):
235
236=== modified file 'doc/en/release-notes/brz-3.1.txt'
237--- doc/en/release-notes/brz-3.1.txt 2019-11-02 23:19:18 +0000
238+++ doc/en/release-notes/brz-3.1.txt 2019-11-06 01:42:18 +0000
239@@ -128,6 +128,11 @@
240 * New ``Tree.get_nested_tree`` method for retrieving a nested tree.
241 (Jelmer Vernooij)
242
243+* The ``ControlDirFormat.register_server_prober`` method has been removed.
244+ Instead, probers can now have a ``priority`` method to influence
245+ when they are run. (Jelmer Vernooij)
246+
247+
248 Internals
249 *********
250

Subscribers

People subscribed via source and target branches