[PATCH v4 7/9] hook: replace run-command.h:find_hook
- From
Emily Shaffer <emilyshaffer@google.com>
- Date
- Sep 9, 2020, 00:49 UTC
- Message-ID
- <20200909004939.1942347-8-emilyshaffer@google.com>
- In-Reply-To
- <20200909004939.1942347-1-emilyshaffer@google.com>
Add a helper to easily determine whether any hooks exist for a given hook event.
Signed-off-by: Emily Shaffer <emilyshaffer@google.com> --- hook.c | 9 +++++++++ hook.h | 1 + 2 files changed, 10 insertions(+)
diff --git a/hook.c b/hook.c index 0dab981681..7c7b922369 100644 --- 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); +} + int run_hooks(const char *const *env, const struct strbuf *hookname, const struct strvec *args) { diff --git a/hook.h b/hook.h index d020788a6b..d94511b609 100644 --- a/hook.h +++ b/hook.h @@ -11,6 +11,7 @@ struct hook }; struct list_head* hook_list(const struct strbuf *hookname); +int hook_exists(const char *hookname); int run_hooks(const char *const *env, const struct strbuf *hookname, const struct strvec *args);
-- 2.28.0.rc0.142.g3c755180ce-goog