hook.c: add a hook_exists() wrapper and use it in bugreport.c

Add a boolean version of the find_hook() function for those callers who are only interested in checking whether the hook exists, not what the path to it is. Signed-off-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Emily Shaffer committed Sep 26, 2021 at 21:03 UTC 330155ed8af3b2e050ac74554993ba68d303e8c3
3 files changed +11 -1
builtin/bugreport.c
+1 -1
@@ -82,7 +82,7 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit)
82 }
83
84 for (i = 0; i < ARRAY_SIZE(hook); i++)
85 - if (find_hook(hook[i]))
85 + if (hook_exists(hook[i]))
86 strbuf_addf(hook_info, "%s\n", hook[i]);
87 }
88
hook.c
+5
@@ -35,3 +35,8 @@ const char *find_hook(const char *name)
35 }
36 return path.buf;
37 }
38 +
39 +int hook_exists(const char *name)
40 +{
41 + return !!find_hook(name);
42 +}
hook.h
+5
@@ -8,4 +8,9 @@
8 */
9 const char *find_hook(const char *name);
10
11 +/**
12 + * A boolean version of find_hook()
13 + */
14 +int hook_exists(const char *hookname);
15 +
16 #endif