Questions regarding hooks
Didly
didlybom at gmail.com
Mon Jun 21 13:29:48 UTC 2010
On Fri, Jun 18, 2010 at 1:02 PM, Martin Geisler <mg at lazybytes.net> wrote:
>
> >> Didly Bom <didlybom at gmail.com> writes:
> >>
> >> > Hi,
> >> >
> >> > I have two questions regarding hooks:
> >> >
> >> > I know that you can register a hook from a plugin by using
> >> > ui.setconfig("hooks", HOOK_NAME, HOOK_FUNCTION)
> >> >
> >> > - Does it matter which ui object is used to register the hook? That
> >> > is, does it matter if I setup the hook using the global ui object
> >> > using the repo.ui object?
> >>
> >> The hooks are stored by name in the ui object. When hooks are run,
> >> they are triggered by code like this from dispatch.runcommand:
> >>
> >> # run pre-hook, and abort if it fails
> >> ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args="
> >> ".join(fullargs),
> >> pats=cmdpats, opts=cmdoptions)
> >>
> >> This code executed the pre-<cmd> hook configured in the lui object.
> >> So it matters which ui object you use when configuring the hook. If
> >> you start in dispatch.py, then you can trace your way through the
> >> code and see which ui object is used where.
> >>
> >> I find this confusing as well and I would love if you could document
> >> it on the MercurialApi page on the Wiki.
> >
> >
> > Martin, I missed this part of your replay on your previous email. What
> > exactly would you like to see documented on the Wiki? Are you
> > referring to the method to register hooks through extensions as
> > discussed in this thread? Or are you thinking about documenting which
> > ui object is used where? I don't feel qualified enough to answer this
> > last question, although I definitely see the value of having that
> > properly documented, since it is quite confusing.
>
> Documenting that ui.setconfig('hooks', ...) works for an extension would
> be a good start -- some people may expect to use some other API.
>
Martin, I have updated the "Writing Extensions" page of the wiki with some
information regarding how to configure hooks automatically within the
extension code: http://mercurial.selenic.com/wiki/WritingExtensions
In there I explain that the "ui" element that is passed to the uisetup() and
extsetup() functions is not the same as the one that is passed to the
reposetup() function.
I have also added a new section "Configuring hooks", in which I explain that
different hooks must be configured in different "setup functions" (some must
be configured on the uisetup ()or extsetup() functions, while others must be
configured on the reposetup() function). I also added an example that
demonstrates this. However I have not added a table indicating which hooks
must be setup on which function since I would need to test each of them. If
I get the time I will do so, in which case I would add this info into the
"Hooks" page as you suggested.
Please have a look let me know if it is fine (both in terms of content and
style). Please take into account that English is not may mother tongue, so
if you find any syntax errors please let me know so that I can fix them (or
feel free to fix them yourself).
Cheers,
Angel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-devel/attachments/20100621/d096bd0b/attachment.html>
More information about the Mercurial-devel
mailing list