]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hook API: add a run_hooks_l() wrapper
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 22 Dec 2021 03:59:31 +0000 (04:59 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jan 2022 23:19:34 +0000 (15:19 -0800)
Add a run_hooks_l() wrapper, we'll use it in subsequent commits for
the simple cases of wanting to run a single hook under a given name
along with a list of arguments.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Emily Shaffer <emilyshaffer@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
hook.c
hook.h

diff --git a/hook.c b/hook.c
index d67a114e62d929ee08e7f1e5508b5bade2b81608..1ad123422b26f640661e2cf076fd55c0c358316f 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -149,3 +149,17 @@ int run_hooks(const char *hook_name)
 
        return run_hooks_opt(hook_name, &opt);
 }
+
+int run_hooks_l(const char *hook_name, ...)
+{
+       struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
+       va_list ap;
+       const char *arg;
+
+       va_start(ap, hook_name);
+       while ((arg = va_arg(ap, const char *)))
+               strvec_push(&opt.args, arg);
+       va_end(ap);
+
+       return run_hooks_opt(hook_name, &opt);
+}
diff --git a/hook.h b/hook.h
index 9c358789958442022264dd43346c35259e11ea0e..54528395953bca8410bde2dac81d9796d8395f97 100644 (file)
--- a/hook.h
+++ b/hook.h
@@ -54,4 +54,14 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options);
  * run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT".
  */
 int run_hooks(const char *hook_name);
+
+/**
+ * Like run_hooks(), a wrapper for run_hooks_opt().
+ *
+ * In addition to the wrapping behavior provided by run_hooks(), this
+ * wrapper takes a list of strings terminated by a NULL
+ * argument. These things will be used as positional arguments to the
+ * hook. This function behaves like the old run_hook_le() API.
+ */
+int run_hooks_l(const char *hook_name, ...);
 #endif