diff mbox series

[v4,05/36] hook.c: add a hook_exists() wrapper and use it in bugreport.c

Message ID patch-v4-05.36-3514e0c0251-20210803T191505Z-avarab@gmail.com (mailing list archive)
State Superseded
Headers show
Series Run hooks via "git run hook" & hook library | expand

Commit Message

Ævar Arnfjörð Bjarmason Aug. 3, 2021, 7:38 p.m. UTC
From: Emily Shaffer <emilyshaffer@google.com>

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>
---
 builtin/bugreport.c | 2 +-
 hook.c              | 5 +++++
 hook.h              | 5 +++++
 3 files changed, 11 insertions(+), 1 deletion(-)

Comments

Emily Shaffer Aug. 20, 2021, 12:09 a.m. UTC | #1
On Tue, Aug 03, 2021 at 09:38:31PM +0200, Ævar Arnfjörð Bjarmason wrote:
> 
> 
> 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.

Seems fine.

> 
> Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/bugreport.c | 2 +-
>  hook.c              | 5 +++++
>  hook.h              | 5 +++++
>  3 files changed, 11 insertions(+), 1 deletion(-)
> 
> 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 c4dbef1d0ef..97cd799a320 100644
> --- a/hook.c
> +++ b/hook.c
> @@ -35,3 +35,8 @@ const char *find_hook(const char *name)
>  	}
>  	return path.buf;
>  }
> +
> +int hook_exists(const char *name)
> +{
> +	return !!find_hook(name);

Later on I'll change this to refer to the output of list_hooks()
instead.

> +}
> diff --git a/hook.h b/hook.h
> index 68624f16059..4c547ac15e5 100644
> --- a/hook.h
> +++ b/hook.h
> @@ -8,4 +8,9 @@
>   */
>  const char *find_hook(const char *name);
>  
> +/*
> + * A boolean version of find_hook()
> + */
> +int hook_exists(const char *hookname);
> +
>  #endif
> -- 
> 2.33.0.rc0.595.ge31e012651d
>
diff mbox series

Patch

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 c4dbef1d0ef..97cd799a320 100644
--- a/hook.c
+++ b/hook.c
@@ -35,3 +35,8 @@  const char *find_hook(const char *name)
 	}
 	return path.buf;
 }
+
+int hook_exists(const char *name)
+{
+	return !!find_hook(name);
+}
diff --git a/hook.h b/hook.h
index 68624f16059..4c547ac15e5 100644
--- a/hook.h
+++ b/hook.h
@@ -8,4 +8,9 @@ 
  */
 const char *find_hook(const char *name);
 
+/*
+ * A boolean version of find_hook()
+ */
+int hook_exists(const char *hookname);
+
 #endif