Loading in-process hooks under Windows

Roman V. Kiseliov roman.kiseliov at gmail.com
Thu Aug 6 12:41:26 CDT 2009


I've installed TotroiseHg-0.8.1-Mercurial-1.3.1.exe from bitbucket.
I've created repo 'hghooktest', issue 'hg init', create some file, 'hg
add', etc.
I've placed 'hgrc' into '.hg', 'update-build-info.py' (module with the
hook) into 'hghooktest/hooks'

'hg.exe commit' throws exception.

Now the trick itself :)

Go to the 'C:\Program Files\TortoiseHg'.
You'll find 'library.zip' created by py2exe.
'library.zip' contains 'hook.pyc' produced from mercurial-1.3.1's
buggy 'hook.py'

We must replace 'hook.pyc' in 'library.zip' to overcome bug with colon.

Patch original 'hook.py' from mercurial-1.3.1.
Compile patched 'hook.py' (it's now without bug) to get 'hook.pyc'
(also without bug).
Replace old 'hook.pyc' inside 'library.zip' with just created 'hook.pyc'

Now 'library.zip' contains 'hook.pyc' produced from patched 'hook.py'.

'hg.exe commit' works as expected.

I don't want build TortoiseHg from sources and trick helps me.
I don't know why it does not work for you...

Roman

2009/8/6 Steve Borho <steve at borho.org>:
> On Thu, Aug 6, 2009 at 9:40 AM, Roman V.
> Kiseliov<roman.kiseliov at gmail.com> wrote:
>> For me binary installer works.
>>
>> I'm using TotroiseHg-0.8.1-Mercurial-1.3.1.exe. To test it I've
>> compiled patched 'hook.py' and inserted new 'hook.pyc' into
>> 'library.zip' :)
>
> You lost me here.  Are you saying you had to add the hook to
> library.zip, or that you got the following to work without it?
>
>> Then I've prepared 'hgrc' as
>> -------------------------------------------------------------------------------------------------------------------------
>> [hooks]
>> commit.update-build-info =
>> python:e:\projects\hghooktest\hooks\update-build-info.py:myhook
>> -------------------------------------------------------------------------------------------------------------------------
>>
>> and 'update-build-info.py' as
>>
>> ----------------------------------------------------------------------------------------------------------------------------
>> # Author: Roman V. Kiseliov
>> # Purpose: illustrate basic work with in-process python Mercurial hooks
>>
>> from mercurial.node import nullrev, short
>> from mercurial.util import datestr, Abort
>>
>> data_fmt_str = "%s changeset:\n\tnode=%s,\n\trev=%i,\n\tshort=%s,\n\tdate=%s\n"
>> date_fmt_str = '%Y-%m-%d %H:%M:%S %1%2'
>>
>> def myhook(ui, repo, hooktype, *args, **kwargs):
>>
>>    if hooktype != 'commit':
>>        raise Abort('Hooktype "%s" is not supported.' % hooktype)
>>
>>    try:
>>        print 'root:', repo.root
>>
>>        str_nodes = [(kwargs["node"],    'committed'),
>>                     (kwargs["parent1"], 'parent #1'),
>>                     (kwargs["parent2"], 'parent #2')]
>>
>>        for str_node, description in str_nodes:
>>            if str_node:
>>                changeset_context = repo[str_node]
>>
>>                node = changeset_context.node()
>>                rev  = changeset_context.rev()
>>                date = changeset_context.date()
>>
>>                date = datestr(date, date_fmt_str)
>>
>>                data_tuple = (description, str_node, rev, short(node), date)
>>                print data_fmt_str % data_tuple
>>
>>    except Exception, e:
>>        raise Abort('Hook has encountered an error "%s".' % e.message)
>> --------------------------------------------------------------------------------------------------------------------
>>
>> 'hg.exe commit' works without any errors. I do not have source install
>> on my computer (Windows XP x64, hg.exe lives in 'C:\Program
>> Files\TortoiseHg')
>
> So did this require any more changes to Mercurial?  If not, I wonder
> why I could not reproduce this.
>
>> P.S. py2exe writes into sys.path the only item: path to library.zip.
>> It's easily can be seen in 'static int set_path_early()' from py2exe's
>> 'start.c'. So PYTHONPATH is thrown away.
>
> Yep
>



More information about the Mercurial-devel mailing list