diff options
author | Emily Shaffer <emilyshaffer@google.com> | 2023-02-08 22:21:13 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-02-08 23:50:03 +0300 |
commit | 917e0802493a39d77c4bdbdf9aaa5d8d69b7a7b0 (patch) | |
tree | cd486d5641f1f5ca2df22e39ee6310dd1570c567 /builtin/am.c | |
parent | 540267304d37d6257edb3144e770693071d8fbb7 (diff) |
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>
Diffstat (limited to 'builtin/am.c')
-rw-r--r-- | builtin/am.c | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/builtin/am.c b/builtin/am.c index 82a41cbfc4..8be91617fe 100644 --- a/builtin/am.c +++ b/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) { - struct child_process cp = CHILD_PROCESS_INIT; - const char *hook = find_hook("post-rewrite"); - int ret; - - if (!hook) - return 0; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; - strvec_push(&cp.args, hook); - strvec_push(&cp.args, "rebase"); + strvec_push(&opt.args, "rebase"); + opt.path_to_stdin = am_path(state, "rewritten"); - 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; + return run_hooks_opt("post-rewrite", &opt); } /** |