From ae98a0089ff7f7641ed15ddd595797de56eb49f1 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Fri, 16 Jan 2009 20:09:59 +0100 Subject: Move run_hook() from builtin-commit.c into run-command.c (libgit) A function that runs a hook is used in several Git commands. builtin-commit.c has the one that is most general for cases without piping. The one in builtin-gc.c prints some useful warnings. This patch moves a merged version of these variants into libgit and lets the other builtins use this libified run_hook(). The run_hook() function used in receive-pack.c feeds the standard input of the pre-receive or post-receive hooks. This function is renamed to run_receive_hook() because the libified run_hook() cannot handle this. Mentored-by: Daniel Barkalow Mentored-by: Christian Couder Signed-off-by: Stephan Beyer Signed-off-by: Junio C Hamano --- builtin-commit.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'builtin-commit.c') diff --git a/builtin-commit.c b/builtin-commit.c index e88b78f811..6f8d9fbfe6 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -361,40 +361,6 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int return s.commitable; } -static int run_hook(const char *index_file, const char *name, ...) -{ - struct child_process hook; - const char *argv[10], *env[2]; - char index[PATH_MAX]; - va_list args; - int i; - - va_start(args, name); - argv[0] = git_path("hooks/%s", name); - i = 0; - do { - if (++i >= ARRAY_SIZE(argv)) - die ("run_hook(): too many arguments"); - argv[i] = va_arg(args, const char *); - } while (argv[i]); - va_end(args); - - snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); - env[0] = index; - env[1] = NULL; - - if (access(argv[0], X_OK) < 0) - return 0; - - memset(&hook, 0, sizeof(hook)); - hook.argv = argv; - hook.no_stdin = 1; - hook.stdout_to_stderr = 1; - hook.env = env; - - return run_command(&hook); -} - static int is_a_merge(const unsigned char *sha1) { struct commit *commit = lookup_commit(sha1); -- cgit v1.2.3