views:

189

answers:

1

I'm trying to get a Mercurial in-process hook to run on Windows.
The problem is not how to write the hook (I want to use an existing one, in this case BugTracker.Net's hook for Mercurial integration - I didn't find a direct link to the file, but you can see it if you download BT.net here, it's in the "mercurial" subfolder).
The problem is how to tell Mercurial to run it.

I spent quite some time to read the documentation, but I'm stuck right now.
(it would probably be easier with a certain knowledge of Python - which I don't have)

I know that I have to insert a line in the hgrc file (in the .hg folder of my repository).

There's an example in the HG Book which looks like this:

[hooks]
commit.example = python:mymodule.submodule.myhook

And there's another example on the Mercurial site, it looks like this:

[hooks]
changegroup = /path/to/changegrouphook

Now I want a "incoming" hook, so at least I know I have to do this:

[hooks]   
incoming.btnet = X

The problem is to figure out "X".
The filename is hg_hook_for_btnet.py and in the file, there is a line which looks like this:

def debug_out(s):

I suppose that's the name of the "function" itself.
So my line needs to look something like this:

[hooks]   
incoming.btnet = python:hg_hook_for_btnet.debug_out

But this gives me an error message [Errno 2] No such file or directory when I push.
I already tried lots of different variations, but it doesn't work and I don't know what I'm doing wrong.

  • Do I need python: at the beginning or not?
  • Do I need to specify the file extension .py or not?
  • Do I need /path/to/... as indicated in the example from the Mercurial site (see above)?
  • If yes, what is the correct syntax for the path? (just c:\MyRepo\ doesn't work - syntax must be different in Python)

Also, did I put the hook file into the correct folder?
Right now, it is in the main folder of my repository (on the same level as the .hg folder).


EDIT:

Martin, I changed it into this:

[hooks]
incoming.btnet = python:~c:\HG\MyRepo\hg_hook_for_btnet.py:debug_out

Now I get a different message: [Errno 22] Invalid argument
I suppose this is because of the repo and ui arguments you mentioned.

So, does this mean that the hook script is broken?
(as I said - I don't know anything about Python, this is an existing hook script from an open source bugtracker)


EDIT 2:

Sorry for the confusion regarding in-process and separate process - I know there is a difference, but I assumed that if the hook is written in Python, it must be in-process automatically (turns out I was wrong :-)

Okay, with the syntax in your edited answer, the script at least runs.
I have Python 2.7 installed (already did that before I asked the question here) and changed the first line in the script into #!C:\Python27\python.exe.
Now I get this:

running hook incoming.btnet: c:\HG\MyRepo\hg_hook_for_btnet.py
warning: incoming.btnet hook exited with status 1

So the script runs, but there is still some error.
This seems to be a Bugtracker.NET related problem, so I will ask on the BT.NET mailing list for further advice.
Thank you for your help though, without you I probably wouldn't even have come so far!

+3  A: 

You should use

[hooks]
incoming.btnet = python:~/path/to/hg_hook_for_btnet.py:debug_out

and define debug_out as

def debug_out(ui, repo, **kwargs):
    # ...

as explained in the HG book -- all hooks are called with a ui and a repo argument plus some extra hook-specific arguments. The Mercurial API page explains what you can do with the ui and a repo arguments.


Edit: Aha... I've now looked at the script. It is not designed to be run as an in-process Mercurial hook. It is instead designed to be run as a separate process. So you will need to use

[hooks]
incoming.btnet = c:\HG\MyRepo\hg_hook_for_btnet.py

and make sure you follow the instructions in the script: it talks about setting the path to the hg.exe binary and to your Python interpreter. The latter means that the author expects you to install Python. There is an email address in the script -- I suggest you contact corey Trager directly or via a BugTracker.NET mailinglist. Since it's a bug tracker, I assume they have a proper place where you can report this! :-)

Martin Geisler
I edited my question, see above!
haarrrgh