builtin/maintenance: fix leaking config string
[git/gitster.git] / hook.h
blob11863fa7347e6f8f819de95aec99d132aea7e62f
1 #ifndef HOOK_H
2 #define HOOK_H
3 #include "strvec.h"
5 struct repository;
7 struct run_hooks_opt
9 /* Environment vars to be set for each hook */
10 struct strvec env;
12 /* Args to be passed to each hook */
13 struct strvec args;
15 /* Emit an error if the hook is missing */
16 unsigned int error_if_missing:1;
18 /**
19 * An optional initial working directory for the hook,
20 * translates to "struct child_process"'s "dir" member.
22 const char *dir;
24 /**
25 * A pointer which if provided will be set to 1 or 0 depending
26 * on if a hook was started, regardless of whether or not that
27 * was successful. I.e. if the underlying start_command() was
28 * successful this will be set to 1.
30 * Used for avoiding TOCTOU races in code that would otherwise
31 * call hook_exist() after a "maybe hook run" to see if a hook
32 * was invoked.
34 int *invoked_hook;
36 /**
37 * Path to file which should be piped to stdin for each hook.
39 const char *path_to_stdin;
42 #define RUN_HOOKS_OPT_INIT { \
43 .env = STRVEC_INIT, \
44 .args = STRVEC_INIT, \
47 struct hook_cb_data {
48 /* rc reflects the cumulative failure state */
49 int rc;
50 const char *hook_name;
51 const char *hook_path;
52 struct run_hooks_opt *options;
56 * Returns the path to the hook file, or NULL if the hook is missing
57 * or disabled. Note that this points to static storage that will be
58 * overwritten by further calls to find_hook and run_hook_*.
60 const char *find_hook(struct repository *r, const char *name);
62 /**
63 * A boolean version of find_hook()
65 int hook_exists(struct repository *r, const char *hookname);
67 /**
68 * Takes a `hook_name`, resolves it to a path with find_hook(), and
69 * runs the hook for you with the options specified in "struct
70 * run_hooks opt". Will free memory associated with the "struct run_hooks_opt".
72 * Returns the status code of the run hook, or a negative value on
73 * error().
75 int run_hooks_opt(struct repository *r, const char *hook_name,
76 struct run_hooks_opt *options);
78 /**
79 * A wrapper for run_hooks_opt() which provides a dummy "struct
80 * run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT".
82 int run_hooks(struct repository *r, const char *hook_name);
84 /**
85 * Like run_hooks(), a wrapper for run_hooks_opt().
87 * In addition to the wrapping behavior provided by run_hooks(), this
88 * wrapper takes a list of strings terminated by a NULL
89 * argument. These things will be used as positional arguments to the
90 * hook. This function behaves like the old run_hook_le() API.
92 LAST_ARG_MUST_BE_NULL
93 int run_hooks_l(struct repository *r, const char *hook_name, ...);
94 #endif