[PATCH] hooks with pats and opts

Chad Dombrova chadrik at gmail.com
Mon May 24 17:44:33 CDT 2010


hi all,
this is my first post on the dev list, but i've been a long time follower of
the user list, so be gentle :)

i'm presenting a patch for hooks that allows for a streamlined workflow that
avoids dataloss. currently, pre- and post- command hooks get passed a string
representing what the user entered on the command-line.  however, the
current method causes data loss: when a user inputs a string with spaces in
it this information is not preserved.

ex.

   $ hg tag 'my tag'

any pre-tag or post-tag hook is passed the string: 'hg tag my tag'

because of this data loss, there is currently not a 100% reliable way to do
anything with this information in a hook.

at the time that the hooks are called in dispatch.runcommand() hg has
already parsed the cli args into *pats and **opts, and ultimately this is
the most versatile and accurate representation of this data (exactly as it
is passed to the command function), so why not just pass it to the hooks as
well?

in my patch, this data is passed to hooks via **kwargs -- patterns as 'pats'
and options as 'opts' -- so a  hook could get this information like so:

    def myhook(ui, repo, **kwargs)
        options = kwargs['opts']
pats = kwargs['pats']

i wanted to keep the patch as clean as possible, so i'm using the hook
mechanism's existing support for transmitting extra **kwargs to the
callback.  one downside here is that generic user data gets sent to both
python and shell hooks, which means shell hooks get $HG_PATS and $HG_OPTS,
containing string representations of pats and opts.  these args are easily
ignored and should not affect adversely anything.

let me know what you think.

-chad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20100524/2cad7d8b/attachment.htm>


More information about the Mercurial-devel mailing list