comparison mercurial/help/internals/extensions.txt @ 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 04d08f17ce7a
children 86f6b441adea
comparison
equal deleted inserted replaced
40728:2cd5f1fac788 40729:c93d046d4300
180 Command table setup 180 Command table setup
181 ------------------- 181 -------------------
182 182
183 After ``extsetup``, the ``cmdtable`` is copied into the global command table 183 After ``extsetup``, the ``cmdtable`` is copied into the global command table
184 in Mercurial. 184 in Mercurial.
185
186 Ui instance setup
187 -----------------
188
189 The optional ``uipopulate`` is called for each ``ui`` instance after
190 configuration is loaded, where extensions can set up additional ui members,
191 update configuration by ``ui.setconfig()``, and extend the class dynamically.
192
193 Typically there are three ``ui`` instances involved in command execution:
194
195 ``req.ui`` (or ``repo.baseui``)
196 Only system and user configurations are loaded into it.
197 ``lui``
198 Local repository configuration is loaded as well. This will be used at
199 early dispatching stage where a repository isn't available.
200 ``repo.ui``
201 The fully-loaded ``ui`` used after a repository is instantiated. This
202 will be created from the ``req.ui`` per repository.
203
204 In command server and hgweb, this may be called more than once for the same
205 ``ui`` instance.
206
207 (New in Mercurial 4.9)
185 208
186 Repository setup 209 Repository setup
187 ---------------- 210 ----------------
188 211
189 Extensions can implement an optional callback named ``reposetup``. It is 212 Extensions can implement an optional callback named ``reposetup``. It is
302 * Changes that need to be visible by other extensions: because initialization 325 * Changes that need to be visible by other extensions: because initialization
303 occurs in phases (all extensions run ``uisetup``, then all run ``extsetup``), 326 occurs in phases (all extensions run ``uisetup``, then all run ``extsetup``),
304 a change made here will be visible by other extensions during ``extsetup``. 327 a change made here will be visible by other extensions during ``extsetup``.
305 * Monkeypatches or function wraps (``extensions.wrapfunction``) of ``dispatch`` 328 * Monkeypatches or function wraps (``extensions.wrapfunction``) of ``dispatch``
306 module members 329 module members
307 * Setup of ``pre-*`` and ``post-*`` hooks 330 * Set up ``pre-*`` and ``post-*`` hooks. (DEPRECATED. ``uipopulate`` is
331 preferred on Mercurial 4.9 and later.)
308 * ``pushkey`` setup 332 * ``pushkey`` setup
309 333
310 extsetup 334 extsetup
311 -------- 335 --------
312 336
313 * Changes depending on the status of other extensions. (``if extensions.find('mq')``) 337 * Changes depending on the status of other extensions. (``if extensions.find('mq')``)
314 * Add a global option to all commands 338 * Add a global option to all commands
315 * Extend revsets 339 * Extend revsets
316 340
341 uipopulate
342 ----------
343
344 * Modify ``ui`` instance attributes and configuration variables.
345 * Changes to ``ui.__class__`` per instance.
346 * Set up all hooks per scoped configuration.
347
317 reposetup 348 reposetup
318 --------- 349 ---------
319 350
320 * All hooks but ``pre-*`` and ``post-*`` 351 * Set up all hooks but ``pre-*`` and ``post-*``. (DEPRECATED. ``uipopulate`` is
352 preferred on Mercurial 4.9 and later.)
321 * Modify configuration variables 353 * Modify configuration variables
322 * Changes to ``repo.__class__``, ``repo.dirstate.__class__`` 354 * Changes to ``repo.__class__``, ``repo.dirstate.__class__``