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 <barkalow@iabervon.org>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Stephan Beyer
2009-01-16 20:09:59 +01:00
committed by Junio C Hamano
parent 2292ce4785
commit ae98a0089f
7 changed files with 57 additions and 113 deletions

View File

@ -300,35 +300,6 @@ static void squash_message(void)
strbuf_release(&out);
}
static int run_hook(const char *name)
{
struct child_process hook;
const char *argv[3], *env[2];
char index[PATH_MAX];
argv[0] = git_path("hooks/%s", name);
if (access(argv[0], X_OK) < 0)
return 0;
snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", get_index_file());
env[0] = index;
env[1] = NULL;
if (squash)
argv[1] = "1";
else
argv[1] = "0";
argv[2] = NULL;
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 void finish(const unsigned char *new_head, const char *msg)
{
struct strbuf reflog_message = STRBUF_INIT;
@ -374,7 +345,7 @@ static void finish(const unsigned char *new_head, const char *msg)
}
/* Run a post-merge hook */
run_hook("post-merge");
run_hook(NULL, "post-merge", squash ? "1" : "0", NULL);
strbuf_release(&reflog_message);
}