Skip to content

Commit ab81cf2

Browse files
avargitster
authored andcommitted
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 <[email protected]> Reviewed-by: Emily Shaffer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 593ffdd commit ab81cf2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

hook.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,17 @@ int run_hooks(const char *hook_name)
149149

150150
return run_hooks_opt(hook_name, &opt);
151151
}
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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,14 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options);
5454
* run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT".
5555
*/
5656
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, ...);
5767
#endif

0 commit comments

Comments
 (0)