mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
hook API: don't segfault on strbuf_addf() to NULL "out"
Fix a logic error ina082345372(hook API: fix v2.36.0 regression: hooks should be connected to a TTY, 2022-06-07). When it started using the "ungroup" API added infd3aaf53f7(run-command: add an "ungroup" option to run_process_parallel(), 2022-06-07) it should have made the same sort of change thatfd3aaf53f7itself made in "t/helper/test-run-command.c". The correct way to emit this "Couldn't start" output with "ungroup" would be: fprintf(stderr, _("Couldn't start hook '%s'\n"), hook_path); But we should instead remove the emitting of this output. As the added test shows we already emit output when we can't run the child. The "cannot run" output here is emitted by run-command.c's child_err_spew(). So the addition of the "Couldn't start hook" output here in96e7225b31(hook: add 'run' subcommand, 2021-12-22) was always redundant. For the pre-commit hook we'll now emit exactly the same output as we did beforef443246b9f(commit: convert {pre-commit,prepare-commit-msg} hook to hook.h, 2021-12-22) (and likewise for others). We could at this point add this to the pick_next_hook() callbacks in hook.c: assert(!out); assert(!*pp_task_cb); And this to notify_start_failure() and notify_hook_finished() (in the latter case the parameter is called "pp_task_cp"): assert(!out); assert(!pp_task_cb); But let's leave any such instrumentation for some eventual cleanup of the "ungroup" API. Reported-by: Ilya K <me@0upti.me> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Emily Shaffer <emilyshaffer@google.com> Reviewed-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
a082345372
commit
99ddc24672
7
hook.c
7
hook.c
@@ -62,9 +62,6 @@ static int pick_next_hook(struct child_process *cp,
|
||||
strvec_push(&cp->args, hook_path);
|
||||
strvec_pushv(&cp->args, hook_cb->options->args.v);
|
||||
|
||||
/* Provide context for errors if necessary */
|
||||
*pp_task_cb = (char *)hook_path;
|
||||
|
||||
/*
|
||||
* This pick_next_hook() will be called again, we're only
|
||||
* running one hook, so indicate that no more work will be
|
||||
@@ -80,13 +77,9 @@ static int notify_start_failure(struct strbuf *out,
|
||||
void *pp_task_cp)
|
||||
{
|
||||
struct hook_cb_data *hook_cb = pp_cb;
|
||||
const char *hook_path = pp_task_cp;
|
||||
|
||||
hook_cb->rc |= 1;
|
||||
|
||||
strbuf_addf(out, _("Couldn't start hook '%s'\n"),
|
||||
hook_path);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user