| 781 | } |
| 782 | |
| 783 | int run_hooks_opt(struct repository *r, const char *hook_name, |
| 784 | struct run_hooks_opt *options) |
| 785 | { |
| 786 | struct string_list *hook_list = list_hooks(r, hook_name, options); |
| 787 | struct hook_cb_data cb_data = { |
| 788 | .rc = 0, |
| 789 | .hook_name = hook_name, |
| 790 | .hook_command_list = hook_list, |
| 791 | .options = options, |
| 792 | }; |
| 793 | int ret = 0; |
| 794 | unsigned int jobs = get_hook_jobs(r, options, hook_name, hook_list); |
| 795 | const struct run_process_parallel_opts opts = { |
| 796 | .tr2_category = "hook", |
| 797 | .tr2_label = hook_name, |
| 798 | |
| 799 | .processes = jobs, |
| 800 | .ungroup = jobs == 1, |
| 801 | |
| 802 | .get_next_task = pick_next_hook, |
| 803 | .start_failure = notify_start_failure, |
| 804 | .feed_pipe = options->feed_pipe, |
| 805 | .task_finished = notify_hook_finished, |
| 806 | |
| 807 | .data = &cb_data, |
| 808 | }; |
| 809 | |
| 810 | if (!options) |
| 811 | BUG("a struct run_hooks_opt must be provided to run_hooks"); |
| 812 | |
| 813 | if (options->path_to_stdin && options->feed_pipe) |
| 814 | BUG("options path_to_stdin and feed_pipe are mutually exclusive"); |
| 815 | |
| 816 | /* |
| 817 | * Ensure cb_data copy and free functions are either provided together, |
| 818 | * or neither one is provided. |
| 819 | */ |
| 820 | if (!options->feed_pipe_cb_data_alloc != !options->feed_pipe_cb_data_free) |
| 821 | BUG("feed_pipe_cb_data_alloc and feed_pipe_cb_data_free must be set together"); |
| 822 | |
| 823 | if (options->invoked_hook) |
| 824 | *options->invoked_hook = 0; |
| 825 | |
| 826 | if (!cb_data.hook_command_list->nr) { |
| 827 | if (options->error_if_missing) |
| 828 | ret = error("cannot find a hook named %s", hook_name); |
| 829 | goto cleanup; |
| 830 | } |
| 831 | |
| 832 | run_processes_parallel(&opts); |
| 833 | ret = cb_data.rc; |
| 834 | cleanup: |
| 835 | string_list_clear_func(cb_data.hook_command_list, hook_free); |
| 836 | free(cb_data.hook_command_list); |
| 837 | run_hooks_opt_clear(options); |
| 838 | return ret; |
| 839 | } |
| 840 |
no test coverage detected