@@ -1199,31 +1199,14 @@ static void die_with_unpushed_submodules(struct string_list *needs_pushing)
static int run_pre_push_hook(struct transport *transport,
struct ref *remote_refs)
{
- int ret = 0, x;
+ int ret = 0;
+ struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
+ struct strbuf tmp = STRBUF_INIT;
struct ref *r;
- struct child_process proc = CHILD_PROCESS_INIT;
- struct strbuf buf;
- const char *argv[4];
-
- if (!(argv[0] = find_hook("pre-push")))
- return 0;
-
- argv[1] = transport->remote->name;
- argv[2] = transport->url;
- argv[3] = NULL;
-
- proc.argv = argv;
- proc.in = -1;
- proc.trace2_hook_name = "pre-push";
-
- if (start_command(&proc)) {
- finish_command(&proc);
- return -1;
- }
-
- sigchain_push(SIGPIPE, SIG_IGN);
+ struct string_list to_stdin = STRING_LIST_INIT_DUP;
- strbuf_init(&buf, 256);
+ strvec_push(&opt.args, transport->remote->name);
+ strvec_push(&opt.args, transport->url);
for (r = remote_refs; r; r = r->next) {
if (!r->peer_ref) continue;
@@ -1232,30 +1215,20 @@ static int run_pre_push_hook(struct transport *transport,
if (r->status == REF_STATUS_REJECT_REMOTE_UPDATED) continue;
if (r->status == REF_STATUS_UPTODATE) continue;
- strbuf_reset(&buf);
- strbuf_addf( &buf, "%s %s %s %s\n",
+ strbuf_reset(&tmp);
+ strbuf_addf(&tmp, "%s %s %s %s",
r->peer_ref->name, oid_to_hex(&r->new_oid),
r->name, oid_to_hex(&r->old_oid));
-
- 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;
- }
+ string_list_append(&to_stdin, tmp.buf);
}
- strbuf_release(&buf);
-
- x = close(proc.in);
- if (!ret)
- ret = x;
-
- sigchain_pop(SIGPIPE);
+ opt.feed_pipe = pipe_from_string_list;
+ opt.feed_pipe_ctx = &to_stdin;
- x = finish_command(&proc);
- if (!ret)
- ret = x;
+ ret = run_hooks("pre-push", &opt);
+ run_hooks_opt_clear(&opt);
+ strbuf_release(&tmp);
+ string_list_clear(&to_stdin, 0);
return ret;
}