Add a new run_hook_strvec() function

The two existing members of the run_hook*() family, run_hook_ve() and
run_hook_le(), are good for callers that know the precise number of
parameters already. Let's introduce a new sibling that takes a strvec
for callers that want to pass a variable number of parameters.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2016-11-30 23:11:36 +01:00 коммит произвёл Derrick Stolee
Родитель 53871be0a7
Коммит c822095f87
2 изменённых файлов: 19 добавлений и 3 удалений

Просмотреть файл

@ -1343,7 +1343,8 @@ const char *find_hook(const char *name)
return path.buf;
}
int run_hook_ve(const char *const *env, const char *name, va_list args)
int run_hook_strvec(const char *const *env, const char *name,
struct strvec *argv)
{
struct child_process hook = CHILD_PROCESS_INIT;
const char *p;
@ -1353,8 +1354,7 @@ int run_hook_ve(const char *const *env, const char *name, va_list args)
return 0;
strvec_push(&hook.args, p);
while ((p = va_arg(args, const char *)))
strvec_push(&hook.args, p);
strvec_pushv(&hook.args, argv->v);
hook.env = env;
hook.no_stdin = 1;
hook.stdout_to_stderr = 1;
@ -1363,6 +1363,20 @@ int run_hook_ve(const char *const *env, const char *name, va_list args)
return run_command(&hook);
}
int run_hook_ve(const char *const *env, const char *name, va_list args)
{
struct strvec argv = STRVEC_INIT;
const char *p;
int ret;
while ((p = va_arg(args, const char *)))
strvec_push(&argv, p);
ret = run_hook_strvec(env, name, &argv);
strvec_clear(&argv);
return ret;
}
int run_hook_le(const char *const *env, const char *name, ...)
{
va_list args;

Просмотреть файл

@ -217,6 +217,8 @@ const char *find_hook(const char *name);
LAST_ARG_MUST_BE_NULL
int run_hook_le(const char *const *env, const char *name, ...);
int run_hook_ve(const char *const *env, const char *name, va_list args);
int run_hook_strvec(const char *const *env, const char *name,
struct strvec *argv);
/*
* Trigger an auto-gc