5 #include "run-command.h"
8 /* The path to the hook */
12 * Use this to keep state for your feed_pipe_fn if you are using
13 * run_hooks_opt.feed_pipe. Otherwise, do not touch it.
15 void *feed_pipe_cb_data;
20 /* Environment vars to be set for each hook */
23 /* Args to be passed to each hook */
26 /* Number of threads to parallelize across */
29 /* Resolve and run the "absolute_path(hook)" instead of
30 * "hook". Used for "git worktree" hooks
34 /* Path to initial working directory for subprocess */
37 /* Path to file which should be piped to stdin for each hook */
38 const char *path_to_stdin;
41 * Callback and state pointer to ask for more content to pipe to stdin.
42 * Will be called repeatedly, for each hook. See
43 * hook.c:pipe_from_stdin() for an example. Keep per-hook state in
44 * hook.feed_pipe_cb_data (per process). Keep initialization context in
45 * feed_pipe_ctx (shared by all processes).
47 * See 'pipe_from_string_list()' for info about how to specify a
48 * string_list as the stdin input instead of writing your own handler.
50 feed_pipe_fn feed_pipe;
54 * Populate this to capture output and prevent it from being printed to
55 * stderr. This will be passed directly through to
56 * run_command:run_parallel_processes(). See t/helper/test-run-command.c
59 consume_sideband_fn consume_sideband;
62 * A pointer which if provided will be set to 1 or 0 depending
63 * on if a hook was invoked (i.e. existed), regardless of
64 * whether or not that was successful. Used for avoiding
65 * TOCTOU races in code that would otherwise call hook_exist()
66 * after a "maybe hook run" to see if a hook was invoked.
71 #define RUN_HOOKS_OPT_INIT { \
74 .args = STRVEC_INIT, \
78 * To specify a 'struct string_list', set 'run_hooks_opt.feed_pipe_ctx' to the
79 * string_list and set 'run_hooks_opt.feed_pipe' to 'pipe_from_string_list()'.
80 * This will pipe each string in the list to stdin, separated by newlines. (Do
81 * not inject your own newlines.)
83 int pipe_from_string_list(struct strbuf *pipe, void *pp_cb, void *pp_task_cb);
86 * Callback provided to feed_pipe_fn and consume_sideband_fn.
90 const char *hook_name;
92 struct run_hooks_opt *options;
97 * Returns the path to the hook file, or NULL if the hook is missing
98 * or disabled. Note that this points to static storage that will be
99 * overwritten by further calls to find_hook and run_hook_*.
101 const char *find_hook(const char *name);
104 * A boolean version of find_hook()
106 int hook_exists(const char *hookname);
108 void run_hooks_opt_clear(struct run_hooks_opt *o);
111 * Calls find_hook(hookname) and runs the hooks (if any) with
114 int run_hooks(const char *hook_name, struct run_hooks_opt *options);
117 * Takes an already resolved hook and runs it. Internally the simpler
118 * run_hooks() will call this.
120 int run_found_hooks(const char *hookname, const char *hook_path,
121 struct run_hooks_opt *options);