Mercurial > public > mercurial-scm > hg
comparison mercurial/extensions.py @ 40729:c93d046d4300
extensions: add "uipopulate" hook, called per instance, not per process
In short, this is the "reposetup" function for ui. It allows us to modify
ui attributes without extending ui.__class__. Before, the only way to do
that was to abuse the config dictionary, which is copied across ui instances.
See the next patch for usage example.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 12 Nov 2018 21:10:51 +0900 |
parents | cfa564037789 |
children | 6f2510b581a0 |
comparison
equal
deleted
inserted
replaced
40728:2cd5f1fac788 | 40729:c93d046d4300 |
---|---|
403 loaded = (_extensions[extension] is not None) | 403 loaded = (_extensions[extension] is not None) |
404 callback(loaded=loaded) | 404 callback(loaded=loaded) |
405 else: | 405 else: |
406 _aftercallbacks.setdefault(extension, []).append(callback) | 406 _aftercallbacks.setdefault(extension, []).append(callback) |
407 | 407 |
408 def populateui(ui): | |
409 """Run extension hooks on the given ui to populate additional members, | |
410 extend the class dynamically, etc. | |
411 | |
412 This will be called after the configuration is loaded, and/or extensions | |
413 are loaded. In general, it's once per ui instance, but in command-server | |
414 and hgweb, this may be called more than once with the same ui. | |
415 """ | |
416 for name, mod in extensions(ui): | |
417 hook = getattr(mod, 'uipopulate', None) | |
418 if not hook: | |
419 continue | |
420 try: | |
421 hook(ui) | |
422 except Exception as inst: | |
423 ui.traceback(force=True) | |
424 ui.warn(_('*** failed to populate ui by extension %s: %s\n') | |
425 % (name, stringutil.forcebytestr(inst))) | |
426 | |
408 def bind(func, *args): | 427 def bind(func, *args): |
409 '''Partial function application | 428 '''Partial function application |
410 | 429 |
411 Returns a new function that is the partial application of args and kwargs | 430 Returns a new function that is the partial application of args and kwargs |
412 to func. For example, | 431 to func. For example, |