diff options
| author | Junio C Hamano <gitster@pobox.com> | 2026-01-15 11:12:53 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-01-15 13:02:38 -0800 |
| commit | a3d1f391d35762162356201028fb73774a6c4a8b (patch) | |
| tree | 4b27ddcff1e2c2a24f34eccd2c50cb0275b39b2f /transport.c | |
| parent | 7264e61d87e58b9d0f5e6424c47c11e9657dfb75 (diff) | |
| download | git-a3d1f391d35762162356201028fb73774a6c4a8b.tar.xz | |
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.
Diffstat (limited to 'transport.c')
| -rw-r--r-- | transport.c | 89 |
1 files changed, 44 insertions, 45 deletions
diff --git a/transport.c b/transport.c index 6d0f02be5d..c7f06a7382 100644 --- a/transport.c +++ b/transport.c @@ -1316,66 +1316,65 @@ static void die_with_unpushed_submodules(struct string_list *needs_pushing) die(_("Aborting.")); } -struct feed_pre_push_hook_data { +static int run_pre_push_hook(struct transport *transport, + struct ref *remote_refs) +{ + int ret = 0, x; + struct ref *r; + struct child_process proc = CHILD_PROCESS_INIT; struct strbuf buf; - const struct ref *refs; -}; + const char *hook_path = find_hook(the_repository, "pre-push"); -static int pre_push_hook_feed_stdin(int hook_stdin_fd, void *pp_cb UNUSED, void *pp_task_cb) -{ - struct feed_pre_push_hook_data *data = pp_task_cb; - const struct ref *r = data->refs; - int ret = 0; + if (!hook_path) + return 0; - if (!r) - return 1; /* no more refs */ + strvec_push(&proc.args, hook_path); + strvec_push(&proc.args, transport->remote->name); + strvec_push(&proc.args, transport->url); - data->refs = r->next; + proc.in = -1; + proc.trace2_hook_name = "pre-push"; - switch (r->status) { - case REF_STATUS_REJECT_NONFASTFORWARD: - case REF_STATUS_REJECT_REMOTE_UPDATED: - case REF_STATUS_REJECT_STALE: - case REF_STATUS_UPTODATE: - return 0; /* skip refs which won't be pushed */ - default: - break; + if (start_command(&proc)) { + finish_command(&proc); + return -1; } - if (!r->peer_ref) - return 0; - - strbuf_reset(&data->buf); - strbuf_addf(&data->buf, "%s %s %s %s\n", - r->peer_ref->name, oid_to_hex(&r->new_oid), - r->name, oid_to_hex(&r->old_oid)); + sigchain_push(SIGPIPE, SIG_IGN); - ret = write_in_full(hook_stdin_fd, data->buf.buf, data->buf.len); - if (ret < 0 && errno != EPIPE) - return ret; /* We do not mind if a hook does not read all refs. */ + strbuf_init(&buf, 256); - return 0; -} + for (r = remote_refs; r; r = r->next) { + if (!r->peer_ref) continue; + if (r->status == REF_STATUS_REJECT_NONFASTFORWARD) continue; + if (r->status == REF_STATUS_REJECT_STALE) continue; + if (r->status == REF_STATUS_REJECT_REMOTE_UPDATED) continue; + if (r->status == REF_STATUS_UPTODATE) continue; -static int run_pre_push_hook(struct transport *transport, - struct ref *remote_refs) -{ - struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; - struct feed_pre_push_hook_data data; - int ret = 0; + strbuf_reset(&buf); + strbuf_addf( &buf, "%s %s %s %s\n", + r->peer_ref->name, oid_to_hex(&r->new_oid), + r->name, oid_to_hex(&r->old_oid)); - strvec_push(&opt.args, transport->remote->name); - strvec_push(&opt.args, transport->url); + if (write_in_full(proc.in, buf.buf, buf.len) < 0) { + /* We do not mind if a hook does not read all refs. */ + if (errno != EPIPE) + ret = -1; + break; + } + } - strbuf_init(&data.buf, 0); - data.refs = remote_refs; + strbuf_release(&buf); - opt.feed_pipe = pre_push_hook_feed_stdin; - opt.feed_pipe_cb_data = &data; + x = close(proc.in); + if (!ret) + ret = x; - ret = run_hooks_opt(the_repository, "pre-push", &opt); + sigchain_pop(SIGPIPE); - strbuf_release(&data.buf); + x = finish_command(&proc); + if (!ret) + ret = x; return ret; } |
