Thread (581 messages) flat view 581 messages, 16 authors, 2021-10-12
STALE1799d

Revision v1 of 2 in this series.

Revisions (2)
  1. v1 current
  2. v2 [diff vs current]

[PATCH 05/31] hook.c: add a hook_exists() wrapper and use it in bugreport.c

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-05-28 12:11:55
Subsystem: the rest · Maintainer: Linus Torvalds

From: Emily Shaffer <redacted>

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 <redacted>
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 builtin/bugreport.c | 2 +-
 hook.c              | 5 ++++-
 hook.h              | 5 +++++
 3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index 596f079a7f9..941c8d5e270 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -82,7 +82,7 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit)
 	}
 
 	for (i = 0; i < ARRAY_SIZE(hook); i++)
-		if (find_hook(hook[i]))
+		if (hook_exists(hook[i]))
 			strbuf_addf(hook_info, "%s\n", hook[i]);
 }
 
diff --git a/hook.c b/hook.c
index 06842f50e5c..c7da273822d 100644
--- a/hook.c
+++ b/hook.c
@@ -36,7 +36,10 @@ const char *find_hook(const char *name)
 	return path.buf;
 }
 
-
+int hook_exists(const char *name)
+{
+	return !!find_hook(name);
+}
 
 void run_hooks_opt_clear(struct run_hooks_opt *o)
 {
diff --git a/hook.h b/hook.h
index 291ee19469a..cbda7746a5d 100644
--- a/hook.h
+++ b/hook.h
@@ -44,6 +44,11 @@ struct hook_cb_data {
  */
 const char *find_hook(const char *name);
 
+/*
+ * A boolean version of find_hook()
+ */
+int hook_exists(const char *hookname);
+
 void run_hooks_opt_clear(struct run_hooks_opt *o);
 
 /*
-- 
2.32.0.rc1.458.gd885d4f985c
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help