API for an extension to register a hook?

Tory Patnoe tpatnoe at cisco.com
Fri Jan 8 19:11:09 CST 2010


On 01/07/2010 11:41 AM, Matt Mackall wrote:
> You can add hooks to the config data stored in the ui objects.
>    

I tried editing the hooks in uisetup of an extension and it wasn't 
working. Here is my uisetup:

def uisetup(ui):

     # Hook to check if the commit message is there
     ui.setconfig('hooks', 'pretxncommit.rally_ext', 
'python:rally_ext.do_pretxncommit')

After further digging, I think the problem is in 
mercurial.dispatch.runcommand

312 def runcommand(lui, repo, cmd, fullargs, ui, options, d):
313     # run pre-hook, and abort if it fails
314     ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" 
".join(fullargs))
315     if ret:
316         return ret
317     ret = _runcommand(ui, options, cmd, d)
318     # run post-hook, passing command result
319     hook.hook(lui, repo, "post-%s" % cmd, False, args=" 
".join(fullargs),
320               result = ret)
321     return ret


On line 317. The lui is changed to ui. The lui instance has the hook 
added by the extention but _runcommand is passed just the ui instance 
and so I don't get the hook. This is probably by design since there is 
both an ui and lui instance. But what this prevents is my extension 
adding a hook at runtime.


Tory






More information about the Mercurial mailing list