From a3d1f391d35762162356201028fb73774a6c4a8b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 15 Jan 2026 11:12:53 -0800 Subject: Revert "Merge branch 'ar/run-command-hook'" This reverts commit f406b8955295d01089ba2baf35eceadff2d11cae, reversing changes made to 1627809eeff75e6ec936fc609e7be46d5eb2fa9e. It seems to have caused a few regressions, two of the three known ones we have proposed solutions for. Let's give ourselves a bit more room to maneuver during the pre-release freeze period and restart once the 2.53 ships. --- refs.c | 100 +++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 48 insertions(+), 52 deletions(-) (limited to 'refs.c') diff --git a/refs.c b/refs.c index e06e0cb072..046b695bb2 100644 --- a/refs.c +++ b/refs.c @@ -2422,72 +2422,68 @@ static int ref_update_reject_duplicates(struct string_list *refnames, return 0; } -struct transaction_feed_cb_data { - size_t index; - struct strbuf buf; -}; - -static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_task_cb) +static int run_transaction_hook(struct ref_transaction *transaction, + const char *state) { - struct hook_cb_data *hook_cb = pp_cb; - struct ref_transaction *transaction = hook_cb->options->feed_pipe_ctx; - struct transaction_feed_cb_data *feed_cb_data = pp_task_cb; - struct strbuf *buf = &feed_cb_data->buf; - struct ref_update *update; - size_t i = feed_cb_data->index++; - int ret; - - if (i >= transaction->nr) - return 1; /* No more refs to process */ - - update = transaction->updates[i]; + struct child_process proc = CHILD_PROCESS_INIT; + struct strbuf buf = STRBUF_INIT; + const char *hook; + int ret = 0; - if (update->flags & REF_LOG_ONLY) - return 0; + hook = find_hook(transaction->ref_store->repo, "reference-transaction"); + if (!hook) + return ret; - strbuf_reset(buf); + strvec_pushl(&proc.args, hook, state, NULL); + proc.in = -1; + proc.stdout_to_stderr = 1; + proc.trace2_hook_name = "reference-transaction"; - if (!(update->flags & REF_HAVE_OLD)) - strbuf_addf(buf, "%s ", oid_to_hex(null_oid(the_hash_algo))); - else if (update->old_target) - strbuf_addf(buf, "ref:%s ", update->old_target); - else - strbuf_addf(buf, "%s ", oid_to_hex(&update->old_oid)); + ret = start_command(&proc); + if (ret) + return ret; - if (!(update->flags & REF_HAVE_NEW)) - strbuf_addf(buf, "%s ", oid_to_hex(null_oid(the_hash_algo))); - else if (update->new_target) - strbuf_addf(buf, "ref:%s ", update->new_target); - else - strbuf_addf(buf, "%s ", oid_to_hex(&update->new_oid)); + sigchain_push(SIGPIPE, SIG_IGN); - strbuf_addf(buf, "%s\n", update->refname); + for (size_t i = 0; i < transaction->nr; i++) { + struct ref_update *update = transaction->updates[i]; - ret = write_in_full(hook_stdin_fd, buf->buf, buf->len); - if (ret < 0 && errno != EPIPE) - return ret; + if (update->flags & REF_LOG_ONLY) + continue; - return 0; /* no more input to feed */ -} + strbuf_reset(&buf); -static int run_transaction_hook(struct ref_transaction *transaction, - const char *state) -{ - struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; - struct transaction_feed_cb_data feed_ctx = { 0 }; - int ret = 0; + if (!(update->flags & REF_HAVE_OLD)) + strbuf_addf(&buf, "%s ", oid_to_hex(null_oid(the_hash_algo))); + else if (update->old_target) + strbuf_addf(&buf, "ref:%s ", update->old_target); + else + strbuf_addf(&buf, "%s ", oid_to_hex(&update->old_oid)); - strvec_push(&opt.args, state); + if (!(update->flags & REF_HAVE_NEW)) + strbuf_addf(&buf, "%s ", oid_to_hex(null_oid(the_hash_algo))); + else if (update->new_target) + strbuf_addf(&buf, "ref:%s ", update->new_target); + else + strbuf_addf(&buf, "%s ", oid_to_hex(&update->new_oid)); - opt.feed_pipe = transaction_hook_feed_stdin; - opt.feed_pipe_ctx = transaction; - opt.feed_pipe_cb_data = &feed_ctx; + strbuf_addf(&buf, "%s\n", update->refname); - strbuf_init(&feed_ctx.buf, 0); + if (write_in_full(proc.in, buf.buf, buf.len) < 0) { + if (errno != EPIPE) { + /* Don't leak errno outside this API */ + errno = 0; + ret = -1; + } + break; + } + } - ret = run_hooks_opt(transaction->ref_store->repo, "reference-transaction", &opt); + close(proc.in); + sigchain_pop(SIGPIPE); + strbuf_release(&buf); - strbuf_release(&feed_ctx.buf); + ret |= finish_command(&proc); return ret; } -- cgit v1.3