Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I configure mercurial hooks like some extensions are configured in the hgrc file?

I know how to specify which hooks are run when. What I want to know is if it is possible to pass config into the hook via the hgrc file. Extensions can do this, e.g.

[extensions]
someextension = something

[someextension]
some.config = 1
some.other.config = True

I want to be able to do something similar for hooks, e.g.

[hooks]
changegroup.mail_someone = python:something

[changegroup.mail_someone]
to_address = [email protected]

Is something like this possible? Searching for a way to do this hasn't turned up anything useful... If it is possible, how do I go about reading in the config in my (Python in-process) hook handler?

like image 868
Spycho Avatar asked Mar 05 '12 10:03

Spycho


1 Answers

Let me answer for both hook types:

  • An in-process hook would use ui.config and the related methods to read the config values:

    address = ui.config('changegroup.mail_someone', 'to_address')
    

    You can also use ui.configbool and ui.configlist to read Booleans and lists, respectively.

  • An external hook can use hg showconfig to extract the configuration value:

    $ hg showconfig changegroup.mail_someone.to_address
    

    That will return [email protected] on stdout. You can use

    $ hg showconfig changegroup.mail_someone
    

    to see all settings in that particular section.

like image 79
Martin Geisler Avatar answered Oct 11 '22 08:10

Martin Geisler