Loading in-process hooks under Windows

Steve Borho steve at borho.org
Thu Aug 6 10:48:22 CDT 2009


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