hook: convert 'post-rewrite' hook in sequencer.c to hook API

Replace the custom run-command calls used by post-rewrite with the newer and simpler hook_run_opt(), which does not need to create a custom 'struct child_process' or call find_hook(). Another benefit of using the hook API is that hook_run_opt() handles the SIGPIPE toggle logic. 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Emily Shaffer committed Dec 26, 2025 at 14:23 UTC 05eccff8c7e6c58bad777a642ab8a28c87602d36
1 file changed +25 -17
sequencer.c
+25 -17
@@ -1292,32 +1292,40 @@ int update_head_with_reflog(const struct commit *old_head,
1292 return ret;
1293 }
1294
1295 +static int pipe_from_strbuf(int hook_stdin_fd, void *pp_cb, void *pp_task_cb UNUSED)
1296 +{
1297 + struct hook_cb_data *hook_cb = pp_cb;
1298 + struct strbuf *to_pipe = hook_cb->options->feed_pipe_ctx;
1299 + int ret;
1300 +
1301 + if (!to_pipe)
1302 + BUG("pipe_from_strbuf called without feed_pipe_ctx");
1303 +
1304 + ret = write_in_full(hook_stdin_fd, to_pipe->buf, to_pipe->len);
1305 + if (ret < 0 && errno != EPIPE)
1306 + return ret;
1307 +
1308 + return 1; /* done writing */
1309 +}
1310 +
1311 static int run_rewrite_hook(const struct object_id *oldoid,
1312 const struct object_id *newoid)
1313 {
1298 - struct child_process proc = CHILD_PROCESS_INIT;
1314 + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
1315 int code;
1316 struct strbuf sb = STRBUF_INIT;
1301 - const char *hook_path = find_hook(the_repository, "post-rewrite");
1317
1303 - if (!hook_path)
1304 - return 0;
1318 + strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid));
1319
1306 - strvec_pushl(&proc.args, hook_path, "amend", NULL);
1307 - proc.in = -1;
1308 - proc.stdout_to_stderr = 1;
1309 - proc.trace2_hook_name = "post-rewrite";
1320 + opt.feed_pipe_ctx = &sb;
1321 + opt.feed_pipe = pipe_from_strbuf;
1322 +
1323 + strvec_push(&opt.args, "amend");
1324 +
1325 + code = run_hooks_opt(the_repository, "post-rewrite", &opt);
1326
1311 - code = start_command(&proc);
1312 - if (code)
1313 - return code;
1314 - strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid));
1315 - sigchain_push(SIGPIPE, SIG_IGN);
1316 - write_in_full(proc.in, sb.buf, sb.len);
1317 - close(proc.in);
1327 strbuf_release(&sb);
1319 - sigchain_pop(SIGPIPE);
1320 - return finish_command(&proc);
1328 + return code;
1329 }
1330
1331 void commit_post_rewrite(struct repository *r,