Re: [PATCH v4 7/9] hook: replace run-command.h:find_hook
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Oct 5, 2020, 23:42 UTC
- Message-ID
- <20201005234237.GE1393696@google.com>
- In-Reply-To
- <20200909004939.1942347-8-emilyshaffer@google.com>
Emily Shaffer wrote:
> Subject: hook: replace run-command.h:find_hook
tiny nit: This doesn't remove find_hook, so this may want to be described as "add replacement for" instead of "replace".
[...]
Show 14 quoted lines
> --- a/hook.c
> +++ b/hook.c
> @@ -111,6 +111,15 @@ struct list_head* hook_list(const struct strbuf* hookname)
> return &hook_head;
> }
>
> +int hook_exists(const char *hookname)
> +{
> + const char *value = NULL;
> + struct strbuf hook_key = STRBUF_INIT;
> + strbuf_addf(&hook_key, "hook.%s.command", hookname);
> +
> + return (!git_config_get_value(hook_key.buf, &value)) || !!find_hook(hookname);
> +}This feels a bit fragile, since it can go out of sync with run_hooks. I think I'd prefer if they shared code and this function either returned a parsed structure that could be used later to run hooks or cached the result keyed by hookname.
Thanks, Jonathan