Status: | Needs review |
---|---|
Proposed branch: | lp:~jelmer/brz/pending |
Merge into: | lp:brz |
Prerequisite: | lp:~jelmer/brz/python3.7 |
Diff against target: |
736 lines (+136/-162) 16 files modified
breezy/bzr/bzrdir.py (+43/-72) breezy/bzr/remote.py (+0/-4) breezy/controldir.py (+24/-7) breezy/errors.py (+0/-5) breezy/git/dir.py (+0/-3) breezy/plugins/cvs/__init__.py (+0/-3) breezy/plugins/darcs/__init__.py (+0/-3) breezy/plugins/mtn/__init__.py (+0/-3) breezy/plugins/weave_fmt/bzrdir.py (+35/-21) breezy/plugins/weave_fmt/test_bzrdir.py (+0/-10) breezy/tests/blackbox/test_upgrade.py (+7/-5) breezy/tests/per_controldir/test_controldir.py (+7/-9) breezy/tests/test_bzrdir.py (+5/-5) breezy/tests/test_upgrade.py (+7/-7) breezy/upgrade.py (+7/-5) tools/prepare_for_latex.py (+1/-0) |
To merge this branch: | bzr merge lp:~jelmer/brz/pending |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Packman | Approve | ||
Review via email: mp+359654@code.launchpad.net |
Commit message
Add registration for Converter objects.
Description of the change
Add registration for Converter objects.
To post a comment you must log in.
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Running landing tests failed
https:/
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Merging failed
https:/
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Running landing tests failed
https:/
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Running landing tests failed
https:/
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Merging failed
https:/
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Merging failed
https:/
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Merging failed
https:/
Unmerged revisions
- 7221. By Jelmer Vernooij
-
Merge trunk.
- 7220. By Jelmer Vernooij
-
Merge trunk.
- 7219. By Jelmer Vernooij
-
Add registration for Converter objects.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'breezy/bzr/bzrdir.py' |
2 | --- breezy/bzr/bzrdir.py 2018-11-18 19:48:57 +0000 |
3 | +++ breezy/bzr/bzrdir.py 2019-02-04 13:47:49 +0000 |
4 | @@ -869,10 +869,6 @@ |
5 | self.control_transport, self._format._lock_file_name, |
6 | self._format._lock_class) |
7 | |
8 | - def can_convert_format(self): |
9 | - """See BzrDir.can_convert_format().""" |
10 | - return True |
11 | - |
12 | def create_branch(self, name=None, repository=None, |
13 | append_revisions_only=None): |
14 | """See ControlDir.create_branch.""" |
15 | @@ -1612,21 +1608,6 @@ |
16 | ' using format:\n %s'), |
17 | new_branch_format.get_format_description()) |
18 | |
19 | - def get_converter(self, format=None): |
20 | - """See BzrDirFormat.get_converter().""" |
21 | - if format is None: |
22 | - format = BzrDirFormat.get_default_format() |
23 | - if (isinstance(self, BzrDirMetaFormat1) |
24 | - and isinstance(format, BzrDirMetaFormat1Colo)): |
25 | - return ConvertMetaToColo(format) |
26 | - if (isinstance(self, BzrDirMetaFormat1Colo) |
27 | - and isinstance(format, BzrDirMetaFormat1)): |
28 | - return ConvertMetaToColo(format) |
29 | - if not isinstance(self, format.__class__): |
30 | - # converting away from metadir is not implemented |
31 | - raise NotImplementedError(self.get_converter) |
32 | - return ConvertMetaToMeta(format) |
33 | - |
34 | @classmethod |
35 | def get_format_string(cls): |
36 | """See BzrDirFormat.get_format_string().""" |
37 | @@ -1720,29 +1701,27 @@ |
38 | return BzrDirMeta1(transport, format) |
39 | |
40 | |
41 | -class ConvertMetaToMeta(controldir.Converter): |
42 | +class ConvertMetaContents(controldir.Converter): |
43 | """Converts the components of metadirs.""" |
44 | |
45 | - def __init__(self, target_format): |
46 | - """Create a metadir to metadir converter. |
47 | - |
48 | - :param target_format: The final metadir format that is desired. |
49 | - """ |
50 | - self.target_format = target_format |
51 | - |
52 | - def convert(self, to_convert, pb): |
53 | + @classmethod |
54 | + def is_compatible(cls, source_format, target_format): |
55 | + return (isinstance(source_format, BzrDirMetaFormat1) and |
56 | + isinstance(target_format, BzrDirMetaFormat1) and |
57 | + source_format.get_format_string() == target_format.get_format_string()) |
58 | + |
59 | + def convert(self, to_convert, target_format, pb): |
60 | """See Converter.convert().""" |
61 | - self.controldir = to_convert |
62 | self.pb = ui.ui_factory.nested_progress_bar() |
63 | self.count = 0 |
64 | self.total = 1 |
65 | self.step('checking repository format') |
66 | try: |
67 | - repo = self.controldir.open_repository() |
68 | + repo = to_convert.open_repository() |
69 | except errors.NoRepositoryPresent: |
70 | pass |
71 | else: |
72 | - repo_fmt = self.target_format.repository_format |
73 | + repo_fmt = target_format.repository_format |
74 | if not isinstance(repo._format, repo_fmt.__class__): |
75 | from ..repository import CopyConverter |
76 | ui.ui_factory.note(gettext('starting repository conversion')) |
77 | @@ -1750,14 +1729,14 @@ |
78 | raise AssertionError( |
79 | "Repository in metadir does not support " |
80 | "overriding transport") |
81 | - converter = CopyConverter(self.target_format.repository_format) |
82 | + converter = CopyConverter(target_format.repository_format) |
83 | converter.convert(repo, pb) |
84 | - for branch in self.controldir.list_branches(): |
85 | + for branch in to_convert.list_branches(): |
86 | # TODO: conversions of Branch and Tree should be done by |
87 | # InterXFormat lookups/some sort of registry. |
88 | # Avoid circular imports |
89 | old = branch._format.__class__ |
90 | - new = self.target_format.get_branch_format().__class__ |
91 | + new = target_format.get_branch_format().__class__ |
92 | while old != new: |
93 | if (old == fullhistorybranch.BzrBranchFormat5 |
94 | and new in (_mod_bzrbranch.BzrBranchFormat6, |
95 | @@ -1775,10 +1754,10 @@ |
96 | raise errors.BadConversionTarget("No converter", new, |
97 | branch._format) |
98 | branch_converter.convert(branch) |
99 | - branch = self.controldir.open_branch() |
100 | + branch = to_convert.open_branch() |
101 | old = branch._format.__class__ |
102 | try: |
103 | - tree = self.controldir.open_workingtree(recommend_upgrade=False) |
104 | + tree = to_convert.open_workingtree(recommend_upgrade=False) |
105 | except (errors.NoWorkingTree, errors.NotLocalUrl): |
106 | pass |
107 | else: |
108 | @@ -1786,56 +1765,48 @@ |
109 | # InterXFormat lookups |
110 | if (isinstance(tree, workingtree_3.WorkingTree3) |
111 | and not isinstance(tree, workingtree_4.DirStateWorkingTree) |
112 | - and isinstance(self.target_format.workingtree_format, |
113 | + and isinstance(target_format.workingtree_format, |
114 | workingtree_4.DirStateWorkingTreeFormat)): |
115 | workingtree_4.Converter3to4().convert(tree) |
116 | if (isinstance(tree, workingtree_4.DirStateWorkingTree) |
117 | and not isinstance(tree, workingtree_4.WorkingTree5) |
118 | - and isinstance(self.target_format.workingtree_format, |
119 | + and isinstance(target_format.workingtree_format, |
120 | workingtree_4.WorkingTreeFormat5)): |
121 | workingtree_4.Converter4to5().convert(tree) |
122 | if (isinstance(tree, workingtree_4.DirStateWorkingTree) |
123 | and not isinstance(tree, workingtree_4.WorkingTree6) |
124 | - and isinstance(self.target_format.workingtree_format, |
125 | + and isinstance(target_format.workingtree_format, |
126 | workingtree_4.WorkingTreeFormat6)): |
127 | workingtree_4.Converter4or5to6().convert(tree) |
128 | self.pb.finished() |
129 | return to_convert |
130 | |
131 | |
132 | -class ConvertMetaToColo(controldir.Converter): |
133 | - """Add colocated branch support.""" |
134 | - |
135 | - def __init__(self, target_format): |
136 | - """Create a converter.that upgrades a metadir to the colo format. |
137 | - |
138 | - :param target_format: The final metadir format that is desired. |
139 | - """ |
140 | - self.target_format = target_format |
141 | - |
142 | - def convert(self, to_convert, pb): |
143 | - """See Converter.convert().""" |
144 | - to_convert.transport.put_bytes('branch-format', |
145 | - self.target_format.as_string()) |
146 | - return BzrDir.open_from_transport(to_convert.root_transport) |
147 | - |
148 | - |
149 | -class ConvertMetaToColo(controldir.Converter): |
150 | - """Convert a 'development-colo' bzrdir to a '2a' bzrdir.""" |
151 | - |
152 | - def __init__(self, target_format): |
153 | - """Create a converter that converts a 'development-colo' metadir |
154 | - to a '2a' metadir. |
155 | - |
156 | - :param target_format: The final metadir format that is desired. |
157 | - """ |
158 | - self.target_format = target_format |
159 | - |
160 | - def convert(self, to_convert, pb): |
161 | - """See Converter.convert().""" |
162 | - to_convert.transport.put_bytes('branch-format', |
163 | - self.target_format.as_string()) |
164 | - return BzrDir.open_from_transport(to_convert.root_transport) |
165 | +controldir.Converter.register_converter(ConvertMetaContents) |
166 | + |
167 | + |
168 | +class ConvertMetaToColo(controldir.Converter): |
169 | + """Convert a 'development-colo' bzrdir to a '2a' bzrdir and vice versa. |
170 | + """ |
171 | + |
172 | + @classmethod |
173 | + def is_compatible(self, source_format, target_format): |
174 | + if (isinstance(source_format, BzrDirMetaFormat1) |
175 | + and isinstance(target_format, BzrDirMetaFormat1Colo)): |
176 | + return True |
177 | + if (isinstance(source_format, BzrDirMetaFormat1Colo) |
178 | + and isinstance(target_format, BzrDirMetaFormat1)): |
179 | + return True |
180 | + return False |
181 | + |
182 | + def convert(self, to_convert, target_format, pb): |
183 | + """See Converter.convert().""" |
184 | + to_convert.transport.put_bytes('branch-format', |
185 | + target_format.as_string()) |
186 | + return BzrDir.open_from_transport(to_convert.root_transport) |
187 | + |
188 | + |
189 | +controldir.Converter.register_converter(ConvertMetaToColo) |
190 | |
191 | |
192 | class CreateRepository(controldir.RepositoryAcquisitionPolicy): |
193 | |
194 | === modified file 'breezy/bzr/remote.py' |
195 | --- breezy/bzr/remote.py 2019-01-01 23:40:59 +0000 |
196 | +++ breezy/bzr/remote.py 2019-02-04 13:47:49 +0000 |
197 | @@ -932,10 +932,6 @@ |
198 | self._ensure_real() |
199 | return self._real_bzrdir.get_workingtree_transport(workingtree_format) |
200 | |
201 | - def can_convert_format(self): |
202 | - """Upgrading of remote bzrdirs is not supported yet.""" |
203 | - return False |
204 | - |
205 | def needs_format_conversion(self, format): |
206 | """Upgrading of remote bzrdirs is not supported yet.""" |
207 | return False |
208 | |
209 | === modified file 'breezy/controldir.py' |
210 | --- breezy/controldir.py 2018-11-12 01:41:38 +0000 |
211 | +++ breezy/controldir.py 2019-02-04 13:47:49 +0000 |
212 | @@ -118,11 +118,6 @@ |
213 | API users to check for magic attributes to see what features are supported. |
214 | """ |
215 | |
216 | - def can_convert_format(self): |
217 | - """Return true if this controldir is one whose format we can convert |
218 | - from.""" |
219 | - return True |
220 | - |
221 | def list_branches(self): |
222 | """Return a sequence of all branches local to this control directory. |
223 | |
224 | @@ -990,18 +985,38 @@ |
225 | class Converter(object): |
226 | """Converts a disk format object from one format to another.""" |
227 | |
228 | - def convert(self, to_convert, pb): |
229 | + _converters = [] |
230 | + |
231 | + def convert(self, to_convert, target_format, pb): |
232 | """Perform the conversion of to_convert, giving feedback via pb. |
233 | |
234 | :param to_convert: The disk object to convert. |
235 | + :param target_format: The target format |
236 | :param pb: a progress bar to use for progress information. |
237 | """ |
238 | + raise NotImplementedError(self.convert) |
239 | |
240 | def step(self, message): |
241 | """Update the pb by a step.""" |
242 | self.count += 1 |
243 | self.pb.update(message, self.count, self.total) |
244 | |
245 | + @classmethod |
246 | + def is_compatible(cls, source_format, target_format): |
247 | + raise NotImplementedError(cls.is_compatible) |
248 | + |
249 | + @classmethod |
250 | + def register_converter(cls, converter): |
251 | + cls._converters.append(converter) |
252 | + |
253 | + @classmethod |
254 | + def get_converter(cls, source_format, target_format): |
255 | + for converter in cls._converters: |
256 | + if converter.is_compatible(source_format, target_format): |
257 | + return converter() |
258 | + raise errors.BadConversionTarget( |
259 | + "no converter available", target_format, source_format) |
260 | + |
261 | |
262 | class ControlDirFormat(object): |
263 | """An encapsulation of the initialization and open routines for a format. |
264 | @@ -1070,7 +1085,9 @@ |
265 | :param format: Optional format to override the default format of the |
266 | library. |
267 | """ |
268 | - raise NotImplementedError(self.get_converter) |
269 | + if format is None: |
270 | + format = ControlDirFormat.get_default_format() |
271 | + return Converter.get_converter(self, format) |
272 | |
273 | def is_supported(self): |
274 | """Is this format supported? |
275 | |
276 | === modified file 'breezy/errors.py' |
277 | --- breezy/errors.py 2018-11-11 04:08:32 +0000 |
278 | +++ breezy/errors.py 2019-02-04 13:47:49 +0000 |
279 | @@ -922,11 +922,6 @@ |
280 | self.lock_token = lock_token |
281 | |
282 | |
283 | -class UpgradeReadonly(BzrError): |
284 | - |
285 | - _fmt = "Upgrade URL cannot work with readonly URLs." |
286 | - |
287 | - |
288 | class UpToDateFormat(BzrError): |
289 | |
290 | _fmt = "The branch format %(format)s is already at the most recent format." |
291 | |
292 | === modified file 'breezy/git/dir.py' |
293 | --- breezy/git/dir.py 2018-11-16 11:37:47 +0000 |
294 | +++ breezy/git/dir.py 2019-02-04 13:47:49 +0000 |
295 | @@ -107,9 +107,6 @@ |
296 | def is_supported(self): |
297 | return True |
298 | |
299 | - def can_convert_format(self): |
300 | - return False |
301 | - |
302 | def break_lock(self): |
303 | # There are no global locks, so nothing to break. |
304 | raise NotImplementedError(self.break_lock) |
305 | |
306 | === modified file 'breezy/plugins/cvs/__init__.py' |
307 | --- breezy/plugins/cvs/__init__.py 2018-11-11 04:08:32 +0000 |
308 | +++ breezy/plugins/cvs/__init__.py 2019-02-04 13:47:49 +0000 |
309 | @@ -39,9 +39,6 @@ |
310 | class CVSDirFormat(controldir.ControlDirFormat): |
311 | """The CVS directory control format.""" |
312 | |
313 | - def get_converter(self): |
314 | - raise NotImplementedError(self.get_converter) |
315 | - |
316 | def get_format_description(self): |
317 | return "CVS control directory." |
318 | |
319 | |
320 | === modified file 'breezy/plugins/darcs/__init__.py' |
321 | --- breezy/plugins/darcs/__init__.py 2018-11-11 04:08:32 +0000 |
322 | +++ breezy/plugins/darcs/__init__.py 2019-02-04 13:47:49 +0000 |
323 | @@ -37,9 +37,6 @@ |
324 | class DarcsDirFormat(controldir.ControlDirFormat): |
325 | """Darcs directory format.""" |
326 | |
327 | - def get_converter(self): |
328 | - raise NotImplementedError(self.get_converter) |
329 | - |
330 | def get_format_description(self): |
331 | return "darcs control directory" |
332 | |
333 | |
334 | === modified file 'breezy/plugins/mtn/__init__.py' |
335 | --- breezy/plugins/mtn/__init__.py 2018-11-11 04:08:32 +0000 |
336 | +++ breezy/plugins/mtn/__init__.py 2019-02-04 13:47:49 +0000 |
337 | @@ -39,9 +39,6 @@ |
338 | class MonotoneDirFormat(controldir.ControlDirFormat): |
339 | """Monotone directory format.""" |
340 | |
341 | - def get_converter(self): |
342 | - raise NotImplementedError(self.get_converter) |
343 | - |
344 | def get_format_description(self): |
345 | return "Monotone control directory" |
346 | |
347 | |
348 | === modified file 'breezy/plugins/weave_fmt/bzrdir.py' |
349 | --- breezy/plugins/weave_fmt/bzrdir.py 2018-11-11 04:08:32 +0000 |
350 | +++ breezy/plugins/weave_fmt/bzrdir.py 2019-02-04 13:47:49 +0000 |
351 | @@ -126,11 +126,6 @@ |
352 | """See ControlDirFormat.get_format_description().""" |
353 | return "All-in-one format 5" |
354 | |
355 | - def get_converter(self, format=None): |
356 | - """See ControlDirFormat.get_converter().""" |
357 | - # there is one and only one upgrade path here. |
358 | - return ConvertBzrDir5To6() |
359 | - |
360 | def _initialize_for_clone(self, url): |
361 | return self.initialize_on_transport(get_transport(url), _cloning=True) |
362 | |
363 | @@ -190,11 +185,6 @@ |
364 | from .branch import BzrBranchFormat4 |
365 | return BzrBranchFormat4() |
366 | |
367 | - def get_converter(self, format=None): |
368 | - """See ControlDirFormat.get_converter().""" |
369 | - # there is one and only one upgrade path here. |
370 | - return ConvertBzrDir6ToMeta() |
371 | - |
372 | def _initialize_for_clone(self, url): |
373 | return self.initialize_on_transport(get_transport(url), _cloning=True) |
374 | |
375 | @@ -236,7 +226,15 @@ |
376 | self.text_count = 0 |
377 | self.revisions = {} |
378 | |
379 | - def convert(self, to_convert, pb): |
380 | + @classmethod |
381 | + def is_compatible(cls, source_format, target_format): |
382 | + if not isinstance(target_format, BzrDirFormat5): |
383 | + return False |
384 | + if not isinstance(source_format, BzrDirFormat4): |
385 | + return False |
386 | + return True |
387 | + |
388 | + def convert(self, to_convert, target_format, pb): |
389 | """See Converter.convert().""" |
390 | self.controldir = to_convert |
391 | if pb is not None: |
392 | @@ -294,7 +292,7 @@ |
393 | self._cleanup_spare_files_after_format4() |
394 | self.branch._transport.put_bytes( |
395 | 'branch-format', |
396 | - BzrDirFormat5().get_format_string(), |
397 | + target_format.get_format_string(), |
398 | mode=self.controldir._get_file_mode()) |
399 | |
400 | def _cleanup_spare_files_after_format4(self): |
401 | @@ -504,7 +502,15 @@ |
402 | class ConvertBzrDir5To6(Converter): |
403 | """Converts format 5 bzr dirs to format 6.""" |
404 | |
405 | - def convert(self, to_convert, pb): |
406 | + @classmethod |
407 | + def is_compatible(cls, source_format, target_format): |
408 | + if not isinstance(source_format, BzrDirFormat5): |
409 | + return False |
410 | + if not isinstance(source_format, BzrDirFormat6): |
411 | + return False |
412 | + return True |
413 | + |
414 | + def convert(self, to_convert, target_format, pb): |
415 | """See Converter.convert().""" |
416 | self.controldir = to_convert |
417 | with ui.ui_factory.nested_progress_bar() as pb: |
418 | @@ -538,14 +544,22 @@ |
419 | store_transport.move(filename, new_name) |
420 | self.controldir.transport.put_bytes( |
421 | 'branch-format', |
422 | - BzrDirFormat6().get_format_string(), |
423 | + target_format.get_format_string(), |
424 | mode=self.controldir._get_file_mode()) |
425 | |
426 | |
427 | class ConvertBzrDir6ToMeta(Converter): |
428 | """Converts format 6 bzr dirs to metadirs.""" |
429 | |
430 | - def convert(self, to_convert, pb): |
431 | + @classmethod |
432 | + def is_compatible(cls, source_format, target_format): |
433 | + if not isinstance(source_format, BzrDirFormat6): |
434 | + return False |
435 | + if not isinstance(target_format, BzrDirMetaFormat1): |
436 | + return False |
437 | + return True |
438 | + |
439 | + def convert(self, to_convert, target_format, pb): |
440 | """See Converter.convert().""" |
441 | from .repository import RepositoryFormat7 |
442 | from ...bzr.fullhistory import BzrBranchFormat5 |
443 | @@ -634,7 +648,7 @@ |
444 | 'checkout/last-revision', last_revision) |
445 | self.controldir.transport.put_bytes( |
446 | 'branch-format', |
447 | - BzrDirMetaFormat1().get_format_string(), |
448 | + target_format.get_format_string(), |
449 | mode=self.file_mode) |
450 | self.pb.finished() |
451 | return ControlDir.open(self.controldir.user_url) |
452 | @@ -692,11 +706,6 @@ |
453 | """See ControlDirFormat.get_format_description().""" |
454 | return "All-in-one format 4" |
455 | |
456 | - def get_converter(self, format=None): |
457 | - """See ControlDirFormat.get_converter().""" |
458 | - # there is one and only one upgrade path here. |
459 | - return ConvertBzrDir4To5() |
460 | - |
461 | def initialize_on_transport(self, transport): |
462 | """Format 4 branches cannot be created.""" |
463 | raise errors.UninitializableFormat(self) |
464 | @@ -1000,3 +1009,8 @@ |
465 | # bzrdir as a whole |
466 | from .workingtree import WorkingTreeFormat2 |
467 | return WorkingTreeFormat2().open(self, _found=True) |
468 | + |
469 | + |
470 | +Converter.register_converter(ConvertBzrDir4To5) |
471 | +Converter.register_converter(ConvertBzrDir5To6) |
472 | +Converter.register_converter(ConvertBzrDir6ToMeta) |
473 | |
474 | === modified file 'breezy/plugins/weave_fmt/test_bzrdir.py' |
475 | --- breezy/plugins/weave_fmt/test_bzrdir.py 2018-11-16 18:33:17 +0000 |
476 | +++ breezy/plugins/weave_fmt/test_bzrdir.py 2019-02-04 13:47:49 +0000 |
477 | @@ -73,11 +73,6 @@ |
478 | dir = controldir.ControlDir.open(self.get_url()) |
479 | check_dir_components_use_same_lock(dir) |
480 | |
481 | - def test_can_convert(self): |
482 | - # format 5 dirs are convertable |
483 | - dir = BzrDirFormat5().initialize(self.get_url()) |
484 | - self.assertTrue(dir.can_convert_format()) |
485 | - |
486 | def test_needs_conversion(self): |
487 | # format 5 dirs need a conversion if they are not the default, |
488 | # and they aren't |
489 | @@ -108,11 +103,6 @@ |
490 | dir = controldir.ControlDir.open(self.get_url()) |
491 | check_dir_components_use_same_lock(dir) |
492 | |
493 | - def test_can_convert(self): |
494 | - # format 6 dirs are convertable |
495 | - dir = BzrDirFormat6().initialize(self.get_url()) |
496 | - self.assertTrue(dir.can_convert_format()) |
497 | - |
498 | def test_needs_conversion(self): |
499 | # format 6 dirs need an conversion if they are not the default. |
500 | dir = BzrDirFormat6().initialize(self.get_url()) |
501 | |
502 | === modified file 'breezy/tests/blackbox/test_upgrade.py' |
503 | --- breezy/tests/blackbox/test_upgrade.py 2018-11-11 04:08:32 +0000 |
504 | +++ breezy/tests/blackbox/test_upgrade.py 2019-02-04 13:47:49 +0000 |
505 | @@ -46,11 +46,15 @@ |
506 | class ConvertOldTestToMeta(controldir.Converter): |
507 | """A trivial converter, used for testing.""" |
508 | |
509 | - def convert(self, to_convert, pb): |
510 | + @classmethod |
511 | + def is_compatible(cls, source_format, target_format): |
512 | + return True |
513 | + |
514 | + def convert(self, to_convert, target_format, pb): |
515 | ui.ui_factory.note('starting upgrade from old test format to 2a') |
516 | to_convert.control_transport.put_bytes( |
517 | 'branch-format', |
518 | - bzrdir.BzrDirMetaFormat1().get_format_string(), |
519 | + target_format.get_format_string(), |
520 | mode=to_convert._get_file_mode()) |
521 | return controldir.ControlDir.open(to_convert.user_url) |
522 | |
523 | @@ -59,9 +63,6 @@ |
524 | |
525 | _lock_class = lockable_files.TransportLock |
526 | |
527 | - def get_converter(self, format=None): |
528 | - return ConvertOldTestToMeta() |
529 | - |
530 | @classmethod |
531 | def get_format_string(cls): |
532 | return b"Ancient Test Format" |
533 | @@ -131,6 +132,7 @@ |
534 | |
535 | def test_upgrade_control_dir(self): |
536 | old_format = OldBzrDirFormat() |
537 | + self.overrideAttr(controldir.Converter, '_converters', [ConvertOldTestToMeta]) |
538 | self.addCleanup(bzr.BzrProber.formats.remove, |
539 | old_format.get_format_string()) |
540 | bzr.BzrProber.formats.register(old_format.get_format_string(), |
541 | |
542 | === modified file 'breezy/tests/per_controldir/test_controldir.py' |
543 | --- breezy/tests/per_controldir/test_controldir.py 2018-11-11 04:08:32 +0000 |
544 | +++ breezy/tests/per_controldir/test_controldir.py 2019-02-04 13:47:49 +0000 |
545 | @@ -1580,12 +1580,11 @@ |
546 | def test_can_and_needs_format_conversion(self): |
547 | # check that we can ask an instance if its upgradable |
548 | dir = self.make_controldir('.') |
549 | - if dir.can_convert_format(): |
550 | - # if its default updatable there must be an updater |
551 | - # (we force the latest known format as downgrades may not be |
552 | - # available |
553 | + try: |
554 | self.assertTrue(isinstance(dir._format.get_converter( |
555 | format=dir._format), controldir.Converter)) |
556 | + except errors.BadConversionTarget: |
557 | + pass # No converter available |
558 | dir.needs_format_conversion( |
559 | controldir.ControlDirFormat.get_default_format()) |
560 | |
561 | @@ -1618,14 +1617,13 @@ |
562 | dir.create_repository() |
563 | dir.create_branch() |
564 | self.createWorkingTreeOrSkip(dir) |
565 | - if dir.can_convert_format(): |
566 | - # if its default updatable there must be an updater |
567 | - # (we force the latest known format as downgrades may not be |
568 | - # available |
569 | + try: |
570 | with ui.ui_factory.nested_progress_bar() as pb: |
571 | - dir._format.get_converter(format=dir._format).convert(dir, pb) |
572 | + dir._format.get_converter(format=dir._format).convert(dir, dir._format, pb) |
573 | # and it should pass 'check' now. |
574 | check.check_dwim(self.get_url('.'), False, True, True) |
575 | + except errors.BadConversionTarget: |
576 | + pass # no converter available |
577 | |
578 | def test_format_description(self): |
579 | dir = self.make_controldir('.') |
580 | |
581 | === modified file 'breezy/tests/test_bzrdir.py' |
582 | --- breezy/tests/test_bzrdir.py 2019-01-04 21:30:02 +0000 |
583 | +++ breezy/tests/test_bzrdir.py 2019-02-04 13:47:49 +0000 |
584 | @@ -1440,7 +1440,7 @@ |
585 | format = bzrdir.BzrDirMetaFormat1Colo() |
586 | self.assertTrue(tree.controldir.needs_format_conversion(format)) |
587 | converter = tree.controldir._format.get_converter(format) |
588 | - result = converter.convert(tree.controldir, None) |
589 | + result = converter.convert(tree.controldir, format, None) |
590 | self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1Colo) |
591 | self.assertFalse(result.needs_format_conversion(format)) |
592 | |
593 | @@ -1449,16 +1449,16 @@ |
594 | format = bzrdir.BzrDirMetaFormat1() |
595 | self.assertTrue(tree.controldir.needs_format_conversion(format)) |
596 | converter = tree.controldir._format.get_converter(format) |
597 | - result = converter.convert(tree.controldir, None) |
598 | + result = converter.convert(tree.controldir, format, None) |
599 | self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1) |
600 | self.assertFalse(result.needs_format_conversion(format)) |
601 | |
602 | def test_downgrade_to_2a_too_many_branches(self): |
603 | tree = self.make_branch_and_tree('.', format='development-colo') |
604 | tree.controldir.create_branch(name="another-colocated-branch") |
605 | - converter = tree.controldir._format.get_converter( |
606 | - bzrdir.BzrDirMetaFormat1()) |
607 | - result = converter.convert(tree.controldir, bzrdir.BzrDirMetaFormat1()) |
608 | + target_format = bzrdir.BzrDirMetaFormat1() |
609 | + converter = tree.controldir._format.get_converter(target_format) |
610 | + result = converter.convert(tree.controldir, target_format, None) |
611 | self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1) |
612 | |
613 | def test_nested(self): |
614 | |
615 | === modified file 'breezy/tests/test_upgrade.py' |
616 | --- breezy/tests/test_upgrade.py 2018-11-12 01:41:38 +0000 |
617 | +++ breezy/tests/test_upgrade.py 2019-02-04 13:47:49 +0000 |
618 | @@ -51,7 +51,7 @@ |
619 | target = controldir.format_registry.make_controldir( |
620 | 'dirstate-with-subtree') |
621 | converter = b.controldir._format.get_converter(target) |
622 | - converter.convert(b.controldir, None) |
623 | + converter.convert(b.controldir, target, None) |
624 | new_branch = branch.Branch.open(self.get_url('branch')) |
625 | self.assertIs(new_branch.__class__, bzrbranch.BzrBranch6) |
626 | self.assertEqual(b'CD', new_branch.last_revision()) |
627 | @@ -62,7 +62,7 @@ |
628 | |
629 | b2 = self.make_branch('branch2', format='knit') |
630 | converter = b2.controldir._format.get_converter(target) |
631 | - converter.convert(b2.controldir, None) |
632 | + converter.convert(b2.controldir, target, None) |
633 | b2 = branch.Branch.open(self.get_url('branch')) |
634 | self.assertIs(b2.__class__, bzrbranch.BzrBranch6) |
635 | |
636 | @@ -71,7 +71,7 @@ |
637 | target = controldir.format_registry.make_controldir('1.9') |
638 | target.set_branch_format(bzrbranch.BzrBranchFormat8()) |
639 | converter = b.controldir._format.get_converter(target) |
640 | - converter.convert(b.controldir, None) |
641 | + converter.convert(b.controldir, target, None) |
642 | b = branch.Branch.open(self.get_url('branch')) |
643 | self.assertIs(b.__class__, bzrbranch.BzrBranch8) |
644 | self.assertEqual({}, b._get_all_reference_info()) |
645 | @@ -81,7 +81,7 @@ |
646 | tree = self.make_branch_and_tree('tree', format='knit') |
647 | target = controldir.format_registry.make_controldir('dirstate') |
648 | converter = tree.controldir._format.get_converter(target) |
649 | - converter.convert(tree.controldir, None) |
650 | + converter.convert(tree.controldir, target, None) |
651 | new_tree = workingtree.WorkingTree.open('tree') |
652 | self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4) |
653 | self.assertEqual(b'null:', new_tree.last_revision()) |
654 | @@ -94,7 +94,7 @@ |
655 | tree.add(['file'], [b'file-id']) |
656 | target = controldir.format_registry.make_controldir('dirstate') |
657 | converter = tree.controldir._format.get_converter(target) |
658 | - converter.convert(tree.controldir, None) |
659 | + converter.convert(tree.controldir, target, None) |
660 | new_tree = workingtree.WorkingTree.open('tree') |
661 | self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4) |
662 | self.assertEqual(b'null:', new_tree.last_revision()) |
663 | @@ -105,7 +105,7 @@ |
664 | rev_id = tree.commit('first post') |
665 | target = controldir.format_registry.make_controldir('dirstate') |
666 | converter = tree.controldir._format.get_converter(target) |
667 | - converter.convert(tree.controldir, None) |
668 | + converter.convert(tree.controldir, target, None) |
669 | new_tree = workingtree.WorkingTree.open('tree') |
670 | self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4) |
671 | self.assertEqual(rev_id, new_tree.last_revision()) |
672 | @@ -122,7 +122,7 @@ |
673 | tree.merge_from_branch(merge_tree.branch) |
674 | target = controldir.format_registry.make_controldir('dirstate') |
675 | converter = tree.controldir._format.get_converter(target) |
676 | - converter.convert(tree.controldir, None) |
677 | + converter.convert(tree.controldir, target, None) |
678 | new_tree = workingtree.WorkingTree.open('tree') |
679 | self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4) |
680 | self.assertEqual(rev_id2, new_tree.last_revision()) |
681 | |
682 | === modified file 'breezy/upgrade.py' |
683 | --- breezy/upgrade.py 2018-11-11 04:08:32 +0000 |
684 | +++ breezy/upgrade.py 2019-02-04 13:47:49 +0000 |
685 | @@ -32,6 +32,11 @@ |
686 | from .bzr.remote import RemoteBzrDir |
687 | |
688 | |
689 | +class UpgradeReadonly(errors.BzrError): |
690 | + |
691 | + _fmt = "Upgrade URL cannot work with readonly URLs." |
692 | + |
693 | + |
694 | class Convert(object): |
695 | |
696 | def __init__(self, url=None, format=None, control_dir=None): |
697 | @@ -60,7 +65,7 @@ |
698 | self.controldir._ensure_real() |
699 | self.controldir = self.controldir._real_bzrdir |
700 | if self.controldir.root_transport.is_readonly(): |
701 | - raise errors.UpgradeReadonly |
702 | + raise UpgradeReadonly |
703 | self.transport = self.controldir.root_transport |
704 | ui.ui_factory.suppressed_warnings.add(warning_id) |
705 | try: |
706 | @@ -96,9 +101,6 @@ |
707 | format = self.format |
708 | if not self.controldir.needs_format_conversion(format): |
709 | raise errors.UpToDateFormat(self.controldir._format) |
710 | - if not self.controldir.can_convert_format(): |
711 | - raise errors.BzrError(gettext("cannot upgrade from bzrdir format %s") % |
712 | - self.controldir._format) |
713 | self.controldir.check_conversion_target(format) |
714 | ui.ui_factory.note(gettext('starting upgrade of %s') % |
715 | urlutils.unescape_for_display(self.transport.base, 'utf-8')) |
716 | @@ -106,7 +108,7 @@ |
717 | self.backup_oldpath, self.backup_newpath = self.controldir.backup_bzrdir() |
718 | while self.controldir.needs_format_conversion(format): |
719 | converter = self.controldir._format.get_converter(format) |
720 | - self.controldir = converter.convert(self.controldir, None) |
721 | + self.controldir = converter.convert(self.controldir, format, None) |
722 | ui.ui_factory.note(gettext('finished')) |
723 | |
724 | def clean_up(self): |
725 | |
726 | === modified file 'tools/prepare_for_latex.py' |
727 | --- tools/prepare_for_latex.py 2018-11-17 16:19:11 +0000 |
728 | +++ tools/prepare_for_latex.py 2019-02-04 13:47:49 +0000 |
729 | @@ -41,6 +41,7 @@ |
730 | DIRECTIVE_ELEMENT_PATTERN = re.compile(u'^\\s+:[^:]+:\\s+') |
731 | |
732 | class Converter(object): |
733 | + |
734 | def __init__(self, srcdir, destdir): |
735 | self.srcdir = srcdir |
736 | self.destdir = destdir |
Looks good, thanks!