Accessing HTTP user in a hook
Maxim Khitrov
mkhitrov at gmail.com
Tue Jun 29 12:40:24 UTC 2010
On Tue, Jun 29, 2010 at 8:31 AM, John Ament <my.reprive at gmail.com> wrote:
> On Tue, Jun 29, 2010 at 6:30 AM, Maxim Khitrov <mkhitrov at gmail.com> wrote:
>>
>> On Tue, Jun 29, 2010 at 5:41 AM, John Ament <my.reprive at gmail.com> wrote:
>> > On Tue, Jun 29, 2010 at 12:15 AM, Matt Mackall <mpm at selenic.com> wrote:
>> >> On Mon, 2010-06-28 at 21:05 -0400, John Ament wrote:
>> >> > Hmmm. I think it has to do with how the script is being called. I
>> >> > executed yours and it worked fine for me.
>> >> >
>> >> > The script I'm playing with is mozilla's pushlog hook. The call
>> >> > looks
>> >> > like this:
>> >> >
>> >> > python:mozhghooks.pushlog.log
>> >> >
>> >> > where the log function is defined like this:
>> >> >
>> >> > def log(ui, repo, node, **kwargs):
>> >> >
>> >> > There are other calls to os, it just seems like the environment is
>> >> > getting passed along.
>> >>
>> >> No, for hooks, the args get passed in via kwargs.
>> >>
>> >
>> > To be honest with you, I'm not sure which args you're referring to. os
>> > wouldn't be an arg in this case, right?
>>
>> Now I understand. Matt is referring to the fact that executing a
>> python function is different from running an external program for a
>> hook. In my example, even though it's python code, it was executed as
>> a separate process. With external programs, HG_URL is passed as an
>> environment variable. For python functions, you need to look at kwargs
>> dictionary. Here's a modified version of my previous test.py code:
>>
>> def log(ui, repo, node, **kwargs):
>> print 'Username:', kwargs['url'].split(':')[-1]
>>
>> Instead of os.environ['HG_URL'] you need to look at kwargs['url'].
>> Everything else is identical. With this modification, I can set my
>> hook to the following and everything should work as before:
>>
>> [hooks]
>> changegroup = python:test.log
>>
>> Python has to be able to find the specified function, but it sounds
>> like that's not a problem in your case.
>>
>> - Max
>
> Yep so that was it. Great, thanks!
>
> Is there a list of everything available in kwargs somewhere?
>
> John
John, please don't top-post. See hgrc(5) for info on what is in kwargs:
http://www.selenic.com/mercurial/hgrc.5.html
"Arguments listed as environment variables above are passed as keyword
arguments, with no HG_ prefix, and names in lower case."
- Max
More information about the Mercurial
mailing list