Re: [PATCH v3 04/10] transport: convert pre-push to hook API
On Mon, 24 Nov 2025, Junio C Hamano <gitster@pobox.com> wrote:
Show 31 quoted lines
> Adrian Ratiu <adrian.ratiu@collabora.com> writes:
>
>> From: Emily Shaffer <emilyshaffer@google.com>
>>
>> Move the pre-push hook from custom run-command invocations to
>> the new hook API which doesn't require a custom child_process
>> structure and signal toggling.
>>
>> Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com> ---
>> transport.c | 95
>> ++++++++++++++++++++++++++++------------------------- 1 file
>> changed, 51 insertions(+), 44 deletions(-)
>
> So, this completes what 01/10 hinted at when it created a
> generalized interface modelled after how pre-push hook was run.
> We used to spawn the pre-push hook and fed its standard input by
> calling write_in_full(). Now that is largely encapsulated in
> run_hooks_opt(), but the application specific processing
> (namely, what we write to the pre-push hook, i.e. the list of
> ref update status) is given in pre_push_hook_feed_stdin()
> callback defined here and given to the run_hooks_opt() call.
>
> In other words, the mechanisms are very cleanly separated
> between generic machinery and the client specific processing.
> Nice.
>
> How and where does the pipe we are writing into
> (i.e. hook_stdin_fd) gets closed when we are done with the
> child?
That happens in run-command.c:pp_buffer_stdin() which calls the
feed pipe callback then closes the fd when feeding is finished:
/**
* Feed the pipe: * ret < 0 means error * ret == 0 means there
is more data to be fed * ret > 0 means feeding finished */
ret = opts->feed_pipe(proc->in, opts->data, pp->children[i].data);
...