From: Adrian Ratiu <adrian.ratiu@collabora.com>
To: phillip.wood@dunelm.org.uk, git@vger.kernel.org
Cc: "Emily Shaffer" <emilyshaffer@google.com>,
"Rodrigo Damazio Bovendorp" <rdamazio@google.com>,
"Junio C Hamano" <gitster@pobox.com>,
"Patrick Steinhardt" <ps@pks.im>,
"Josh Steadmon" <steadmon@google.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH 03/10] hook: convert 'post-rewrite' hook in sequencer.c to hook.h
Date: Fri, 26 Sep 2025 18:53:41 +0300 [thread overview]
Message-ID: <87zfahmcqi.fsf@collabora.com> (raw)
In-Reply-To: <f408e46c-650a-4632-9628-cf817e393e7f@gmail.com>
On Fri, 26 Sep 2025, Phillip Wood <phillip.wood123@gmail.com>
wrote:
> Hi Adrian
>
> Thanks for working on this, it would be really good to be able
> to run hooks in parallel.
Hi Phillip and thank you for your feedback! It is very valuable
and appreciated on all my patch series.
>
> On 25/09/2025 13:53, Adrian Ratiu wrote:
>> From: Emily Shaffer <emilyshaffer@google.com> By using
>> 'hook.h' for 'post-rewrite', we simplify hook invocations by
>> not needing to put together our own 'struct child_process'.
>
> Right so instead we use the new api to feed an strbuf into the
> hook's stdin, sounds reasonable.
That is the high level idea yes, maybe I can improve the commit
msg a bit in v2 to make it clearer (those are not actually my
words :).
Slightly unrelated:
I actually thought about putting pipe_from_strbuf() into hook.c or
someplace similar because it's a generic utility function, however
this is the only hook which needs it, so I've left it in
sequencer.c.
>> The signal handling that's being removed by this commit now
>> takes place in run-command.h:run_processes_parallel(), so it is
>> OK to remove them here. 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> ---
>> sequencer.c | 62
>> ++++++++++++++++++++++++++++++++--------------------- 1 file
>> changed, 38 insertions(+), 24 deletions(-)
>> diff --git a/sequencer.c b/sequencer.c index
>> 9ae40a91b2..93cd6ab1f2 100644 --- a/sequencer.c +++
>> b/sequencer.c @@ -1298,32 +1298,46 @@ int
>> update_head_with_reflog(const struct commit *old_head,
>> return ret; }
>> +static int pipe_from_strbuf(int hook_stdin_fd, void *pp_cb,
>> void *pp_task_cb UNUSED) +{ + struct hook_cb_data
>> *hook_cb = pp_cb; + struct strbuf *to_pipe =
>> hook_cb->options->feed_pipe_ctx; + int ret; + + if
>> (!to_pipe || !to_pipe->len) + return 1; /*
>> nothing to feed */
>
> Why are we running the hook if there is nothing to pass to it?
run-commands has a ppoll loop which calls the stdin feed callback
(pipe_from_stdbuf in this case) repeatedly until it signals
reading is finished by return 1;
Now that I look again at this code, I made the mistake of assuming
it needs to work recursively:
1. write the strbuf
2. reset the strbuf (return 0)
3. next callback sees the strbuf is empty and stops the loop
(return 1)
The line you're asking asking here is actually step 3. :)
This all can be simplified by writing just once and returning 1
immediately since it's just a simple strbuf to write to stdin.
We still need to keep the pointer null check though, just in case.
>> + ret = write_in_full(hook_stdin_fd, to_pipe->buf,
>> to_pipe->len);
>
> This will block until the hook has read all of the input. Unless
> the hook drains and closes stdin before it does anything else
> it will block the parallel execution of other hooks.
I double checked the write_in_full / xwrite implementations. :)
Sorry for the wall of text btw, I try to explain as best I can.
I think it blocks only if/when the stdin fd pipe is full, which
can't happen in this specific instance because the strbuf data is
small, so the write_in_full() call just writes all it has, then
returns.
In other words, the most important aspect I think is how much data
we are writing to the pipe in every single callback call.
The idea of these callbacks is to write small chunks of data at a
time, then switch context: it's usually the child hook processes
which end up blocking for their stdin input which is fed by the
parent which multiplexes between the parallel processes.
Of course, a balance needs to be found: I've noticed, in other
hooks, that if we write too small chunks of data in each callback,
we unnecessarily increase wait times for hooks.
This can be seen especially in hooks like post-receive which can
get a lot of data: if we feed one line at a time and let's say
run-command's ppoll loop adds 100ms delay between callbacks, then
from 7-800 ms we end up with something like 90 seconds!
Of course that is a pathological case and the solution there is to
batch more data in a single callback write. I've actually batched
500 lines in every write for those update hooks (we can do more or
less).
None of this is set in stone and can be changed. What I tried is
to get similar performance with what we had before these
callbacks.
If you notice any specific degradation or unnecessary blocking,
please raise it up and we can address it.
>> + if (ret < 0) { + if (errno == EPIPE) { +
>> return 1; /* child closed pipe, nothing more to feed */ +
>> }
>
> Style: we don't use braces for single statement bodies.
Ack, will fix in v2.
>> + return ret; + } + + /* Reset the input buffer
>> to avoid sending it again */ + strbuf_reset(to_pipe);
>
> Shouldn't the return value do that?
Yes, as explained above with my 1 2 3 recursive steps above we
don't actually need this and the function can be simplified.
I'll do that in v2.
>> + return ret; +}
>
> The changes to run_rewrite_hook() look fine. I'm not sure whats
> happening in commit_post_rewrite() below though - am I missing
> something or have you just renamed "child" -> "notes_cp". If so
> I don't see what that has to do with using the new api.
Thanks for spotting this!
It's actually a leftover from Emily and Aevar's string_list API
implementation which I've rewritten / removed and this hunk fell
through the cracks. :)
Will drop it in v2.
>
> Thanks
>
> Phillip
>
>> void commit_post_rewrite(struct repository *r,
>> @@ -5140,16 +5154,16 @@ static int pick_commits(struct repository *r,
>> flush_rewritten_pending();
>> if (!stat(rebase_path_rewritten_list(), &st) &&
>> st.st_size > 0) {
>> - struct child_process child = CHILD_PROCESS_INIT;
>> + struct child_process notes_cp = CHILD_PROCESS_INIT;
>> struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT;
>>
>> - child.in = open(rebase_path_rewritten_list(), O_RDONLY);
>> - child.git_cmd = 1;
>> - strvec_push(&child.args, "notes");
>> - strvec_push(&child.args, "copy");
>> - strvec_push(&child.args, "--for-rewrite=rebase");
>> + notes_cp.in = open(rebase_path_rewritten_list(), O_RDONLY);
>> + notes_cp.git_cmd = 1;
>> + strvec_push(¬es_cp.args, "notes");
>> + strvec_push(¬es_cp.args, "copy");
>> + strvec_push(¬es_cp.args, "--for-rewrite=rebase");
>> /* we don't care if this copying failed */
>> - run_command(&child);
>> + run_command(¬es_cp);
>>
>> hook_opt.path_to_stdin = rebase_path_rewritten_list();
>> strvec_push(&hook_opt.args, "rebase");
next prev parent reply other threads:[~2025-09-26 15:54 UTC|newest]
Thread overview: 137+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-25 12:53 [PATCH 00/10] Convert remaining hooks to hook.h Adrian Ratiu
2025-09-25 12:53 ` [PATCH 01/10] run-command: add stdin callback for parallelization Adrian Ratiu
2025-10-02 6:34 ` Patrick Steinhardt
2025-10-02 15:46 ` Junio C Hamano
2025-10-06 13:01 ` Adrian Ratiu
2025-10-06 12:59 ` Adrian Ratiu
2025-10-14 17:35 ` Adrian Ratiu
2025-09-25 12:53 ` [PATCH 02/10] hook: provide stdin via callback Adrian Ratiu
2025-09-25 20:05 ` Junio C Hamano
2025-09-26 12:03 ` Adrian Ratiu
2025-10-10 19:57 ` Emily Shaffer
2025-10-13 14:47 ` Adrian Ratiu
2025-09-25 12:53 ` [PATCH 03/10] hook: convert 'post-rewrite' hook in sequencer.c to hook.h Adrian Ratiu
2025-09-25 20:15 ` Junio C Hamano
2025-09-26 12:29 ` Adrian Ratiu
2025-09-26 14:12 ` Phillip Wood
2025-09-26 15:53 ` Adrian Ratiu [this message]
2025-09-29 10:11 ` Phillip Wood
2025-09-26 17:52 ` Junio C Hamano
2025-09-29 7:33 ` Adrian Ratiu
2025-10-02 6:34 ` Patrick Steinhardt
2025-10-08 7:04 ` Adrian Ratiu
2025-09-25 12:53 ` [PATCH 04/10] transport: convert pre-push hook " Adrian Ratiu
2025-09-25 18:58 ` D. Ben Knoble
2025-09-26 13:02 ` Adrian Ratiu
2025-09-26 14:11 ` Phillip Wood
2025-09-29 11:33 ` Adrian Ratiu
2025-09-25 12:53 ` [PATCH 05/10] reference-transaction: use hook.h to run hooks Adrian Ratiu
2025-09-25 21:45 ` Junio C Hamano
2025-09-26 13:03 ` Adrian Ratiu
2025-10-02 6:34 ` Patrick Steinhardt
2025-10-08 12:26 ` Adrian Ratiu
2025-09-25 12:53 ` [PATCH 06/10] run-command: allow capturing of collated output Adrian Ratiu
2025-09-25 21:52 ` Junio C Hamano
2025-09-26 14:14 ` Adrian Ratiu
2025-09-25 12:53 ` [PATCH 07/10] hooks: allow callers to capture output Adrian Ratiu
2025-09-25 12:53 ` [PATCH 08/10] receive-pack: convert 'update' hook to hook.h Adrian Ratiu
2025-09-25 21:53 ` Junio C Hamano
2025-10-10 19:57 ` Emily Shaffer
2025-10-17 8:27 ` Adrian Ratiu
2025-09-25 12:53 ` [PATCH 09/10] post-update: use hook.h library Adrian Ratiu
2025-09-25 18:02 ` [PATCH 10/10] receive-pack: convert receive hooks to hook.h Adrian Ratiu
2025-10-10 19:57 ` [PATCH 00/10] Convert remaining " Emily Shaffer
2025-10-17 14:15 ` [PATCH v2 " Adrian Ratiu
2025-10-17 14:15 ` [PATCH v2 01/10] run-command: add stdin callback for parallelization Adrian Ratiu
2025-10-21 7:40 ` Patrick Steinhardt
2025-10-17 14:15 ` [PATCH v2 02/10] hook: provide stdin via callback Adrian Ratiu
2025-10-21 7:41 ` Patrick Steinhardt
2025-10-21 7:41 ` Patrick Steinhardt
2025-10-21 14:44 ` Adrian Ratiu
2025-10-17 14:15 ` [PATCH v2 03/10] hook: convert 'post-rewrite' hook in sequencer.c to hook API Adrian Ratiu
2025-10-21 7:41 ` Patrick Steinhardt
2025-10-21 15:44 ` Adrian Ratiu
2025-10-17 14:15 ` [PATCH v2 04/10] transport: convert pre-push " Adrian Ratiu
2025-10-21 7:41 ` Patrick Steinhardt
2025-10-21 16:04 ` Adrian Ratiu
2025-10-17 14:15 ` [PATCH v2 05/10] reference-transaction: use hook API instead of run-command Adrian Ratiu
2025-10-17 14:15 ` [PATCH v2 06/10] hook: allow overriding the ungroup option Adrian Ratiu
2025-10-17 14:15 ` [PATCH v2 07/10] run-command: allow capturing of collated output Adrian Ratiu
2025-10-21 7:41 ` Patrick Steinhardt
2025-10-21 16:25 ` Adrian Ratiu
2025-10-17 14:15 ` [PATCH v2 08/10] hooks: allow callers to capture output Adrian Ratiu
2025-10-17 14:15 ` [PATCH v2 09/10] receive-pack: convert update hooks to new API Adrian Ratiu
2025-10-28 18:39 ` Kristoffer Haugsbakk
2025-10-17 14:15 ` [PATCH v2 10/10] receive-pack: convert receive hooks to hook API Adrian Ratiu
2025-10-21 7:41 ` Patrick Steinhardt
2025-10-28 18:42 ` Kristoffer Haugsbakk
2025-10-29 13:46 ` Adrian Ratiu
2025-10-29 13:50 ` Kristoffer Haugsbakk
2025-11-15 19:48 ` Junio C Hamano
2025-11-17 16:51 ` Adrian Ratiu
2025-10-21 7:40 ` [PATCH v2 00/10] Convert remaining hooks to hook.h Patrick Steinhardt
2025-10-21 16:34 ` Adrian Ratiu
2025-11-24 17:20 ` [PATCH v3 " Adrian Ratiu
2025-11-24 17:20 ` [PATCH v3 01/10] run-command: add stdin callback for parallelization Adrian Ratiu
2025-11-25 23:15 ` Junio C Hamano
2025-11-27 12:00 ` Adrian Ratiu
2025-11-24 17:20 ` [PATCH v3 02/10] hook: provide stdin via callback Adrian Ratiu
2025-11-29 13:03 ` Adrian Ratiu
2025-11-29 22:21 ` Junio C Hamano
2025-12-01 13:26 ` Adrian Ratiu
2025-11-24 17:20 ` [PATCH v3 03/10] hook: convert 'post-rewrite' hook in sequencer.c to hook API Adrian Ratiu
2025-11-24 17:20 ` [PATCH v3 04/10] transport: convert pre-push " Adrian Ratiu
2025-11-24 22:55 ` Junio C Hamano
2025-11-27 14:24 ` Adrian Ratiu
2025-11-24 17:20 ` [PATCH v3 05/10] reference-transaction: use hook API instead of run-command Adrian Ratiu
2025-11-24 17:20 ` [PATCH v3 06/10] hook: allow overriding the ungroup option Adrian Ratiu
2025-11-24 17:20 ` [PATCH v3 07/10] run-command: allow capturing of collated output Adrian Ratiu
2025-11-24 17:20 ` [PATCH v3 08/10] hooks: allow callers to capture output Adrian Ratiu
2025-11-24 17:20 ` [PATCH v3 09/10] receive-pack: convert update hooks to new API Adrian Ratiu
2025-11-24 17:20 ` [PATCH v3 10/10] receive-pack: convert receive hooks to hook API Adrian Ratiu
2025-12-04 14:15 ` [PATCH v4 00/11] Convert remaining hooks to hook.h Adrian Ratiu
2025-12-04 14:15 ` [PATCH v4 01/11] run-command: add first helper for pp child states Adrian Ratiu
2025-12-04 14:15 ` [PATCH v4 02/11] run-command: add stdin callback for parallelization Adrian Ratiu
2025-12-04 14:15 ` [PATCH v4 03/11] hook: provide stdin via callback Adrian Ratiu
2025-12-16 8:08 ` Patrick Steinhardt
2025-12-04 14:15 ` [PATCH v4 04/11] hook: convert 'post-rewrite' hook in sequencer.c to hook API Adrian Ratiu
2025-12-04 14:15 ` [PATCH v4 05/11] transport: convert pre-push " Adrian Ratiu
2025-12-16 8:08 ` Patrick Steinhardt
2025-12-16 9:09 ` Adrian Ratiu
2025-12-16 9:30 ` Patrick Steinhardt
2025-12-17 23:07 ` Junio C Hamano
2025-12-04 14:15 ` [PATCH v4 06/11] reference-transaction: use hook API instead of run-command Adrian Ratiu
2025-12-04 14:15 ` [PATCH v4 07/11] hook: allow overriding the ungroup option Adrian Ratiu
2025-12-04 14:15 ` [PATCH v4 08/11] run-command: allow capturing of collated output Adrian Ratiu
2025-12-04 14:15 ` [PATCH v4 09/11] hooks: allow callers to capture output Adrian Ratiu
2025-12-04 14:15 ` [PATCH v4 10/11] receive-pack: convert update hooks to new API Adrian Ratiu
2025-12-16 8:08 ` Patrick Steinhardt
2025-12-16 9:22 ` Adrian Ratiu
2025-12-04 14:15 ` [PATCH v4 11/11] receive-pack: convert receive hooks to hook API Adrian Ratiu
2025-12-18 17:11 ` [PATCH v5 00/11] Convert remaining hooks to hook.h Adrian Ratiu
2025-12-18 17:11 ` [PATCH v5 01/11] run-command: add first helper for pp child states Adrian Ratiu
2025-12-18 17:11 ` [PATCH v5 02/11] run-command: add stdin callback for parallelization Adrian Ratiu
2025-12-18 17:11 ` [PATCH v5 03/11] hook: provide stdin via callback Adrian Ratiu
2025-12-18 17:11 ` [PATCH v5 04/11] hook: convert 'post-rewrite' hook in sequencer.c to hook API Adrian Ratiu
2025-12-18 17:11 ` [PATCH v5 05/11] transport: convert pre-push " Adrian Ratiu
2025-12-18 17:11 ` [PATCH v5 06/11] reference-transaction: use hook API instead of run-command Adrian Ratiu
2025-12-18 17:11 ` [PATCH v5 07/11] hook: allow overriding the ungroup option Adrian Ratiu
2025-12-18 17:11 ` [PATCH v5 08/11] run-command: allow capturing of collated output Adrian Ratiu
2025-12-18 17:11 ` [PATCH v5 09/11] hooks: allow callers to capture output Adrian Ratiu
2025-12-18 17:11 ` [PATCH v5 10/11] receive-pack: convert update hooks to new API Adrian Ratiu
2025-12-18 17:11 ` [PATCH v5 11/11] receive-pack: convert receive hooks to hook API Adrian Ratiu
2025-12-19 12:38 ` Patrick Steinhardt
2025-12-20 10:40 ` Adrian Ratiu
2025-12-26 12:23 ` [PATCH v6 00/11] Convert remaining hooks to hook.h Adrian Ratiu
2025-12-26 12:23 ` [PATCH v6 01/11] run-command: add first helper for pp child states Adrian Ratiu
2025-12-26 12:23 ` [PATCH v6 02/11] run-command: add stdin callback for parallelization Adrian Ratiu
2025-12-26 12:23 ` [PATCH v6 03/11] hook: provide stdin via callback Adrian Ratiu
2025-12-26 12:23 ` [PATCH v6 04/11] hook: convert 'post-rewrite' hook in sequencer.c to hook API Adrian Ratiu
2025-12-26 12:23 ` [PATCH v6 05/11] transport: convert pre-push " Adrian Ratiu
2025-12-26 12:23 ` [PATCH v6 06/11] reference-transaction: use hook API instead of run-command Adrian Ratiu
2025-12-26 12:23 ` [PATCH v6 07/11] hook: allow overriding the ungroup option Adrian Ratiu
2025-12-26 12:23 ` [PATCH v6 08/11] run-command: allow capturing of collated output Adrian Ratiu
2025-12-26 12:23 ` [PATCH v6 09/11] hooks: allow callers to capture output Adrian Ratiu
2025-12-26 12:23 ` [PATCH v6 10/11] receive-pack: convert update hooks to new API Adrian Ratiu
2025-12-26 12:23 ` [PATCH v6 11/11] receive-pack: convert receive hooks to hook API Adrian Ratiu
2025-12-28 11:32 ` [PATCH v6 00/11] Convert remaining hooks to hook.h Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zfahmcqi.fsf@collabora.com \
--to=adrian.ratiu@collabora.com \
--cc=avarab@gmail.com \
--cc=emilyshaffer@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
--cc=rdamazio@google.com \
--cc=steadmon@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).