[PATCH] hook: add more robust python: syntax checking
Yuya Nishihara
yuya at tcha.org
Fri May 25 08:50:30 EDT 2018
On Thu, 24 May 2018 15:35:40 -0600, tom_hindle at sil.org wrote:
> # HG changeset patch
> # User hindlemail <tom_hindle at sil.org>
> # Date 1527195876 21600
> # Thu May 24 15:04:36 2018 -0600
> # Node ID a30dbd52f2148af7f2d9167b5935367e899b7244
> # Parent bd7a3fa71a72666691b8b77e6bf03be1d2273391
> hook: add more robust python: syntax checking
>
> Added checking for missing trailing :hook when python file is a full path and
> running on windows. Provides an easier to understand error message.
>
> diff -r bd7a3fa71a72 -r a30dbd52f214 mercurial/hook.py
> --- a/mercurial/hook.py Thu May 24 23:26:28 2018 +0900
> +++ b/mercurial/hook.py Thu May 24 15:04:36 2018 -0600
> @@ -240,18 +240,24 @@ def runhooks(ui, repo, htype, hooks, thr
> hint = _("see 'hg help config.trusted'"))
> ui.warn(_('warning: untrusted hook %s not executed\n') % hname)
> r = 1
> raised = False
> elif callable(cmd):
> r, raised = pythonhook(ui, repo, htype, hname, cmd, args,
> throw)
> elif cmd.startswith('python:'):
> + originalcmd = cmd
> if cmd.count(':') >= 2:
> path, cmd = cmd[7:].rsplit(':', 1)
> + if '\\' in cmd or '/' in cmd:
> + if throw:
> + raise error.HookAbort(
> + _("invalid 'python:' syntax: %s") % originalcmd)
> + ui.warn(_("invalid 'python:' syntax: %s") % originalcmd)
Perhaps it shouldn't continue even if throw=False. I'm not sure which will be
the correct behavior.
a) r, raised = 1, False (the same behavior as cmd is untrusted)
b) raise Abort, HookAbort, or ParseError no matter if throw is False
More information about the Mercurial-devel
mailing list