hook API: support passing stdin to hooks, convert am's 'post-rewrite'
Convert the invocation of the 'post-rewrite' hook run by 'git am' to use the hook.h library. To do this we need to add a "path_to_stdin" member to "struct run_hooks_opt". In our API this is supported by asking for a file path, rather than by reading stdin. Reading directly from stdin would involve caching the entire stdin (to memory or to disk) once the hook API is made to support "jobs" larger than 1, along with support for executing N hooks at a time (i.e. the upcoming config-based hooks). Signed-off-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
540267304d
commit
917e080249
20
builtin/am.c
20
builtin/am.c
@ -495,24 +495,12 @@ static int run_applypatch_msg_hook(struct am_state *state)
|
|||||||
*/
|
*/
|
||||||
static int run_post_rewrite_hook(const struct am_state *state)
|
static int run_post_rewrite_hook(const struct am_state *state)
|
||||||
{
|
{
|
||||||
struct child_process cp = CHILD_PROCESS_INIT;
|
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
|
||||||
const char *hook = find_hook("post-rewrite");
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!hook)
|
strvec_push(&opt.args, "rebase");
|
||||||
return 0;
|
opt.path_to_stdin = am_path(state, "rewritten");
|
||||||
|
|
||||||
strvec_push(&cp.args, hook);
|
return run_hooks_opt("post-rewrite", &opt);
|
||||||
strvec_push(&cp.args, "rebase");
|
|
||||||
|
|
||||||
cp.in = xopen(am_path(state, "rewritten"), O_RDONLY);
|
|
||||||
cp.stdout_to_stderr = 1;
|
|
||||||
cp.trace2_hook_name = "post-rewrite";
|
|
||||||
|
|
||||||
ret = run_command(&cp);
|
|
||||||
|
|
||||||
close(cp.in);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
5
hook.c
5
hook.c
@ -55,6 +55,11 @@ static int pick_next_hook(struct child_process *cp,
|
|||||||
|
|
||||||
cp->no_stdin = 1;
|
cp->no_stdin = 1;
|
||||||
strvec_pushv(&cp->env, hook_cb->options->env.v);
|
strvec_pushv(&cp->env, hook_cb->options->env.v);
|
||||||
|
/* reopen the file for stdin; run_command closes it. */
|
||||||
|
if (hook_cb->options->path_to_stdin) {
|
||||||
|
cp->no_stdin = 0;
|
||||||
|
cp->in = xopen(hook_cb->options->path_to_stdin, O_RDONLY);
|
||||||
|
}
|
||||||
cp->stdout_to_stderr = 1;
|
cp->stdout_to_stderr = 1;
|
||||||
cp->trace2_hook_name = hook_cb->hook_name;
|
cp->trace2_hook_name = hook_cb->hook_name;
|
||||||
cp->dir = hook_cb->options->dir;
|
cp->dir = hook_cb->options->dir;
|
||||||
|
Loading…
Reference in New Issue
Block a user