run-command: add stdin callback for parallelization
[git] / hook.h
1 #ifndef HOOK_H
2 #define HOOK_H
3 #include "strbuf.h"
4 #include "strvec.h"
5 #include "run-command.h"
6
7 struct hook {
8         /* The path to the hook */
9         const char *hook_path;
10 };
11
12 struct run_hooks_opt
13 {
14         /* Environment vars to be set for each hook */
15         struct strvec env;
16
17         /* Args to be passed to each hook */
18         struct strvec args;
19
20         /* Number of threads to parallelize across */
21         int jobs;
22
23         /* Resolve and run the "absolute_path(hook)" instead of
24          * "hook". Used for "git worktree" hooks
25          */
26         int absolute_path;
27
28         /* Path to initial working directory for subprocess */
29         const char *dir;
30
31         /* Path to file which should be piped to stdin for each hook */
32         const char *path_to_stdin;
33 };
34
35 #define RUN_HOOKS_OPT_INIT { \
36         .jobs = 1, \
37         .env = STRVEC_INIT, \
38         .args = STRVEC_INIT, \
39 }
40
41 /*
42  * Callback provided to feed_pipe_fn and consume_sideband_fn.
43  */
44 struct hook_cb_data {
45         int rc;
46         const char *hook_name;
47         struct hook *run_me;
48         struct run_hooks_opt *options;
49 };
50
51 /*
52  * Returns the path to the hook file, or NULL if the hook is missing
53  * or disabled. Note that this points to static storage that will be
54  * overwritten by further calls to find_hook and run_hook_*.
55  */
56 const char *find_hook(const char *name);
57
58 /*
59  * A boolean version of find_hook()
60  */
61 int hook_exists(const char *hookname);
62
63 void run_hooks_opt_clear(struct run_hooks_opt *o);
64
65 /*
66  * Calls find_hook(hookname) and runs the hooks (if any) with
67  * run_found_hooks().
68  */
69 int run_hooks(const char *hook_name, struct run_hooks_opt *options);
70
71 /*
72  * Takes an already resolved hook and runs it. Internally the simpler
73  * run_hooks() will call this.
74  */
75 int run_found_hooks(const char *hookname, const char *hook_path,
76                     struct run_hooks_opt *options);
77 #endif