Merge lp:~jelmer/bzr/lazy-registries into lp:bzr
- lazy-registries
- Merge into bzr.dev
Status: | Rejected |
---|---|
Rejected by: | Jelmer Vernooij |
Proposed branch: | lp:~jelmer/bzr/lazy-registries |
Merge into: | lp:bzr |
Diff against target: |
1012 lines (+232/-101) 40 files modified
bzrlib/branch.py (+8/-4) bzrlib/bugtracker.py (+1/-1) bzrlib/bzrdir.py (+2/-1) bzrlib/chk_map.py (+2/-1) bzrlib/commands.py (+4/-3) bzrlib/config.py (+7/-4) bzrlib/conflicts.py (+2/-2) bzrlib/controldir.py (+10/-6) bzrlib/diff.py (+1/-1) bzrlib/directory_service.py (+4/-2) bzrlib/filters/__init__.py (+3/-1) bzrlib/foreign.py (+2/-1) bzrlib/help_topics/__init__.py (+1/-1) bzrlib/hooks.py (+1/-1) bzrlib/log.py (+5/-3) bzrlib/mail_client.py (+2/-1) bzrlib/merge.py (+1/-1) bzrlib/merge_directive.py (+2/-1) bzrlib/option.py (+2/-2) bzrlib/plugins/launchpad/__init__.py (+11/-12) bzrlib/plugins/netrc_credential_store/__init__.py (+2/-1) bzrlib/plugins/po_merge/__init__.py (+2/-2) bzrlib/plugins/weave_fmt/__init__.py (+3/-3) bzrlib/registry.py (+80/-24) bzrlib/remote.py (+3/-2) bzrlib/repository.py (+4/-2) bzrlib/revisionspec.py (+1/-1) bzrlib/send.py (+1/-1) bzrlib/serializer.py (+1/-1) bzrlib/smart/request.py (+1/-1) bzrlib/tag.py (+1/-1) bzrlib/tests/__init__.py (+3/-2) bzrlib/tests/test_foreign.py (+1/-1) bzrlib/tests/test_registry.py (+40/-1) bzrlib/transform.py (+1/-1) bzrlib/transport/__init__.py (+4/-2) bzrlib/version_info_formats/__init__.py (+2/-2) bzrlib/versionedfile.py (+1/-1) bzrlib/workingtree.py (+6/-3) doc/en/release-notes/bzr-2.6.txt (+4/-0) |
To merge this branch: | bzr merge lp:~jelmer/bzr/lazy-registries |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Vincent Ladeuil | Approve | ||
Review via email: mp+99913@code.launchpad.net |
This proposal supersedes a proposal from 2012-03-16.
Commit message
Allow lazy registration in registries without loading the registry itself.
Description of the change
Allow lazy registration of entries in registries.
This allows plugins to significantly reduce the amount of code they have to import.
For example, in bzr-git, bzr-svn and bzr-hg this means we can drop imports of:
* bzrlib.
* bzrlib.send
* bzrlib.diff
* bzrlib.foreign
* bzrlib.help_topics
In e.g. bzr-search we can drop bzrlib.
In bzr-xmloutput, bzrlib.log
Etc.
Vincent Ladeuil (vila) wrote : Posted in a previous version of this proposal | # |
Jelmer Vernooij (jelmer) wrote : Posted in a previous version of this proposal | # |
Am 29/03/12 10:27, schrieb Vincent Ladeuil:
> Review: Needs Fixing
>
> Nice one.
>
> I think I'm not comfortable with two specifics points:
>
> - you've added a feature to Registry, I think it would be clearer to create
> a new class instead,
If we add a new class, then that means that any users of registries
would either have to stick with the old implementation *or* be converted
to the new one. Adding it to the current class just allows us to update
the sites and then plugins can use either the lazy registration or
non-lazy registration as they see fit. We wouldn't have to immediately
update all plugins, their existing calls would still just work.
>
> - the way it works is magical for people that don't know how lazy loading
> works, a few comments or docstrings should address that.
>
> 565 +RegistryEntry = collections.
>
> Good addition but Worth a docstring.
Fixed.
>
> 583 + if module is not None and member_name is not None:
>
> This is the line that conflates two classes into a single one for a benefit
> that is not clear to me.
If module is not set, then the Registry() object only allows for direct
registration (i.e. importing the object itself and calling
install_named_hook or install_
module/member_name is set, then it also supports install_lazy_hook() *in
addition* to the other methods.
I've added a bit of documentation to the Registry docstring.
>
> 688 +# Lazily registered registries. Maps (module, registry_name, name,
> 689 +# entry_module, entry_name) -> (objgetter, info, help)
> 690 +_lazy_registries = {}
>
> This is where you should explain part of the magic.
>
> 712 + obj_getter = _LazyObjectGett
> 713 + registry_dict[key] = RegistryEntry(
>
> And this is the othe place where the magic takes place (truth is there is
> yet another place where the magic occurs but it won't appear that magical if
> you use a different class). Someone not knowing about lazy loading and
> obj_getter is likely to be completely lost ;)
I've updated the comments.
Cheers,
Jelmer
Vincent Ladeuil (vila) wrote : | # |
> If we add a new class, then that means that any users of registries would
> either have to stick with the old implementation *or* be converted to the
> new one.
Hmm. That's true.
On the other hand it means we will never have a clean cut nor a clean
implementation because plugins have no incentive to use the new one, no
deprecation warning here, no nothing.
Not worth blocking this one but I'm always a bit worried when we add more
cruft without a clear path to get rid of it :-/
Jelmer Vernooij (jelmer) wrote : | # |
sent to pqm by email
Jelmer Vernooij (jelmer) wrote : | # |
sent to pqm by email
Jelmer Vernooij (jelmer) wrote : | # |
sent to pqm by email
Jelmer Vernooij (jelmer) wrote : | # |
sent to pqm by email
Jelmer Vernooij (jelmer) wrote : | # |
sent to pqm by email
John A Meinel (jameinel) wrote : | # |
sent to pqm by email
John A Meinel (jameinel) wrote : | # |
sent to pqm by email
Martin Packman (gz) wrote : | # |
What is the failure PQM was giving on this branch?
Preview Diff
1 | === modified file 'bzrlib/branch.py' | |||
2 | --- bzrlib/branch.py 2012-03-29 12:27:52 +0000 | |||
3 | +++ bzrlib/branch.py 2012-03-31 14:09:30 +0000 | |||
4 | @@ -2325,8 +2325,10 @@ | |||
5 | 2325 | class BranchFormatRegistry(controldir.ControlComponentFormatRegistry): | 2325 | class BranchFormatRegistry(controldir.ControlComponentFormatRegistry): |
6 | 2326 | """Branch format registry.""" | 2326 | """Branch format registry.""" |
7 | 2327 | 2327 | ||
10 | 2328 | def __init__(self, other_registry=None): | 2328 | def __init__(self, module_name=None, member_name=None, |
11 | 2329 | super(BranchFormatRegistry, self).__init__(other_registry) | 2329 | other_registry=None): |
12 | 2330 | super(BranchFormatRegistry, self).__init__(module_name, member_name, | ||
13 | 2331 | other_registry) | ||
14 | 2330 | self._default_format = None | 2332 | self._default_format = None |
15 | 2331 | 2333 | ||
16 | 2332 | def set_default(self, format): | 2334 | def set_default(self, format): |
17 | @@ -2336,7 +2338,8 @@ | |||
18 | 2336 | return self._default_format | 2338 | return self._default_format |
19 | 2337 | 2339 | ||
20 | 2338 | 2340 | ||
22 | 2339 | network_format_registry = registry.FormatRegistry() | 2341 | network_format_registry = registry.FormatRegistry("bzrlib.branch", |
23 | 2342 | "network_format_registry") | ||
24 | 2340 | """Registry of formats indexed by their network name. | 2343 | """Registry of formats indexed by their network name. |
25 | 2341 | 2344 | ||
26 | 2342 | The network name for a branch format is an identifier that can be used when | 2345 | The network name for a branch format is an identifier that can be used when |
27 | @@ -2344,7 +2347,8 @@ | |||
28 | 2344 | BranchFormat.network_name() for more detail. | 2347 | BranchFormat.network_name() for more detail. |
29 | 2345 | """ | 2348 | """ |
30 | 2346 | 2349 | ||
32 | 2347 | format_registry = BranchFormatRegistry(network_format_registry) | 2350 | format_registry = BranchFormatRegistry("bzrlib.branch", "format_registry", |
33 | 2351 | network_format_registry) | ||
34 | 2348 | 2352 | ||
35 | 2349 | 2353 | ||
36 | 2350 | # formats which have no format string are not discoverable | 2354 | # formats which have no format string are not discoverable |
37 | 2351 | 2355 | ||
38 | === modified file 'bzrlib/bugtracker.py' | |||
39 | --- bzrlib/bugtracker.py 2011-12-18 12:46:49 +0000 | |||
40 | +++ bzrlib/bugtracker.py 2012-03-31 14:09:30 +0000 | |||
41 | @@ -174,7 +174,7 @@ | |||
42 | 174 | return _bugs_help | 174 | return _bugs_help |
43 | 175 | 175 | ||
44 | 176 | 176 | ||
46 | 177 | tracker_registry = TrackerRegistry() | 177 | tracker_registry = TrackerRegistry("bzrlib.bugtracker", "tracker_registry") |
47 | 178 | """Registry of bug trackers.""" | 178 | """Registry of bug trackers.""" |
48 | 179 | 179 | ||
49 | 180 | 180 | ||
50 | 181 | 181 | ||
51 | === modified file 'bzrlib/bzrdir.py' | |||
52 | --- bzrlib/bzrdir.py 2012-03-29 12:27:52 +0000 | |||
53 | +++ bzrlib/bzrdir.py 2012-03-31 14:09:30 +0000 | |||
54 | @@ -1226,7 +1226,8 @@ | |||
55 | 1226 | class BzrProber(controldir.Prober): | 1226 | class BzrProber(controldir.Prober): |
56 | 1227 | """Prober for formats that use a .bzr/ control directory.""" | 1227 | """Prober for formats that use a .bzr/ control directory.""" |
57 | 1228 | 1228 | ||
59 | 1229 | formats = registry.FormatRegistry(controldir.network_format_registry) | 1229 | formats = registry.FormatRegistry("bzrlib.bzrdir", "BzrProber.formats", |
60 | 1230 | controldir.network_format_registry) | ||
61 | 1230 | """The known .bzr formats.""" | 1231 | """The known .bzr formats.""" |
62 | 1231 | 1232 | ||
63 | 1232 | @classmethod | 1233 | @classmethod |
64 | 1233 | 1234 | ||
65 | === modified file 'bzrlib/chk_map.py' | |||
66 | --- bzrlib/chk_map.py 2011-12-19 13:23:58 +0000 | |||
67 | +++ bzrlib/chk_map.py 2012-03-31 14:09:30 +0000 | |||
68 | @@ -99,7 +99,8 @@ | |||
69 | 99 | return '\x00'.join(key) | 99 | return '\x00'.join(key) |
70 | 100 | 100 | ||
71 | 101 | 101 | ||
73 | 102 | search_key_registry = registry.Registry() | 102 | search_key_registry = registry.Registry("bzrlib.chk_map", |
74 | 103 | "search_key_registry") | ||
75 | 103 | search_key_registry.register('plain', _search_key_plain) | 104 | search_key_registry.register('plain', _search_key_plain) |
76 | 104 | 105 | ||
77 | 105 | 106 | ||
78 | 106 | 107 | ||
79 | === modified file 'bzrlib/commands.py' | |||
80 | --- bzrlib/commands.py 2012-03-13 17:25:29 +0000 | |||
81 | +++ bzrlib/commands.py 2012-03-31 14:09:30 +0000 | |||
82 | @@ -75,8 +75,8 @@ | |||
83 | 75 | about the builtin they're decorating. | 75 | about the builtin they're decorating. |
84 | 76 | """ | 76 | """ |
85 | 77 | 77 | ||
88 | 78 | def __init__(self): | 78 | def __init__(self, module_name=None, member_name=None): |
89 | 79 | registry.Registry.__init__(self) | 79 | registry.Registry.__init__(self, module_name, member_name) |
90 | 80 | self.overridden_registry = None | 80 | self.overridden_registry = None |
91 | 81 | # map from aliases to the real command that implements the name | 81 | # map from aliases to the real command that implements the name |
92 | 82 | self._alias_dict = {} | 82 | self._alias_dict = {} |
93 | @@ -1300,4 +1300,5 @@ | |||
94 | 1300 | for key, provider in self.iteritems(): | 1300 | for key, provider in self.iteritems(): |
95 | 1301 | yield provider | 1301 | yield provider |
96 | 1302 | 1302 | ||
98 | 1303 | command_providers_registry = ProvidersRegistry() | 1303 | command_providers_registry = ProvidersRegistry("bzrlib.commands", |
99 | 1304 | "command_providers_registry") | ||
100 | 1304 | 1305 | ||
101 | === modified file 'bzrlib/config.py' | |||
102 | --- bzrlib/config.py 2012-03-29 12:27:52 +0000 | |||
103 | +++ bzrlib/config.py 2012-03-31 14:09:30 +0000 | |||
104 | @@ -2098,7 +2098,8 @@ | |||
105 | 2098 | info=fallback, override_existing=override_existing) | 2098 | info=fallback, override_existing=override_existing) |
106 | 2099 | 2099 | ||
107 | 2100 | 2100 | ||
109 | 2101 | credential_store_registry = CredentialStoreRegistry() | 2101 | credential_store_registry = CredentialStoreRegistry("bzrlib.config", |
110 | 2102 | "credential_store_registry") | ||
111 | 2102 | 2103 | ||
112 | 2103 | 2104 | ||
113 | 2104 | class CredentialStore(object): | 2105 | class CredentialStore(object): |
114 | @@ -2574,7 +2575,7 @@ | |||
115 | 2574 | return the_help | 2575 | return the_help |
116 | 2575 | 2576 | ||
117 | 2576 | 2577 | ||
119 | 2577 | option_registry = OptionRegistry() | 2578 | option_registry = OptionRegistry("bzrlib.config", "option_registry") |
120 | 2578 | 2579 | ||
121 | 2579 | 2580 | ||
122 | 2580 | # Registered options in lexicographical order | 2581 | # Registered options in lexicographical order |
123 | @@ -4176,9 +4177,11 @@ | |||
124 | 4176 | # The registered object should be a callable receiving a test instance | 4177 | # The registered object should be a callable receiving a test instance |
125 | 4177 | # parameter (inheriting from tests.TestCaseWithTransport) and returning a Store | 4178 | # parameter (inheriting from tests.TestCaseWithTransport) and returning a Store |
126 | 4178 | # object. | 4179 | # object. |
128 | 4179 | test_store_builder_registry = registry.Registry() | 4180 | test_store_builder_registry = registry.Registry("bzrlib.config", |
129 | 4181 | "test_store_builder_registry") | ||
130 | 4180 | 4182 | ||
131 | 4181 | # The registered object should be a callable receiving a test instance | 4183 | # The registered object should be a callable receiving a test instance |
132 | 4182 | # parameter (inheriting from tests.TestCaseWithTransport) and returning a Stack | 4184 | # parameter (inheriting from tests.TestCaseWithTransport) and returning a Stack |
133 | 4183 | # object. | 4185 | # object. |
135 | 4184 | test_stack_builder_registry = registry.Registry() | 4186 | test_stack_builder_registry = registry.Registry("bzrlib.config", |
136 | 4187 | "test_stack_builder_registry") | ||
137 | 4185 | 4188 | ||
138 | === modified file 'bzrlib/conflicts.py' | |||
139 | --- bzrlib/conflicts.py 2012-01-16 14:45:48 +0000 | |||
140 | +++ bzrlib/conflicts.py 2012-03-31 14:09:30 +0000 | |||
141 | @@ -78,8 +78,8 @@ | |||
142 | 78 | self.outf.write(unicode(conflict) + '\n') | 78 | self.outf.write(unicode(conflict) + '\n') |
143 | 79 | 79 | ||
144 | 80 | 80 | ||
147 | 81 | resolve_action_registry = registry.Registry() | 81 | resolve_action_registry = registry.Registry("bzrlib.conflicts", |
148 | 82 | 82 | "resolve_action_registry") | |
149 | 83 | 83 | ||
150 | 84 | resolve_action_registry.register( | 84 | resolve_action_registry.register( |
151 | 85 | 'done', 'done', 'Marks the conflict as resolved.') | 85 | 'done', 'done', 'Marks the conflict as resolved.') |
152 | 86 | 86 | ||
153 | === modified file 'bzrlib/controldir.py' | |||
154 | --- bzrlib/controldir.py 2012-02-14 17:22:37 +0000 | |||
155 | +++ bzrlib/controldir.py 2012-03-31 14:09:30 +0000 | |||
156 | @@ -904,8 +904,10 @@ | |||
157 | 904 | class ControlComponentFormatRegistry(registry.FormatRegistry): | 904 | class ControlComponentFormatRegistry(registry.FormatRegistry): |
158 | 905 | """A registry for control components (branch, workingtree, repository).""" | 905 | """A registry for control components (branch, workingtree, repository).""" |
159 | 906 | 906 | ||
162 | 907 | def __init__(self, other_registry=None): | 907 | def __init__(self, module_name=None, member_name=None, |
163 | 908 | super(ControlComponentFormatRegistry, self).__init__(other_registry) | 908 | other_registry=None): |
164 | 909 | super(ControlComponentFormatRegistry, self).__init__(module_name, | ||
165 | 910 | member_name, other_registry) | ||
166 | 909 | self._extra_formats = [] | 911 | self._extra_formats = [] |
167 | 910 | 912 | ||
168 | 911 | def register(self, format): | 913 | def register(self, format): |
169 | @@ -1290,11 +1292,11 @@ | |||
170 | 1290 | e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented. | 1292 | e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented. |
171 | 1291 | """ | 1293 | """ |
172 | 1292 | 1294 | ||
174 | 1293 | def __init__(self): | 1295 | def __init__(self, module_name=None, member_name=None): |
175 | 1294 | """Create a ControlDirFormatRegistry.""" | 1296 | """Create a ControlDirFormatRegistry.""" |
176 | 1295 | self._aliases = set() | 1297 | self._aliases = set() |
177 | 1296 | self._registration_order = list() | 1298 | self._registration_order = list() |
179 | 1297 | super(ControlDirFormatRegistry, self).__init__() | 1299 | super(ControlDirFormatRegistry, self).__init__(module_name, member_name) |
180 | 1298 | 1300 | ||
181 | 1299 | def aliases(self): | 1301 | def aliases(self): |
182 | 1300 | """Return a set of the format names which are aliases.""" | 1302 | """Return a set of the format names which are aliases.""" |
183 | @@ -1449,9 +1451,11 @@ | |||
184 | 1449 | # Please register new formats after old formats so that formats | 1451 | # Please register new formats after old formats so that formats |
185 | 1450 | # appear in chronological order and format descriptions can build | 1452 | # appear in chronological order and format descriptions can build |
186 | 1451 | # on previous ones. | 1453 | # on previous ones. |
188 | 1452 | format_registry = ControlDirFormatRegistry() | 1454 | format_registry = ControlDirFormatRegistry("bzrlib.controldir", |
189 | 1455 | "format_registry") | ||
190 | 1453 | 1456 | ||
192 | 1454 | network_format_registry = registry.FormatRegistry() | 1457 | network_format_registry = registry.FormatRegistry("bzrlib.controldir", |
193 | 1458 | "network_format_registry") | ||
194 | 1455 | """Registry of formats indexed by their network name. | 1459 | """Registry of formats indexed by their network name. |
195 | 1456 | 1460 | ||
196 | 1457 | The network name for a ControlDirFormat is an identifier that can be used when | 1461 | The network name for a ControlDirFormat is an identifier that can be used when |
197 | 1458 | 1462 | ||
198 | === modified file 'bzrlib/diff.py' | |||
199 | --- bzrlib/diff.py 2011-12-18 12:46:49 +0000 | |||
200 | +++ bzrlib/diff.py 2012-03-31 14:09:30 +0000 | |||
201 | @@ -1039,5 +1039,5 @@ | |||
202 | 1039 | raise errors.NoDiffFound(error_path) | 1039 | raise errors.NoDiffFound(error_path) |
203 | 1040 | 1040 | ||
204 | 1041 | 1041 | ||
206 | 1042 | format_registry = Registry() | 1042 | format_registry = Registry("bzrlib.diff", "format_registry") |
207 | 1043 | format_registry.register('default', DiffTree) | 1043 | format_registry.register('default', DiffTree) |
208 | 1044 | 1044 | ||
209 | === modified file 'bzrlib/directory_service.py' | |||
210 | --- bzrlib/directory_service.py 2012-03-21 13:22:09 +0000 | |||
211 | +++ bzrlib/directory_service.py 2012-03-31 14:09:30 +0000 | |||
212 | @@ -65,7 +65,8 @@ | |||
213 | 65 | service, name = match | 65 | service, name = match |
214 | 66 | return service().look_up(name, url) | 66 | return service().look_up(name, url) |
215 | 67 | 67 | ||
217 | 68 | directories = DirectoryServiceRegistry() | 68 | directories = DirectoryServiceRegistry("bzrlib.directory_service", |
218 | 69 | "directories") | ||
219 | 69 | 70 | ||
220 | 70 | class AliasDirectory(object): | 71 | class AliasDirectory(object): |
221 | 71 | """Directory lookup for locations associated with a branch. | 72 | """Directory lookup for locations associated with a branch. |
222 | @@ -74,7 +75,8 @@ | |||
223 | 74 | supported. On error, a subclass of DirectoryLookupFailure will be raised. | 75 | supported. On error, a subclass of DirectoryLookupFailure will be raised. |
224 | 75 | """ | 76 | """ |
225 | 76 | 77 | ||
227 | 77 | branch_aliases = registry.Registry() | 78 | branch_aliases = registry.Registry("bzrlib.directory_service", |
228 | 79 | "AliasDirectory.branch_aliases") | ||
229 | 78 | branch_aliases.register('parent', lambda b: b.get_parent(), | 80 | branch_aliases.register('parent', lambda b: b.get_parent(), |
230 | 79 | help="The parent of this branch.") | 81 | help="The parent of this branch.") |
231 | 80 | branch_aliases.register('submit', lambda b: b.get_submit_branch(), | 82 | branch_aliases.register('submit', lambda b: b.get_submit_branch(), |
232 | 81 | 83 | ||
233 | === modified file 'bzrlib/filters/__init__.py' | |||
234 | --- bzrlib/filters/__init__.py 2012-03-29 14:54:16 +0000 | |||
235 | +++ bzrlib/filters/__init__.py 2012-03-31 14:09:30 +0000 | |||
236 | @@ -191,7 +191,9 @@ | |||
237 | 191 | 191 | ||
238 | 192 | 192 | ||
239 | 193 | # The registry of filter stacks indexed by name. | 193 | # The registry of filter stacks indexed by name. |
241 | 194 | filter_stacks_registry = registry.Registry() | 194 | # See register_filter_stack_map for details on the registered values. |
242 | 195 | filter_stacks_registry = registry.Registry( | ||
243 | 196 | "bzrlib.filters", "filter_stacks_registry") | ||
244 | 195 | 197 | ||
245 | 196 | 198 | ||
246 | 197 | # Cache of preferences -> stack | 199 | # Cache of preferences -> stack |
247 | 198 | 200 | ||
248 | === modified file 'bzrlib/foreign.py' | |||
249 | --- bzrlib/foreign.py 2012-01-18 14:09:19 +0000 | |||
250 | +++ bzrlib/foreign.py 2012-03-31 14:09:30 +0000 | |||
251 | @@ -188,7 +188,8 @@ | |||
252 | 188 | return foreign_vcs.mapping_registry.revision_id_bzr_to_foreign(revid) | 188 | return foreign_vcs.mapping_registry.revision_id_bzr_to_foreign(revid) |
253 | 189 | 189 | ||
254 | 190 | 190 | ||
256 | 191 | foreign_vcs_registry = ForeignVcsRegistry() | 191 | foreign_vcs_registry = ForeignVcsRegistry("bzrlib.foreign", |
257 | 192 | "foreign_vcs_registry") | ||
258 | 192 | 193 | ||
259 | 193 | 194 | ||
260 | 194 | class ForeignRepository(Repository): | 195 | class ForeignRepository(Repository): |
261 | 195 | 196 | ||
262 | === modified file 'bzrlib/help_topics/__init__.py' | |||
263 | --- bzrlib/help_topics/__init__.py 2012-03-15 15:36:12 +0000 | |||
264 | +++ bzrlib/help_topics/__init__.py 2012-03-31 14:09:30 +0000 | |||
265 | @@ -118,7 +118,7 @@ | |||
266 | 118 | return result | 118 | return result |
267 | 119 | 119 | ||
268 | 120 | 120 | ||
270 | 121 | topic_registry = HelpTopicRegistry() | 121 | topic_registry = HelpTopicRegistry("bzrlib.help_topics", "topic_registry") |
271 | 122 | 122 | ||
272 | 123 | 123 | ||
273 | 124 | #---------------------------------------------------- | 124 | #---------------------------------------------------- |
274 | 125 | 125 | ||
275 | === modified file 'bzrlib/hooks.py' | |||
276 | --- bzrlib/hooks.py 2012-03-14 08:34:10 +0000 | |||
277 | +++ bzrlib/hooks.py 2012-03-31 14:09:30 +0000 | |||
278 | @@ -90,7 +90,7 @@ | |||
279 | 90 | 'MergeDirectiveHooks'), | 90 | 'MergeDirectiveHooks'), |
280 | 91 | ) | 91 | ) |
281 | 92 | 92 | ||
283 | 93 | known_hooks = KnownHooksRegistry() | 93 | known_hooks = KnownHooksRegistry("bzrlib.hooks", "known_hooks") |
284 | 94 | for (_hook_module, _hook_attribute, _hook_class) in _builtin_known_hooks: | 94 | for (_hook_module, _hook_attribute, _hook_class) in _builtin_known_hooks: |
285 | 95 | known_hooks.register_lazy_hook(_hook_module, _hook_attribute, _hook_class) | 95 | known_hooks.register_lazy_hook(_hook_module, _hook_attribute, _hook_class) |
286 | 96 | del _builtin_known_hooks, _hook_module, _hook_attribute, _hook_class | 96 | del _builtin_known_hooks, _hook_module, _hook_attribute, _hook_class |
287 | 97 | 97 | ||
288 | === modified file 'bzrlib/log.py' | |||
289 | --- bzrlib/log.py 2012-03-14 11:30:42 +0000 | |||
290 | +++ bzrlib/log.py 2012-03-31 14:09:30 +0000 | |||
291 | @@ -1789,7 +1789,8 @@ | |||
292 | 1789 | return self.get(c.get('log_format')) | 1789 | return self.get(c.get('log_format')) |
293 | 1790 | 1790 | ||
294 | 1791 | 1791 | ||
296 | 1792 | log_formatter_registry = LogFormatterRegistry() | 1792 | log_formatter_registry = LogFormatterRegistry("bzrlib.log", |
297 | 1793 | "log_formatter_registry") | ||
298 | 1793 | 1794 | ||
299 | 1794 | 1795 | ||
300 | 1795 | log_formatter_registry.register('short', ShortLogFormatter, | 1796 | log_formatter_registry.register('short', ShortLogFormatter, |
301 | @@ -1834,7 +1835,7 @@ | |||
302 | 1834 | return [rev.committer] | 1835 | return [rev.committer] |
303 | 1835 | 1836 | ||
304 | 1836 | 1837 | ||
306 | 1837 | author_list_registry = registry.Registry() | 1838 | author_list_registry = registry.Registry("bzrlib.log", "author_list_registry") |
307 | 1838 | 1839 | ||
308 | 1839 | author_list_registry.register('all', author_list_all, | 1840 | author_list_registry.register('all', author_list_all, |
309 | 1840 | 'All authors') | 1841 | 'All authors') |
310 | @@ -2100,7 +2101,8 @@ | |||
311 | 2100 | return None | 2101 | return None |
312 | 2101 | 2102 | ||
313 | 2102 | 2103 | ||
315 | 2103 | properties_handler_registry = registry.Registry() | 2104 | properties_handler_registry = registry.Registry("bzrlib.log", |
316 | 2105 | "properties_handler_registry") | ||
317 | 2104 | 2106 | ||
318 | 2105 | # Use the properties handlers to print out bug information if available | 2107 | # Use the properties handlers to print out bug information if available |
319 | 2106 | def _bugs_properties_handler(revision): | 2108 | def _bugs_properties_handler(revision): |
320 | 2107 | 2109 | ||
321 | === modified file 'bzrlib/mail_client.py' | |||
322 | --- bzrlib/mail_client.py 2012-02-01 19:55:27 +0000 | |||
323 | +++ bzrlib/mail_client.py 2012-03-31 14:09:30 +0000 | |||
324 | @@ -33,7 +33,8 @@ | |||
325 | 33 | registry | 33 | registry |
326 | 34 | ) | 34 | ) |
327 | 35 | 35 | ||
329 | 36 | mail_client_registry = registry.Registry() | 36 | mail_client_registry = registry.Registry("bzrlib.mail_client", |
330 | 37 | "mail_client_registry") | ||
331 | 37 | 38 | ||
332 | 38 | 39 | ||
333 | 39 | class MailClient(object): | 40 | class MailClient(object): |
334 | 40 | 41 | ||
335 | === modified file 'bzrlib/merge.py' | |||
336 | --- bzrlib/merge.py 2012-03-14 09:30:48 +0000 | |||
337 | +++ bzrlib/merge.py 2012-03-31 14:09:30 +0000 | |||
338 | @@ -1956,7 +1956,7 @@ | |||
339 | 1956 | return merger.do_merge() | 1956 | return merger.do_merge() |
340 | 1957 | 1957 | ||
341 | 1958 | 1958 | ||
343 | 1959 | merge_type_registry = registry.Registry() | 1959 | merge_type_registry = registry.Registry("bzrlib.merge", "merge_type_registry") |
344 | 1960 | merge_type_registry.register('diff3', Diff3Merger, | 1960 | merge_type_registry.register('diff3', Diff3Merger, |
345 | 1961 | "Merge using external diff3.") | 1961 | "Merge using external diff3.") |
346 | 1962 | merge_type_registry.register('lca', LCAMerger, | 1962 | merge_type_registry.register('lca', LCAMerger, |
347 | 1963 | 1963 | ||
348 | === modified file 'bzrlib/merge_directive.py' | |||
349 | --- bzrlib/merge_directive.py 2012-02-07 00:49:58 +0000 | |||
350 | +++ bzrlib/merge_directive.py 2012-03-31 14:09:30 +0000 | |||
351 | @@ -674,7 +674,8 @@ | |||
352 | 674 | registry.Registry.register(self, format_string, directive) | 674 | registry.Registry.register(self, format_string, directive) |
353 | 675 | 675 | ||
354 | 676 | 676 | ||
356 | 677 | _format_registry = MergeDirectiveFormatRegistry() | 677 | _format_registry = MergeDirectiveFormatRegistry("bzrlib.merge_directive", |
357 | 678 | "_format_registry") | ||
358 | 678 | _format_registry.register(MergeDirective) | 679 | _format_registry.register(MergeDirective) |
359 | 679 | _format_registry.register(MergeDirective2) | 680 | _format_registry.register(MergeDirective2) |
360 | 680 | # 0.19 never existed. It got renamed to 0.90. But by that point, there were | 681 | # 0.19 never existed. It got renamed to 0.90. But by that point, there were |
361 | 681 | 682 | ||
362 | === modified file 'bzrlib/option.py' | |||
363 | --- bzrlib/option.py 2011-12-18 12:46:49 +0000 | |||
364 | +++ bzrlib/option.py 2012-03-31 14:09:30 +0000 | |||
365 | @@ -370,7 +370,7 @@ | |||
366 | 370 | RegistryOption constructor. Any other keyword arguments are treated | 370 | RegistryOption constructor. Any other keyword arguments are treated |
367 | 371 | as values for the option, and their value is treated as the help. | 371 | as values for the option, and their value is treated as the help. |
368 | 372 | """ | 372 | """ |
370 | 373 | reg = _mod_registry.Registry() | 373 | reg = _mod_registry.Registry(None, None) |
371 | 374 | for name, switch_help in sorted(kwargs.items()): | 374 | for name, switch_help in sorted(kwargs.items()): |
372 | 375 | name = name.replace('_', '-') | 375 | name = name.replace('_', '-') |
373 | 376 | reg.register(name, name, help=switch_help) | 376 | reg.register(name, name, help=switch_help) |
374 | @@ -570,6 +570,6 @@ | |||
375 | 570 | type=str, | 570 | type=str, |
376 | 571 | help='Display timezone as local, original, or utc.') | 571 | help='Display timezone as local, original, or utc.') |
377 | 572 | 572 | ||
379 | 573 | diff_writer_registry = _mod_registry.Registry() | 573 | diff_writer_registry = _mod_registry.Registry("bzrlib.option", "diff_writer_registry") |
380 | 574 | diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.') | 574 | diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.') |
381 | 575 | diff_writer_registry.default_key = 'plain' | 575 | diff_writer_registry.default_key = 'plain' |
382 | 576 | 576 | ||
383 | === modified file 'bzrlib/plugins/launchpad/__init__.py' | |||
384 | --- bzrlib/plugins/launchpad/__init__.py 2012-03-10 19:11:06 +0000 | |||
385 | +++ bzrlib/plugins/launchpad/__init__.py 2012-03-31 14:09:30 +0000 | |||
386 | @@ -53,8 +53,8 @@ | |||
387 | 53 | from bzrlib.commands import ( | 53 | from bzrlib.commands import ( |
388 | 54 | plugin_cmds, | 54 | plugin_cmds, |
389 | 55 | ) | 55 | ) |
392 | 56 | from bzrlib.directory_service import directories | 56 | from bzrlib.hooks import install_lazy_named_hook |
393 | 57 | from bzrlib.help_topics import topic_registry | 57 | from bzrlib.registry import register_lazy |
394 | 58 | 58 | ||
395 | 59 | for klsname, aliases in [ | 59 | for klsname, aliases in [ |
396 | 60 | ("cmd_register_branch", []), | 60 | ("cmd_register_branch", []), |
397 | @@ -68,16 +68,15 @@ | |||
398 | 68 | 68 | ||
399 | 69 | 69 | ||
400 | 70 | def _register_directory(): | 70 | def _register_directory(): |
405 | 71 | directories.register_lazy('lp:', 'bzrlib.plugins.launchpad.lp_directory', | 71 | register_lazy("bzrlib.directory_service", "directories", 'lp:', |
406 | 72 | 'LaunchpadDirectory', | 72 | 'bzrlib.plugins.launchpad.lp_directory', 'LaunchpadDirectory', |
407 | 73 | 'Launchpad-based directory service',) | 73 | 'Launchpad-based directory service',) |
408 | 74 | directories.register_lazy( | 74 | register_lazy("bzrlib.directory_service", "directories", |
409 | 75 | 'debianlp:', 'bzrlib.plugins.launchpad.lp_directory', | 75 | 'debianlp:', 'bzrlib.plugins.launchpad.lp_directory', |
410 | 76 | 'LaunchpadDirectory', | 76 | 'LaunchpadDirectory', |
411 | 77 | 'debianlp: shortcut') | 77 | 'debianlp: shortcut') |
415 | 78 | directories.register_lazy( | 78 | register_lazy("bzrlib.directory_service", "directories", 'ubuntu:', |
416 | 79 | 'ubuntu:', 'bzrlib.plugins.launchpad.lp_directory', | 79 | 'bzrlib.plugins.launchpad.lp_directory', 'LaunchpadDirectory', |
414 | 80 | 'LaunchpadDirectory', | ||
417 | 81 | 'ubuntu: shortcut') | 80 | 'ubuntu: shortcut') |
418 | 82 | 81 | ||
419 | 83 | _register_directory() | 82 | _register_directory() |
420 | @@ -132,7 +131,7 @@ | |||
421 | 132 | 131 | ||
422 | 133 | 132 | ||
423 | 134 | def _register_hooks(): | 133 | def _register_hooks(): |
425 | 135 | _mod_branch.Branch.hooks.install_named_hook('open', | 134 | install_lazy_named_hook("bzrlib.branch", "Branch.hooks", 'open', |
426 | 136 | _check_is_up_to_date, 'package-branch-up-to-date') | 135 | _check_is_up_to_date, 'package-branch-up-to-date') |
427 | 137 | 136 | ||
428 | 138 | 137 | ||
429 | @@ -184,8 +183,8 @@ | |||
430 | 184 | 183 | ||
431 | 185 | For more information see http://help.launchpad.net/ | 184 | For more information see http://help.launchpad.net/ |
432 | 186 | """ | 185 | """ |
435 | 187 | topic_registry.register('launchpad', | 186 | register_lazy('bzrlib.help_topics', 'topic_registry', 'launchpad', |
436 | 188 | _launchpad_help, | 187 | "bzrlib.plugins.launchpad", "_launchpad_help", |
437 | 189 | 'Using Bazaar with Launchpad.net') | 188 | 'Using Bazaar with Launchpad.net') |
438 | 190 | 189 | ||
439 | 191 | _mod_config.option_registry.register( | 190 | _mod_config.option_registry.register( |
440 | 192 | 191 | ||
441 | === modified file 'bzrlib/plugins/netrc_credential_store/__init__.py' | |||
442 | --- bzrlib/plugins/netrc_credential_store/__init__.py 2011-12-18 12:46:49 +0000 | |||
443 | +++ bzrlib/plugins/netrc_credential_store/__init__.py 2012-03-31 14:09:30 +0000 | |||
444 | @@ -25,6 +25,7 @@ | |||
445 | 25 | config, | 25 | config, |
446 | 26 | lazy_import, | 26 | lazy_import, |
447 | 27 | ) | 27 | ) |
448 | 28 | from bzrlib.registry import register_lazy | ||
449 | 28 | 29 | ||
450 | 29 | lazy_import.lazy_import(globals(), """ | 30 | lazy_import.lazy_import(globals(), """ |
451 | 30 | import errno | 31 | import errno |
452 | @@ -62,7 +63,7 @@ | |||
453 | 62 | return password | 63 | return password |
454 | 63 | 64 | ||
455 | 64 | 65 | ||
457 | 65 | config.credential_store_registry.register_lazy( | 66 | register_lazy("bzrlib.config", "credential_store_registry", |
458 | 66 | 'netrc', __name__, 'NetrcCredentialStore', help=__doc__) | 67 | 'netrc', __name__, 'NetrcCredentialStore', help=__doc__) |
459 | 67 | 68 | ||
460 | 68 | 69 | ||
461 | 69 | 70 | ||
462 | === modified file 'bzrlib/plugins/po_merge/__init__.py' | |||
463 | --- bzrlib/plugins/po_merge/__init__.py 2011-12-20 22:09:13 +0000 | |||
464 | +++ bzrlib/plugins/po_merge/__init__.py 2012-03-31 14:09:30 +0000 | |||
465 | @@ -54,15 +54,15 @@ | |||
466 | 54 | """ | 54 | """ |
467 | 55 | 55 | ||
468 | 56 | from bzrlib import ( | 56 | from bzrlib import ( |
469 | 57 | config, | ||
470 | 58 | # Since we are a built-in plugin we share the bzrlib version | 57 | # Since we are a built-in plugin we share the bzrlib version |
471 | 59 | version_info, | 58 | version_info, |
472 | 60 | ) | 59 | ) |
473 | 61 | from bzrlib.hooks import install_lazy_named_hook | 60 | from bzrlib.hooks import install_lazy_named_hook |
474 | 61 | from bzrlib.registry import register_lazy | ||
475 | 62 | 62 | ||
476 | 63 | 63 | ||
477 | 64 | def register_lazy_option(key, member): | 64 | def register_lazy_option(key, member): |
479 | 65 | config.option_registry.register_lazy( | 65 | register_lazy("bzrlib.config", "option_registry", |
480 | 66 | key, 'bzrlib.plugins.po_merge.po_merge', member) | 66 | key, 'bzrlib.plugins.po_merge.po_merge', member) |
481 | 67 | 67 | ||
482 | 68 | 68 | ||
483 | 69 | 69 | ||
484 | === modified file 'bzrlib/plugins/weave_fmt/__init__.py' | |||
485 | --- bzrlib/plugins/weave_fmt/__init__.py 2011-12-18 12:46:49 +0000 | |||
486 | +++ bzrlib/plugins/weave_fmt/__init__.py 2012-03-31 14:09:30 +0000 | |||
487 | @@ -28,9 +28,9 @@ | |||
488 | 28 | branch as _mod_branch, | 28 | branch as _mod_branch, |
489 | 29 | controldir, | 29 | controldir, |
490 | 30 | repository as _mod_repository, | 30 | repository as _mod_repository, |
491 | 31 | serializer, | ||
492 | 32 | workingtree as _mod_workingtree, | 31 | workingtree as _mod_workingtree, |
493 | 33 | ) | 32 | ) |
494 | 33 | from bzrlib.registry import register_lazy | ||
495 | 34 | from bzrlib.bzrdir import ( | 34 | from bzrlib.bzrdir import ( |
496 | 35 | BzrProber, | 35 | BzrProber, |
497 | 36 | register_metadir, | 36 | register_metadir, |
498 | @@ -114,8 +114,8 @@ | |||
499 | 114 | 'bzrlib.plugins.weave_fmt.workingtree', | 114 | 'bzrlib.plugins.weave_fmt.workingtree', |
500 | 115 | 'WorkingTreeFormat2') | 115 | 'WorkingTreeFormat2') |
501 | 116 | 116 | ||
504 | 117 | serializer.format_registry.register_lazy('4', 'bzrlib.plugins.weave_fmt.xml4', | 117 | register_lazy("bzrlib.serializer", "format_registry", '4', |
505 | 118 | 'serializer_v4') | 118 | 'bzrlib.plugins.weave_fmt.xml4', 'serializer_v4') |
506 | 119 | 119 | ||
507 | 120 | def load_tests(basic_tests, module, loader): | 120 | def load_tests(basic_tests, module, loader): |
508 | 121 | testmod_names = [ | 121 | testmod_names = [ |
509 | 122 | 122 | ||
510 | === modified file 'bzrlib/registry.py' | |||
511 | --- bzrlib/registry.py 2011-12-19 13:23:58 +0000 | |||
512 | +++ bzrlib/registry.py 2012-03-31 14:09:30 +0000 | |||
513 | @@ -18,6 +18,8 @@ | |||
514 | 18 | 18 | ||
515 | 19 | from __future__ import absolute_import | 19 | from __future__ import absolute_import |
516 | 20 | 20 | ||
517 | 21 | import collections | ||
518 | 22 | |||
519 | 21 | from bzrlib.pyutils import get_named_object | 23 | from bzrlib.pyutils import get_named_object |
520 | 22 | 24 | ||
521 | 23 | 25 | ||
522 | @@ -81,6 +83,16 @@ | |||
523 | 81 | self._module_name, self._member_name, self._imported) | 83 | self._module_name, self._member_name, self._imported) |
524 | 82 | 84 | ||
525 | 83 | 85 | ||
526 | 86 | """\ | ||
527 | 87 | Entry in a registry | ||
528 | 88 | |||
529 | 89 | :ivar objgetter: _ObjectGetter instance which can provide the actual object | ||
530 | 90 | :ivar info: Info object (registry-dependent) | ||
531 | 91 | :ivar help: Help string | ||
532 | 92 | """ | ||
533 | 93 | RegistryEntry = collections.namedtuple('RegistryEntry', 'objgetter info help') | ||
534 | 94 | |||
535 | 95 | |||
536 | 84 | class Registry(object): | 96 | class Registry(object): |
537 | 85 | """A class that registers objects to a name. | 97 | """A class that registers objects to a name. |
538 | 86 | 98 | ||
539 | @@ -97,13 +109,23 @@ | |||
540 | 97 | will return the entry for the default key. | 109 | will return the entry for the default key. |
541 | 98 | """ | 110 | """ |
542 | 99 | 111 | ||
545 | 100 | def __init__(self): | 112 | def __init__(self, module=None, member_name=None): |
546 | 101 | """Create a new Registry.""" | 113 | """Create a new Registry. |
547 | 114 | |||
548 | 115 | :param module: Optional module registry is present in. Used | ||
549 | 116 | for lazy registration. | ||
550 | 117 | :param member_name: Optional member_name of registry in module. Used | ||
551 | 118 | for lazy registration. | ||
552 | 119 | |||
553 | 120 | If module and member_name aren't specified, then lazy registration is | ||
554 | 121 | not supported. | ||
555 | 122 | """ | ||
556 | 102 | self._default_key = None | 123 | self._default_key = None |
557 | 103 | # Map from key => (is_lazy, info) | 124 | # Map from key => (is_lazy, info) |
561 | 104 | self._dict = {} | 125 | if module is not None and member_name is not None: |
562 | 105 | self._help_dict = {} | 126 | self._dict = _lazy_registries.setdefault((module, member_name), {}) |
563 | 106 | self._info_dict = {} | 127 | else: |
564 | 128 | self._dict = {} | ||
565 | 107 | 129 | ||
566 | 108 | def register(self, key, obj, help=None, info=None, | 130 | def register(self, key, obj, help=None, info=None, |
567 | 109 | override_existing=False): | 131 | override_existing=False): |
568 | @@ -125,8 +147,7 @@ | |||
569 | 125 | if not override_existing: | 147 | if not override_existing: |
570 | 126 | if key in self._dict: | 148 | if key in self._dict: |
571 | 127 | raise KeyError('Key %r already registered' % key) | 149 | raise KeyError('Key %r already registered' % key) |
574 | 128 | self._dict[key] = _ObjectGetter(obj) | 150 | self._dict[key] = RegistryEntry(_ObjectGetter(obj), info, help) |
573 | 129 | self._add_help_and_info(key, help=help, info=info) | ||
575 | 130 | 151 | ||
576 | 131 | def register_lazy(self, key, module_name, member_name, | 152 | def register_lazy(self, key, module_name, member_name, |
577 | 132 | help=None, info=None, | 153 | help=None, info=None, |
578 | @@ -149,13 +170,8 @@ | |||
579 | 149 | if not override_existing: | 170 | if not override_existing: |
580 | 150 | if key in self._dict: | 171 | if key in self._dict: |
581 | 151 | raise KeyError('Key %r already registered' % key) | 172 | raise KeyError('Key %r already registered' % key) |
589 | 152 | self._dict[key] = _LazyObjectGetter(module_name, member_name) | 173 | self._dict[key] = RegistryEntry( |
590 | 153 | self._add_help_and_info(key, help=help, info=info) | 174 | _LazyObjectGetter(module_name, member_name), info, help) |
584 | 154 | |||
585 | 155 | def _add_help_and_info(self, key, help=None, info=None): | ||
586 | 156 | """Add the help and information about this key""" | ||
587 | 157 | self._help_dict[key] = help | ||
588 | 158 | self._info_dict[key] = info | ||
591 | 159 | 175 | ||
592 | 160 | def get(self, key=None): | 176 | def get(self, key=None): |
593 | 161 | """Return the object register()'ed to the given key. | 177 | """Return the object register()'ed to the given key. |
594 | @@ -174,7 +190,7 @@ | |||
595 | 174 | :raises AttributeError: If registered lazily, and the module does not | 190 | :raises AttributeError: If registered lazily, and the module does not |
596 | 175 | contain the registered member. | 191 | contain the registered member. |
597 | 176 | """ | 192 | """ |
599 | 177 | return self._dict[self._get_key_or_default(key)].get_obj() | 193 | return self._dict[self._get_key_or_default(key)].objgetter.get_obj() |
600 | 178 | 194 | ||
601 | 179 | def _get_module(self, key): | 195 | def _get_module(self, key): |
602 | 180 | """Return the module the object will be or was loaded from. | 196 | """Return the module the object will be or was loaded from. |
603 | @@ -182,7 +198,7 @@ | |||
604 | 182 | :param key: The key to obtain the module for. | 198 | :param key: The key to obtain the module for. |
605 | 183 | :return: The name of the module | 199 | :return: The name of the module |
606 | 184 | """ | 200 | """ |
608 | 185 | return self._dict[key].get_module() | 201 | return self._dict[key].objgetter.get_module() |
609 | 186 | 202 | ||
610 | 187 | def get_prefix(self, fullname): | 203 | def get_prefix(self, fullname): |
611 | 188 | """Return an object whose key is a prefix of the supplied value. | 204 | """Return an object whose key is a prefix of the supplied value. |
612 | @@ -206,14 +222,14 @@ | |||
613 | 206 | 222 | ||
614 | 207 | def get_help(self, key=None): | 223 | def get_help(self, key=None): |
615 | 208 | """Get the help text associated with the given key""" | 224 | """Get the help text associated with the given key""" |
617 | 209 | the_help = self._help_dict[self._get_key_or_default(key)] | 225 | the_help = self._dict[self._get_key_or_default(key)].help |
618 | 210 | if callable(the_help): | 226 | if callable(the_help): |
619 | 211 | return the_help(self, key) | 227 | return the_help(self, key) |
620 | 212 | return the_help | 228 | return the_help |
621 | 213 | 229 | ||
622 | 214 | def get_info(self, key=None): | 230 | def get_info(self, key=None): |
623 | 215 | """Get the extra information associated with the given key""" | 231 | """Get the extra information associated with the given key""" |
625 | 216 | return self._info_dict[self._get_key_or_default(key)] | 232 | return self._dict[self._get_key_or_default(key)].info |
626 | 217 | 233 | ||
627 | 218 | def remove(self, key): | 234 | def remove(self, key): |
628 | 219 | """Remove a registered entry. | 235 | """Remove a registered entry. |
629 | @@ -230,14 +246,14 @@ | |||
630 | 230 | return sorted(self._dict.keys()) | 246 | return sorted(self._dict.keys()) |
631 | 231 | 247 | ||
632 | 232 | def iteritems(self): | 248 | def iteritems(self): |
635 | 233 | for key, getter in self._dict.iteritems(): | 249 | for key, entry in self._dict.iteritems(): |
636 | 234 | yield key, getter.get_obj() | 250 | yield key, entry.objgetter.get_obj() |
637 | 235 | 251 | ||
638 | 236 | def items(self): | 252 | def items(self): |
639 | 237 | # We should not use the iteritems() implementation below (see bug | 253 | # We should not use the iteritems() implementation below (see bug |
640 | 238 | # #430510) | 254 | # #430510) |
643 | 239 | return sorted([(key, getter.get_obj()) | 255 | return sorted([(key, entry.objgetter.get_obj()) |
644 | 240 | for key, getter in self._dict.items()]) | 256 | for key, entry in self._dict.items()]) |
645 | 241 | 257 | ||
646 | 242 | def _set_default_key(self, key): | 258 | def _set_default_key(self, key): |
647 | 243 | if not self._dict.has_key(key): | 259 | if not self._dict.has_key(key): |
648 | @@ -256,8 +272,9 @@ | |||
649 | 256 | class FormatRegistry(Registry): | 272 | class FormatRegistry(Registry): |
650 | 257 | """Registry specialised for handling formats.""" | 273 | """Registry specialised for handling formats.""" |
651 | 258 | 274 | ||
654 | 259 | def __init__(self, other_registry=None): | 275 | def __init__(self, module_name=None, member_name=None, |
655 | 260 | Registry.__init__(self) | 276 | other_registry=None): |
656 | 277 | Registry.__init__(self, module_name, member_name) | ||
657 | 261 | self._other_registry = other_registry | 278 | self._other_registry = other_registry |
658 | 262 | 279 | ||
659 | 263 | def register(self, key, obj, help=None, info=None, | 280 | def register(self, key, obj, help=None, info=None, |
660 | @@ -289,3 +306,42 @@ | |||
661 | 289 | if callable(r): | 306 | if callable(r): |
662 | 290 | r = r() | 307 | r = r() |
663 | 291 | return r | 308 | return r |
664 | 309 | |||
665 | 310 | |||
666 | 311 | # Lazily registered registries. | ||
667 | 312 | # Maps (module, registry_member_name) -> registry_dict | ||
668 | 313 | # | ||
669 | 314 | # A registry dict maps a key to a RegistryEntry | ||
670 | 315 | # | ||
671 | 316 | # A Registry is associated with either its own private dictionary or | ||
672 | 317 | # a dictionary based in _lazy_registries, if a module name and member name | ||
673 | 318 | # were specified during its creation. | ||
674 | 319 | # | ||
675 | 320 | # The internal registry dictionaries live here so entries can be added | ||
676 | 321 | # without having to load the actual registry. | ||
677 | 322 | _lazy_registries = {} | ||
678 | 323 | |||
679 | 324 | |||
680 | 325 | def register_lazy(registry_module, registry_name, key, entry_module, | ||
681 | 326 | entry_name, help=None, info=None, override_existing=False): | ||
682 | 327 | """Lazily register an entry in a registry that's not yet loaded. | ||
683 | 328 | |||
684 | 329 | :param registry_module: Name of the module in which the registry lives | ||
685 | 330 | :param registry_name: Python name of the registry | ||
686 | 331 | :param key: Key of the entry in the registry | ||
687 | 332 | :param entry_module: Module name for the entry | ||
688 | 333 | :param entry_name: Python name of the entry | ||
689 | 334 | :param info: Optional info object | ||
690 | 335 | :param help: Optional help description | ||
691 | 336 | :param override_existing: Whether to allow overriding existing | ||
692 | 337 | entries | ||
693 | 338 | """ | ||
694 | 339 | # Find the internal registry dict for the specified registry. | ||
695 | 340 | registry_dict = _lazy_registries.setdefault( | ||
696 | 341 | (registry_module, registry_name), {}) | ||
697 | 342 | if not override_existing: | ||
698 | 343 | if key in registry_dict: | ||
699 | 344 | raise KeyError('Key %r already registered' % key) | ||
700 | 345 | obj_getter = _LazyObjectGetter(entry_module, entry_name) | ||
701 | 346 | # Add the entry to the registry dict. | ||
702 | 347 | registry_dict[key] = RegistryEntry(obj_getter, info, help) | ||
703 | 292 | 348 | ||
704 | === modified file 'bzrlib/remote.py' | |||
705 | --- bzrlib/remote.py 2012-03-14 14:17:48 +0000 | |||
706 | +++ bzrlib/remote.py 2012-03-31 14:09:30 +0000 | |||
707 | @@ -4139,8 +4139,9 @@ | |||
708 | 4139 | tar.extract(tarinfo, to_dir) | 4139 | tar.extract(tarinfo, to_dir) |
709 | 4140 | 4140 | ||
710 | 4141 | 4141 | ||
713 | 4142 | error_translators = registry.Registry() | 4142 | error_translators = registry.Registry("bzrlib.remote", "error_translators") |
714 | 4143 | no_context_error_translators = registry.Registry() | 4143 | no_context_error_translators = registry.Registry("bzrlib.remote", |
715 | 4144 | "no_context_error_translators") | ||
716 | 4144 | 4145 | ||
717 | 4145 | 4146 | ||
718 | 4146 | def _translate_error(err, **context): | 4147 | def _translate_error(err, **context): |
719 | 4147 | 4148 | ||
720 | === modified file 'bzrlib/repository.py' | |||
721 | --- bzrlib/repository.py 2012-03-29 12:27:52 +0000 | |||
722 | +++ bzrlib/repository.py 2012-03-31 14:09:30 +0000 | |||
723 | @@ -1324,7 +1324,8 @@ | |||
724 | 1324 | return controldir.format_registry.make_bzrdir('default').repository_format | 1324 | return controldir.format_registry.make_bzrdir('default').repository_format |
725 | 1325 | 1325 | ||
726 | 1326 | 1326 | ||
728 | 1327 | network_format_registry = registry.FormatRegistry() | 1327 | network_format_registry = registry.FormatRegistry("bzrlib.repository", |
729 | 1328 | "network_format_registry") | ||
730 | 1328 | """Registry of formats indexed by their network name. | 1329 | """Registry of formats indexed by their network name. |
731 | 1329 | 1330 | ||
732 | 1330 | The network name for a repository format is an identifier that can be used when | 1331 | The network name for a repository format is an identifier that can be used when |
733 | @@ -1333,7 +1334,8 @@ | |||
734 | 1333 | """ | 1334 | """ |
735 | 1334 | 1335 | ||
736 | 1335 | 1336 | ||
738 | 1336 | format_registry = RepositoryFormatRegistry(network_format_registry) | 1337 | format_registry = RepositoryFormatRegistry("bzrlib.repository", |
739 | 1338 | "format_registry", network_format_registry) | ||
740 | 1337 | """Registry of formats, indexed by their BzrDirMetaFormat format string. | 1339 | """Registry of formats, indexed by their BzrDirMetaFormat format string. |
741 | 1338 | 1340 | ||
742 | 1339 | This can contain either format instances themselves, or classes/factories that | 1341 | This can contain either format instances themselves, or classes/factories that |
743 | 1340 | 1342 | ||
744 | === modified file 'bzrlib/revisionspec.py' | |||
745 | --- bzrlib/revisionspec.py 2011-12-19 10:58:39 +0000 | |||
746 | +++ bzrlib/revisionspec.py 2012-03-31 14:09:30 +0000 | |||
747 | @@ -992,7 +992,7 @@ | |||
748 | 992 | RevisionSpec_dwim.append_possible_revspec(RevisionSpec_date) | 992 | RevisionSpec_dwim.append_possible_revspec(RevisionSpec_date) |
749 | 993 | RevisionSpec_dwim.append_possible_revspec(RevisionSpec_branch) | 993 | RevisionSpec_dwim.append_possible_revspec(RevisionSpec_branch) |
750 | 994 | 994 | ||
752 | 995 | revspec_registry = registry.Registry() | 995 | revspec_registry = registry.Registry("bzrlib.revisionspec", "revspec_registry") |
753 | 996 | def _register_revspec(revspec): | 996 | def _register_revspec(revspec): |
754 | 997 | revspec_registry.register(revspec.prefix, revspec) | 997 | revspec_registry.register(revspec.prefix, revspec) |
755 | 998 | 998 | ||
756 | 999 | 999 | ||
757 | === modified file 'bzrlib/send.py' | |||
758 | --- bzrlib/send.py 2012-02-01 19:18:09 +0000 | |||
759 | +++ bzrlib/send.py 2012-03-31 14:09:30 +0000 | |||
760 | @@ -35,7 +35,7 @@ | |||
761 | 35 | ) | 35 | ) |
762 | 36 | 36 | ||
763 | 37 | 37 | ||
765 | 38 | format_registry = registry.Registry() | 38 | format_registry = registry.Registry("bzrlib.send", "format_registry") |
766 | 39 | 39 | ||
767 | 40 | 40 | ||
768 | 41 | def send(target_branch, revision, public_branch, remember, | 41 | def send(target_branch, revision, public_branch, remember, |
769 | 42 | 42 | ||
770 | === modified file 'bzrlib/serializer.py' | |||
771 | --- bzrlib/serializer.py 2011-12-19 13:23:58 +0000 | |||
772 | +++ bzrlib/serializer.py 2012-03-31 14:09:30 +0000 | |||
773 | @@ -92,7 +92,7 @@ | |||
774 | 92 | """Registry for serializer objects""" | 92 | """Registry for serializer objects""" |
775 | 93 | 93 | ||
776 | 94 | 94 | ||
778 | 95 | format_registry = SerializerRegistry() | 95 | format_registry = SerializerRegistry("bzrlib.serializer", "format_registry") |
779 | 96 | format_registry.register_lazy('5', 'bzrlib.xml5', 'serializer_v5') | 96 | format_registry.register_lazy('5', 'bzrlib.xml5', 'serializer_v5') |
780 | 97 | format_registry.register_lazy('6', 'bzrlib.xml6', 'serializer_v6') | 97 | format_registry.register_lazy('6', 'bzrlib.xml6', 'serializer_v6') |
781 | 98 | format_registry.register_lazy('7', 'bzrlib.xml7', 'serializer_v7') | 98 | format_registry.register_lazy('7', 'bzrlib.xml7', 'serializer_v7') |
782 | 99 | 99 | ||
783 | === modified file 'bzrlib/smart/request.py' | |||
784 | --- bzrlib/smart/request.py 2012-02-23 23:26:35 +0000 | |||
785 | +++ bzrlib/smart/request.py 2012-03-31 14:09:30 +0000 | |||
786 | @@ -521,7 +521,7 @@ | |||
787 | 521 | # mutate State is updated in a way that replaying that request results in a | 521 | # mutate State is updated in a way that replaying that request results in a |
788 | 522 | # different state. For example 'append' writes more bytes to a given | 522 | # different state. For example 'append' writes more bytes to a given |
789 | 523 | # file. If append succeeds, it moves the file pointer. | 523 | # file. If append succeeds, it moves the file pointer. |
791 | 524 | request_handlers = registry.Registry() | 524 | request_handlers = registry.Registry("bzrlib.smart.request", "request_handlers") |
792 | 525 | request_handlers.register_lazy( | 525 | request_handlers.register_lazy( |
793 | 526 | 'append', 'bzrlib.smart.vfs', 'AppendRequest', info='mutate') | 526 | 'append', 'bzrlib.smart.vfs', 'AppendRequest', info='mutate') |
794 | 527 | request_handlers.register_lazy( | 527 | request_handlers.register_lazy( |
795 | 528 | 528 | ||
796 | === modified file 'bzrlib/tag.py' | |||
797 | --- bzrlib/tag.py 2011-12-19 13:23:58 +0000 | |||
798 | +++ bzrlib/tag.py 2012-03-31 14:09:30 +0000 | |||
799 | @@ -421,7 +421,7 @@ | |||
800 | 421 | tags.sort(key=lambda x: timestamps[x[1]]) | 421 | tags.sort(key=lambda x: timestamps[x[1]]) |
801 | 422 | 422 | ||
802 | 423 | 423 | ||
804 | 424 | tag_sort_methods = Registry() | 424 | tag_sort_methods = Registry("bzrlib.tag", "tag_sort_methods") |
805 | 425 | tag_sort_methods.register("natural", sort_natural, | 425 | tag_sort_methods.register("natural", sort_natural, |
806 | 426 | 'Sort numeric substrings as numbers. (default)') | 426 | 'Sort numeric substrings as numbers. (default)') |
807 | 427 | tag_sort_methods.register("alpha", sort_alpha, 'Sort tags lexicographically.') | 427 | tag_sort_methods.register("alpha", sort_alpha, 'Sort tags lexicographically.') |
808 | 428 | 428 | ||
809 | === modified file 'bzrlib/tests/__init__.py' | |||
810 | --- bzrlib/tests/__init__.py 2012-03-13 09:07:18 +0000 | |||
811 | +++ bzrlib/tests/__init__.py 2012-03-31 14:09:30 +0000 | |||
812 | @@ -3328,7 +3328,7 @@ | |||
813 | 3328 | 3328 | ||
814 | 3329 | 3329 | ||
815 | 3330 | # A registry where get() returns a suite decorator. | 3330 | # A registry where get() returns a suite decorator. |
817 | 3331 | parallel_registry = registry.Registry() | 3331 | parallel_registry = registry.Registry("bzrlib.tests", "parallel_registry") |
818 | 3332 | 3332 | ||
819 | 3333 | 3333 | ||
820 | 3334 | def fork_decorator(suite): | 3334 | def fork_decorator(suite): |
821 | @@ -3884,7 +3884,8 @@ | |||
822 | 3884 | return '.'.join(parts) | 3884 | return '.'.join(parts) |
823 | 3885 | 3885 | ||
824 | 3886 | 3886 | ||
826 | 3887 | test_prefix_alias_registry = TestPrefixAliasRegistry() | 3887 | test_prefix_alias_registry = TestPrefixAliasRegistry("bzrlib.tests", |
827 | 3888 | "test_prefix_alias_registry") | ||
828 | 3888 | """Registry of test prefix aliases.""" | 3889 | """Registry of test prefix aliases.""" |
829 | 3889 | 3890 | ||
830 | 3890 | 3891 | ||
831 | 3891 | 3892 | ||
832 | === modified file 'bzrlib/tests/test_foreign.py' | |||
833 | --- bzrlib/tests/test_foreign.py 2012-02-23 19:45:15 +0000 | |||
834 | +++ bzrlib/tests/test_foreign.py 2012-03-31 14:09:30 +0000 | |||
835 | @@ -76,7 +76,7 @@ | |||
836 | 76 | """ | 76 | """ |
837 | 77 | 77 | ||
838 | 78 | def __init__(self): | 78 | def __init__(self): |
840 | 79 | self.mapping_registry = DummyForeignVcsMappingRegistry() | 79 | self.mapping_registry = DummyForeignVcsMappingRegistry(None, None) |
841 | 80 | self.mapping_registry.register("v1", DummyForeignVcsMapping(self), | 80 | self.mapping_registry.register("v1", DummyForeignVcsMapping(self), |
842 | 81 | "Version 1") | 81 | "Version 1") |
843 | 82 | self.abbreviation = "dummy" | 82 | self.abbreviation = "dummy" |
844 | 83 | 83 | ||
845 | === modified file 'bzrlib/tests/test_registry.py' | |||
846 | --- bzrlib/tests/test_registry.py 2012-01-25 21:13:15 +0000 | |||
847 | +++ bzrlib/tests/test_registry.py 2012-03-31 14:09:30 +0000 | |||
848 | @@ -22,6 +22,7 @@ | |||
849 | 22 | from bzrlib import ( | 22 | from bzrlib import ( |
850 | 23 | branch, | 23 | branch, |
851 | 24 | osutils, | 24 | osutils, |
852 | 25 | pyutils, | ||
853 | 25 | registry, | 26 | registry, |
854 | 26 | tests, | 27 | tests, |
855 | 27 | ) | 28 | ) |
856 | @@ -238,7 +239,7 @@ | |||
857 | 238 | # We peek under the covers because the alternative is to use lazy | 239 | # We peek under the covers because the alternative is to use lazy |
858 | 239 | # registration and create a module that can reference our test registry | 240 | # registration and create a module that can reference our test registry |
859 | 240 | # it's too much work for such a corner case -- vila 090916 | 241 | # it's too much work for such a corner case -- vila 090916 |
861 | 241 | self.registry._dict['hacky'] = InvasiveGetter(None) | 242 | self.registry._dict['hacky'] = registry.RegistryEntry(InvasiveGetter(None), None, None) |
862 | 242 | 243 | ||
863 | 243 | def _iter_them(self, iter_func_name): | 244 | def _iter_them(self, iter_func_name): |
864 | 244 | iter_func = getattr(self.registry, iter_func_name, None) | 245 | iter_func = getattr(self.registry, iter_func_name, None) |
865 | @@ -354,3 +355,41 @@ | |||
866 | 354 | a_registry.register("obj", AThing()) | 355 | a_registry.register("obj", AThing()) |
867 | 355 | self.assertEquals("bzrlib.tests.test_registry", | 356 | self.assertEquals("bzrlib.tests.test_registry", |
868 | 356 | a_registry._get_module("obj")) | 357 | a_registry._get_module("obj")) |
869 | 358 | |||
870 | 359 | |||
871 | 360 | |||
872 | 361 | class TestLazyRegistry(tests.TestCase): | ||
873 | 362 | """Test bzrlib.registry.register_lazy.""" | ||
874 | 363 | |||
875 | 364 | def test_valid_lazy_registries(self): | ||
876 | 365 | # Make sure that all the registered lazy hooks are referring to existing | ||
877 | 366 | # hook points which allow lazy registration. | ||
878 | 367 | for key, registry_dict in registry._lazy_registries.iteritems(): | ||
879 | 368 | (module_name, member_name) = key | ||
880 | 369 | obj = pyutils.get_named_object(module_name, member_name) | ||
881 | 370 | self.assertIsInstance(obj, registry.Registry) | ||
882 | 371 | self.assertIsInstance(registry_dict, dict) | ||
883 | 372 | self.assertIs(obj._dict, registry_dict) | ||
884 | 373 | |||
885 | 374 | def test_register_lazy(self): | ||
886 | 375 | # A lazily registered entry shows up if the registry is later created | ||
887 | 376 | registry.register_lazy("bzrlib.tests.test_registry", "SomeRegistry", | ||
888 | 377 | "myname", "bzrlib.tests.test_registry", "TestLazyRegistry", | ||
889 | 378 | help="HELLUP!", info="Informatief") | ||
890 | 379 | a_registry = registry.Registry("bzrlib.tests.test_registry", "SomeRegistry") | ||
891 | 380 | self.addCleanup(registry._lazy_registries.__delitem__, | ||
892 | 381 | ("bzrlib.tests.test_registry", "SomeRegistry")) | ||
893 | 382 | self.assertEquals([("myname", TestLazyRegistry)], a_registry.items()) | ||
894 | 383 | |||
895 | 384 | def test_register_lazy_dupe(self): | ||
896 | 385 | # Two registry entries can't be registered with the same name | ||
897 | 386 | registry.register_lazy("bzrlib.tests.test_registry", "SomeRegistry", | ||
898 | 387 | "myname", "bzrlib.tests.test_registry", "TestLazyRegistry") | ||
899 | 388 | self.addCleanup(registry._lazy_registries.__delitem__, | ||
900 | 389 | ("bzrlib.tests.test_registry", "SomeRegistry")) | ||
901 | 390 | self.assertRaises(KeyError, | ||
902 | 391 | registry.register_lazy, "bzrlib.tests.test_registry", "SomeRegistry", | ||
903 | 392 | "myname", "bzrlib.tests.test_registry", "TestLazyRegistry") | ||
904 | 393 | registry.register_lazy("bzrlib.tests.test_registry", "SomeRegistry", | ||
905 | 394 | "myname", "bzrlib.tests.test_registry", "TestLazyRegistry", | ||
906 | 395 | override_existing=True) | ||
907 | 357 | 396 | ||
908 | === modified file 'bzrlib/transform.py' | |||
909 | --- bzrlib/transform.py 2012-03-14 10:17:12 +0000 | |||
910 | +++ bzrlib/transform.py 2012-03-31 14:09:30 +0000 | |||
911 | @@ -1461,7 +1461,7 @@ | |||
912 | 1461 | raise OrphaningForbidden('never') | 1461 | raise OrphaningForbidden('never') |
913 | 1462 | 1462 | ||
914 | 1463 | 1463 | ||
916 | 1464 | orphaning_registry = registry.Registry() | 1464 | orphaning_registry = registry.Registry("bzrlib.transform", "orphaning_registry") |
917 | 1465 | orphaning_registry.register( | 1465 | orphaning_registry.register( |
918 | 1466 | 'conflict', refuse_orphan, | 1466 | 'conflict', refuse_orphan, |
919 | 1467 | 'Leave orphans in place and create a conflict on the directory.') | 1467 | 'Leave orphans in place and create a conflict on the directory.') |
920 | 1468 | 1468 | ||
921 | === modified file 'bzrlib/transport/__init__.py' | |||
922 | --- bzrlib/transport/__init__.py 2012-03-13 17:25:29 +0000 | |||
923 | +++ bzrlib/transport/__init__.py 2012-03-31 14:09:30 +0000 | |||
924 | @@ -123,7 +123,8 @@ | |||
925 | 123 | self.register(key, [], help) | 123 | self.register(key, [], help) |
926 | 124 | 124 | ||
927 | 125 | 125 | ||
929 | 126 | transport_list_registry = TransportListRegistry() | 126 | transport_list_registry = TransportListRegistry("bzrlib.transport", |
930 | 127 | "transport_list_registry") | ||
931 | 127 | 128 | ||
932 | 128 | 129 | ||
933 | 129 | def register_transport_proto(prefix, help=None, info=None, | 130 | def register_transport_proto(prefix, help=None, info=None, |
934 | @@ -1890,7 +1891,8 @@ | |||
935 | 1890 | 'HintingSSHTransport') | 1891 | 'HintingSSHTransport') |
936 | 1891 | 1892 | ||
937 | 1892 | 1893 | ||
939 | 1893 | transport_server_registry = registry.Registry() | 1894 | transport_server_registry = registry.Registry("bzrlib.transport", |
940 | 1895 | "transport_server_registry") | ||
941 | 1894 | transport_server_registry.register_lazy('bzr', 'bzrlib.smart.server', | 1896 | transport_server_registry.register_lazy('bzr', 'bzrlib.smart.server', |
942 | 1895 | 'serve_bzr', help="The Bazaar smart server protocol over TCP. (default port: 4155)") | 1897 | 'serve_bzr', help="The Bazaar smart server protocol over TCP. (default port: 4155)") |
943 | 1896 | transport_server_registry.default_key = 'bzr' | 1898 | transport_server_registry.default_key = 'bzr' |
944 | 1897 | 1899 | ||
945 | === modified file 'bzrlib/version_info_formats/__init__.py' | |||
946 | --- bzrlib/version_info_formats/__init__.py 2011-12-30 13:02:27 +0000 | |||
947 | +++ bzrlib/version_info_formats/__init__.py 2012-03-31 14:09:30 +0000 | |||
948 | @@ -186,8 +186,8 @@ | |||
949 | 186 | raise NotImplementedError(VersionInfoBuilder.generate) | 186 | raise NotImplementedError(VersionInfoBuilder.generate) |
950 | 187 | 187 | ||
951 | 188 | 188 | ||
954 | 189 | format_registry = registry.Registry() | 189 | format_registry = registry.Registry("bzrlib.version_info_formats", |
955 | 190 | 190 | "format_registry") | |
956 | 191 | 191 | ||
957 | 192 | format_registry.register_lazy( | 192 | format_registry.register_lazy( |
958 | 193 | 'rio', | 193 | 'rio', |
959 | 194 | 194 | ||
960 | === modified file 'bzrlib/versionedfile.py' | |||
961 | --- bzrlib/versionedfile.py 2011-12-19 13:23:58 +0000 | |||
962 | +++ bzrlib/versionedfile.py 2012-03-31 14:09:30 +0000 | |||
963 | @@ -45,7 +45,7 @@ | |||
964 | 45 | from bzrlib.textmerge import TextMerge | 45 | from bzrlib.textmerge import TextMerge |
965 | 46 | 46 | ||
966 | 47 | 47 | ||
968 | 48 | adapter_registry = Registry() | 48 | adapter_registry = Registry("bzrlib.versionedfile", "adapter_registry") |
969 | 49 | adapter_registry.register_lazy(('knit-delta-gz', 'fulltext'), 'bzrlib.knit', | 49 | adapter_registry.register_lazy(('knit-delta-gz', 'fulltext'), 'bzrlib.knit', |
970 | 50 | 'DeltaPlainToFullText') | 50 | 'DeltaPlainToFullText') |
971 | 51 | adapter_registry.register_lazy(('knit-ft-gz', 'fulltext'), 'bzrlib.knit', | 51 | adapter_registry.register_lazy(('knit-ft-gz', 'fulltext'), 'bzrlib.knit', |
972 | 52 | 52 | ||
973 | === modified file 'bzrlib/workingtree.py' | |||
974 | --- bzrlib/workingtree.py 2012-03-29 12:27:52 +0000 | |||
975 | +++ bzrlib/workingtree.py 2012-03-31 14:09:30 +0000 | |||
976 | @@ -2998,8 +2998,10 @@ | |||
977 | 2998 | class WorkingTreeFormatRegistry(controldir.ControlComponentFormatRegistry): | 2998 | class WorkingTreeFormatRegistry(controldir.ControlComponentFormatRegistry): |
978 | 2999 | """Registry for working tree formats.""" | 2999 | """Registry for working tree formats.""" |
979 | 3000 | 3000 | ||
982 | 3001 | def __init__(self, other_registry=None): | 3001 | def __init__(self, module_name=None, member_name=None, |
983 | 3002 | super(WorkingTreeFormatRegistry, self).__init__(other_registry) | 3002 | other_registry=None): |
984 | 3003 | super(WorkingTreeFormatRegistry, self).__init__(module_name, | ||
985 | 3004 | member_name, other_registry) | ||
986 | 3003 | self._default_format = None | 3005 | self._default_format = None |
987 | 3004 | self._default_format_key = None | 3006 | self._default_format_key = None |
988 | 3005 | 3007 | ||
989 | @@ -3021,7 +3023,8 @@ | |||
990 | 3021 | self._default_format = None | 3023 | self._default_format = None |
991 | 3022 | 3024 | ||
992 | 3023 | 3025 | ||
994 | 3024 | format_registry = WorkingTreeFormatRegistry() | 3026 | format_registry = WorkingTreeFormatRegistry("bzrlib.workingtree", |
995 | 3027 | "format_registry") | ||
996 | 3025 | 3028 | ||
997 | 3026 | 3029 | ||
998 | 3027 | class WorkingTreeFormat(controldir.ControlComponentFormat): | 3030 | class WorkingTreeFormat(controldir.ControlComponentFormat): |
999 | 3028 | 3031 | ||
1000 | === modified file 'doc/en/release-notes/bzr-2.6.txt' | |||
1001 | --- doc/en/release-notes/bzr-2.6.txt 2012-03-30 02:23:41 +0000 | |||
1002 | +++ doc/en/release-notes/bzr-2.6.txt 2012-03-31 14:09:30 +0000 | |||
1003 | @@ -157,6 +157,10 @@ | |||
1004 | 157 | * New method ``Repository.verify_revision_signatures``. | 157 | * New method ``Repository.verify_revision_signatures``. |
1005 | 158 | (Jelmer Vernooij) | 158 | (Jelmer Vernooij) |
1006 | 159 | 159 | ||
1007 | 160 | * New function ``bzrlib.registry.register_lazy`` which can | ||
1008 | 161 | register new keys into registries before they are loaded. | ||
1009 | 162 | (Jelmer Vernooij) | ||
1010 | 163 | |||
1011 | 160 | * New configuration option class ``RegistryOption`` which is backed | 164 | * New configuration option class ``RegistryOption`` which is backed |
1012 | 161 | onto a registry. (Jelmer Vernooij) | 165 | onto a registry. (Jelmer Vernooij) |
1013 | 162 | 166 |
Nice one.
I think I'm not comfortable with two specifics points:
- you've added a feature to Registry, I think it would be clearer to create
a new class instead,
- the way it works is magical for people that don't know how lazy loading
works, a few comments or docstrings should address that.
565 +RegistryEntry = collections. namedtuple( 'RegistryEntry' , 'objgetter info help')
Good addition but Worth a docstring.
583 + if module is not None and member_name is not None:
This is the line that conflates two classes into a single one for a benefit
that is not clear to me.
688 +# Lazily registered registries. Maps (module, registry_name, name,
689 +# entry_module, entry_name) -> (objgetter, info, help)
690 +_lazy_registries = {}
This is where you should explain part of the magic.
712 + obj_getter = _LazyObjectGett er(entry_ module, entry_name) obj_getter, info, help)
713 + registry_dict[key] = RegistryEntry(
And this is the othe place where the magic takes place (truth is there is
yet another place where the magic occurs but it won't appear that magical if
you use a different class). Someone not knowing about lazy loading and
obj_getter is likely to be completely lost ;)