API for an extension to register a hook?
Martin Geisler
mg at lazybytes.net
Sat Jan 9 11:04:33 UTC 2010
Tory Patnoe <tpatnoe at cisco.com> writes:
> 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')
In the eol extension I do it like this:
def preupdate(ui, repo, hooktype, parent1, parent2):
#print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2)
readhgeol(ui, repo, parent1)
return False
def uisetup(ui):
ui.setconfig('hooks', 'preupdate.eol', preupdate)
I can see the preupdate function being called if I uncomment the print
statement.
> 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.
I remember having problems because I used reposetup and that didn't
work. I'm afraid I also don't fully understand why we need to have both
a 'ui' and a 'lui' object around. Is it because the 'ui' object is
associated with the program execution as a whole and 'lui' is associated
with the 'repo' object?
--
Martin Geisler
VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20100109/5c0b534d/attachment.asc>
More information about the Mercurial
mailing list