mirror of
https://github.com/git/git.git
synced 2024-09-25 18:01:04 +02:00
run_hook: use argv_array API
This was a pretty straightforward use, so it really doesn't save that many lines. Still, perhaps it's a little bit more readable. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7bf0b01750
commit
5d40a17985
@ -1,6 +1,7 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "run-command.h"
|
#include "run-command.h"
|
||||||
#include "exec_cmd.h"
|
#include "exec_cmd.h"
|
||||||
|
#include "argv-array.h"
|
||||||
|
|
||||||
static inline void close_pair(int fd[2])
|
static inline void close_pair(int fd[2])
|
||||||
{
|
{
|
||||||
@ -609,26 +610,23 @@ int finish_async(struct async *async)
|
|||||||
int run_hook(const char *index_file, const char *name, ...)
|
int run_hook(const char *index_file, const char *name, ...)
|
||||||
{
|
{
|
||||||
struct child_process hook;
|
struct child_process hook;
|
||||||
const char **argv = NULL, *env[2];
|
struct argv_array argv = ARGV_ARRAY_INIT;
|
||||||
|
const char *p, *env[2];
|
||||||
char index[PATH_MAX];
|
char index[PATH_MAX];
|
||||||
va_list args;
|
va_list args;
|
||||||
int ret;
|
int ret;
|
||||||
size_t i = 0, alloc = 0;
|
|
||||||
|
|
||||||
if (access(git_path("hooks/%s", name), X_OK) < 0)
|
if (access(git_path("hooks/%s", name), X_OK) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
va_start(args, name);
|
va_start(args, name);
|
||||||
ALLOC_GROW(argv, i + 1, alloc);
|
argv_array_push(&argv, git_path("hooks/%s", name));
|
||||||
argv[i++] = git_path("hooks/%s", name);
|
while ((p = va_arg(args, const char *)))
|
||||||
while (argv[i-1]) {
|
argv_array_push(&argv, p);
|
||||||
ALLOC_GROW(argv, i + 1, alloc);
|
|
||||||
argv[i++] = va_arg(args, const char *);
|
|
||||||
}
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
memset(&hook, 0, sizeof(hook));
|
memset(&hook, 0, sizeof(hook));
|
||||||
hook.argv = argv;
|
hook.argv = argv.argv;
|
||||||
hook.no_stdin = 1;
|
hook.no_stdin = 1;
|
||||||
hook.stdout_to_stderr = 1;
|
hook.stdout_to_stderr = 1;
|
||||||
if (index_file) {
|
if (index_file) {
|
||||||
@ -639,6 +637,6 @@ int run_hook(const char *index_file, const char *name, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = run_command(&hook);
|
ret = run_command(&hook);
|
||||||
free(argv);
|
argv_array_clear(&argv);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user