hook API: add a run_hooks_l() wrapper
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>
Ævar Arnfjörð Bjarmason committed
Dec 22, 2021 at 04:59 UTC
ab81cf242c67182911352aeacdd6aabb68a8555c
2 files changed
+24
hook.c
+14
@@ -149,3 +149,17 @@ int run_hooks(const char *hook_name)
149
150
return run_hooks_opt(hook_name, &opt);
151
}
152
+
153
+int run_hooks_l(const char *hook_name, ...)
154
+{
155
+ struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
156
+ va_list ap;
157
+ const char *arg;
158
+
159
+ va_start(ap, hook_name);
160
+ while ((arg = va_arg(ap, const char *)))
161
+ strvec_push(&opt.args, arg);
162
+ va_end(ap);
163
+
164
+ return run_hooks_opt(hook_name, &opt);
165
+}
hook.h
+10
@@ -54,4 +54,14 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options);
54
* run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT".
55
*/
56
int run_hooks(const char *hook_name);
57
+
58
+/**
59
+ * Like run_hooks(), a wrapper for run_hooks_opt().
60
+ *
61
+ * In addition to the wrapping behavior provided by run_hooks(), this
62
+ * wrapper takes a list of strings terminated by a NULL
63
+ * argument. These things will be used as positional arguments to the
64
+ * hook. This function behaves like the old run_hook_le() API.
65
+ */
66
+int run_hooks_l(const char *hook_name, ...);
67
#endif