diff options
| author | Junio C Hamano <gitster@pobox.com> | 2023-02-22 14:55:45 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2023-02-22 14:55:45 -0800 |
| commit | 5048df67b295baeaaa6dafb16ff712bd2a62731a (patch) | |
| tree | 3c1325ae2d6ddb123323fc30452dd56043e66c51 /builtin | |
| parent | Merge branch 'ab/various-leak-fixes' (diff) | |
| parent | hook: support a --to-stdin=<path> option (diff) | |
| download | git-5048df67b295baeaaa6dafb16ff712bd2a62731a.tar.gz git-5048df67b295baeaaa6dafb16ff712bd2a62731a.zip | |
Merge branch 'ab/hook-api-with-stdin'
Extend the run-hooks API to allow feeding data from the standard
input when running the hook script(s).
* ab/hook-api-with-stdin:
hook: support a --to-stdin=<path> option
sequencer: use the new hook API for the simpler "post-rewrite" call
hook API: support passing stdin to hooks, convert am's 'post-rewrite'
run-command: allow stdin for run_processes_parallel
run-command.c: remove dead assignment in while-loop
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/am.c | 20 | ||||
| -rw-r--r-- | builtin/hook.c | 4 |
2 files changed, 7 insertions, 17 deletions
diff --git a/builtin/am.c b/builtin/am.c index 8b3dcb66f0..e0848ddadf 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); } /** diff --git a/builtin/hook.c b/builtin/hook.c index b6530d189a..f95b7965c5 100644 --- a/builtin/hook.c +++ b/builtin/hook.c @@ -7,7 +7,7 @@ #include "strvec.h" #define BUILTIN_HOOK_RUN_USAGE \ - N_("git hook run [--ignore-missing] <hook-name> [-- <hook-args>]") + N_("git hook run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]") static const char * const builtin_hook_usage[] = { BUILTIN_HOOK_RUN_USAGE, @@ -28,6 +28,8 @@ static int run(int argc, const char **argv, const char *prefix) struct option run_options[] = { OPT_BOOL(0, "ignore-missing", &ignore_missing, N_("silently ignore missing requested <hook-name>")), + OPT_STRING(0, "to-stdin", &opt.path_to_stdin, N_("path"), + N_("file to read into hooks' stdin")), OPT_END(), }; int ret; |
