API for an extension to register a hook?
Matt Mackall
mpm at selenic.com
Mon Jan 11 21:55:13 UTC 2010
On Sat, 2010-01-09 at 12:04 +0100, Martin Geisler wrote:
> 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?
Yes. And we can have between 0-2 repo objects in existence, depending on
which command is invoked.
--
http://selenic.com : development and support for Mercurial and Linux
More information about the Mercurial
mailing list