MCPcopy Index your code
hub / github.com/git/git / pick_next_hook

Function pick_next_hook

hook.c:573–636  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

571}
572
573static int pick_next_hook(struct child_process *cp,
574 struct strbuf *out UNUSED,
575 void *pp_cb,
576 void **pp_task_cb)
577{
578 struct hook_cb_data *hook_cb = pp_cb;
579 struct string_list *hook_list = hook_cb->hook_command_list;
580 struct hook *h;
581
582 do {
583 if (hook_cb->hook_to_run_index >= hook_list->nr)
584 return 0;
585 h = hook_list->items[hook_cb->hook_to_run_index++].util;
586 } while (h->kind == HOOK_CONFIGURED &&
587 (h->u.configured.disabled || h->u.configured.event_disabled));
588
589 cp->no_stdin = 1;
590 strvec_pushv(&cp->env, hook_cb->options->env.v);
591
592 if (hook_cb->options->path_to_stdin && hook_cb->options->feed_pipe)
593 BUG("options path_to_stdin and feed_pipe are mutually exclusive");
594
595 /* reopen the file for stdin; run_command closes it. */
596 if (hook_cb->options->path_to_stdin) {
597 cp->no_stdin = 0;
598 cp->in = xopen(hook_cb->options->path_to_stdin, O_RDONLY);
599 }
600
601 if (hook_cb->options->feed_pipe) {
602 cp->no_stdin = 0;
603 /* start_command() will allocate a pipe / stdin fd for us */
604 cp->in = -1;
605 }
606
607 cp->stdout_to_stderr = hook_cb->options->stdout_to_stderr;
608 cp->trace2_hook_name = hook_cb->hook_name;
609 cp->dir = hook_cb->options->dir;
610
611 /* Add hook exec paths or commands */
612 if (h->kind == HOOK_TRADITIONAL) {
613 strvec_push(&cp->args, h->u.traditional.path);
614 } else if (h->kind == HOOK_CONFIGURED) {
615 /* to enable oneliners, let config-specified hooks run in shell. */
616 cp->use_shell = true;
617 if (!h->u.configured.command)
618 BUG("non-disabled HOOK_CONFIGURED hook has no command");
619 strvec_push(&cp->args, h->u.configured.command);
620 } else {
621 BUG("unknown hook kind");
622 }
623
624 if (!cp->args.nr)
625 BUG("hook must have at least one command or exec path");
626
627 strvec_pushv(&cp->args, hook_cb->options->args.v);
628
629 /*
630 * Provide per-hook internal state via task_cb for easy access, so

Callers

nothing calls this directly

Calls 3

strvec_pushvFunction · 0.85
xopenFunction · 0.85
strvec_pushFunction · 0.85

Tested by

no test coverage detected