aboutsummaryrefslogtreecommitdiff
path: root/hook.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-03-09 14:36:55 -0700
committerJunio C Hamano <gitster@pobox.com>2026-03-09 14:36:55 -0700
commit5c56c725f104ce278fe1ec0ea0fce0ccfb245aea (patch)
tree148a090bbe73c7bfb8b823bcc642e01c40929250 /hook.h
parent4aa72ea1f64e8ddcd1865c76b24591c0916c0b5d (diff)
parent005f3fbe07a20dd5f7dea57f6f46cd797387e56a (diff)
downloadgit-5c56c725f104ce278fe1ec0ea0fce0ccfb245aea.tar.xz
Merge branch 'ar/run-command-hook-take-2'
Use the hook API to replace ad-hoc invocation of hook scripts via the run_command() API. * ar/run-command-hook-take-2: builtin/receive-pack: avoid spinning no-op sideband async threads receive-pack: convert receive hooks to hook API receive-pack: convert update hooks to new API run-command: poll child input in addition to output hook: add jobs option reference-transaction: use hook API instead of run-command transport: convert pre-push to hook API hook: allow separate std[out|err] streams hook: convert 'post-rewrite' hook in sequencer.c to hook API hook: provide stdin via callback run-command: add stdin callback for parallelization run-command: add helper for pp child states t1800: add hook output stream tests
Diffstat (limited to 'hook.h')
-rw-r--r--hook.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/hook.h b/hook.h
index 11863fa734..20eb56fd63 100644
--- a/hook.h
+++ b/hook.h
@@ -1,6 +1,7 @@
#ifndef HOOK_H
#define HOOK_H
#include "strvec.h"
+#include "run-command.h"
struct repository;
@@ -16,6 +17,14 @@ struct run_hooks_opt
unsigned int error_if_missing:1;
/**
+ * Number of processes to parallelize across.
+ *
+ * If > 1, output will be buffered and de-interleaved (ungroup=0).
+ * If == 1, output will be real-time (ungroup=1).
+ */
+ unsigned int jobs;
+
+ /**
* An optional initial working directory for the hook,
* translates to "struct child_process"'s "dir" member.
*/
@@ -34,14 +43,62 @@ struct run_hooks_opt
int *invoked_hook;
/**
+ * Send the hook's stdout to stderr.
+ *
+ * This is the default behavior for all hooks except pre-push,
+ * which has separate stdout and stderr streams for backwards
+ * compatibility reasons.
+ */
+ unsigned int stdout_to_stderr:1;
+
+ /**
* Path to file which should be piped to stdin for each hook.
*/
const char *path_to_stdin;
+
+ /**
+ * Callback used to incrementally feed a child hook stdin pipe.
+ *
+ * Useful especially if a hook consumes large quantities of data
+ * (e.g. a list of all refs in a client push), so feeding it via
+ * in-memory strings or slurping to/from files is inefficient.
+ * While the callback allows piecemeal writing, it can also be
+ * used for smaller inputs, where it gets called only once.
+ *
+ * Add hook callback initalization context to `feed_pipe_ctx`.
+ * Add hook callback internal state to `feed_pipe_cb_data`.
+ *
+ */
+ feed_pipe_fn feed_pipe;
+
+ /**
+ * Opaque data pointer used to pass context to `feed_pipe_fn`.
+ *
+ * It can be accessed via the second callback arg 'pp_cb':
+ * ((struct hook_cb_data *) pp_cb)->hook_cb->options->feed_pipe_ctx;
+ *
+ * The caller is responsible for managing the memory for this data.
+ * Only useful when using `run_hooks_opt.feed_pipe`, otherwise ignore it.
+ */
+ void *feed_pipe_ctx;
+
+ /**
+ * Opaque data pointer used to keep internal state across callback calls.
+ *
+ * It can be accessed directly via the third callback arg 'pp_task_cb':
+ * struct ... *state = pp_task_cb;
+ *
+ * The caller is responsible for managing the memory for this data.
+ * Only useful when using `run_hooks_opt.feed_pipe`, otherwise ignore it.
+ */
+ void *feed_pipe_cb_data;
};
#define RUN_HOOKS_OPT_INIT { \
.env = STRVEC_INIT, \
.args = STRVEC_INIT, \
+ .stdout_to_stderr = 1, \
+ .jobs = 1, \
}
struct hook_cb_data {