Mercurial > public > mercurial-scm > hg-stable
diff mercurial/extensions.py @ 40763: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 |
line wrap: on
line diff
--- a/mercurial/extensions.py Sat Nov 17 19:11:45 2018 +0900 +++ b/mercurial/extensions.py Mon Nov 12 21:10:51 2018 +0900 @@ -405,6 +405,25 @@ else: _aftercallbacks.setdefault(extension, []).append(callback) +def populateui(ui): + """Run extension hooks on the given ui to populate additional members, + extend the class dynamically, etc. + + This will be called after the configuration is loaded, and/or extensions + are loaded. In general, it's once per ui instance, but in command-server + and hgweb, this may be called more than once with the same ui. + """ + for name, mod in extensions(ui): + hook = getattr(mod, 'uipopulate', None) + if not hook: + continue + try: + hook(ui) + except Exception as inst: + ui.traceback(force=True) + ui.warn(_('*** failed to populate ui by extension %s: %s\n') + % (name, stringutil.forcebytestr(inst))) + def bind(func, *args): '''Partial function application