(extensions) Is it possible to add hook dynamically under TortoiseHg?

Yuya Nishihara yuya at tcha.org
Fri Apr 22 15:25:10 UTC 2016


On Fri, 22 Apr 2016 01:04:11 +0200, Marcin Kasperski wrote:
> I am trying to get mercurial_update_version working under TortoiseHg.
> The extension works by adding pre-tag hook and, as suggested by wiki
> docs, it does it from ui.setup. Nothing special:
> 
>     def uisetup(ui):
>         ui.setconfig("hooks", "pre-tag.update_version", pre_tag_hook)
> 
> Under „normal Mercurial” it works nicely.
> Under TortoiseHg - it does not.
> 
> uisetup is being called, but seems to have no impact (hook is not enabled)
> 
> I tried looking around the code, and noted two things:
> 
> a) ui given to uisetup is in fact „lui” variable, which is effectively 
>    thrown away afterwards (see hgqt/run.py:runcommand:
>  https://bitbucket.org/tortoisehg/thg/src/32ea32c53b34663e8497e57d982d948249794ba1/tortoisehg/hgqt/run.py?at=default&fileviewer=file-view-default#run.py-312 
>    and note that actual commands use ui passed to checkedfunc)
> 
> b) even if this was worked around somehow, actual command is spawned via
>    cmdserver, in separate process.

Well, the problem resides in hg. In general, you can't do ui.setconfig() in
uisetup() and extsetup() because the changes would be discarded soon.

https://selenic.com/repo/hg/file/tip/mercurial/dispatch.py#l747

> Is it possible to work it around somehow? I suppose I could get my
> effects via some brute monkeypatching (wrapping tag?), but would be
> great to find less invasive way…

Perhaps you can use reposetup() and (no-dash) "pretag" hook.



More information about the Mercurial mailing list