]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hook: parse the hook.jobs config
authorAdrian Ratiu <adrian.ratiu@collabora.com>
Fri, 10 Apr 2026 09:05:58 +0000 (12:05 +0300)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Apr 2026 14:58:53 +0000 (07:58 -0700)
The hook.jobs config is a global way to set hook parallelization for
all hooks, in the sense that it is not per-event nor per-hook.

Finer-grained configs will be added in later commits which can override
it, for e.g. via a per-event type job options. Next commits will also
add to this item's documentation.

Parse hook.jobs config key in hook_config_lookup_all() and store its
value in hook_all_config_cb.jobs, then transfer it into r->jobs after
the config pass completes.

This is mostly plumbing and the cached value is not yet used.

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/hook.adoc
hook.c
repository.h

index 9e78f264396ca5150faa617a2083b3e5807143ed..b7847f9338c65f69a5ea399ca4d1b47dd9dd810d 100644 (file)
@@ -22,3 +22,7 @@ hook.<friendly-name>.enabled::
        configuration. This is particularly useful when a hook is defined
        in a system or global config file and needs to be disabled for a
        specific repository. See linkgit:git-hook[1].
+
+hook.jobs::
+       Specifies how many hooks can be run simultaneously during parallelized
+       hook execution. If unspecified, defaults to 1 (serial execution).
diff --git a/hook.c b/hook.c
index cc23276d27f035b65914df53b8f367aabc29a0be..b8cce00e578d3c4ec4d03986d082265f24de2e45 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -123,11 +123,13 @@ struct hook_config_cache_entry {
  * commands: friendly-name to command map.
  * event_hooks: event-name to list of friendly-names map.
  * disabled_hooks: set of friendly-names with hook.<friendly-name>.enabled = false.
+ * jobs: value of the global hook.jobs key. Defaults to 0 if unset (stored in r->hook_jobs).
  */
 struct hook_all_config_cb {
        struct strmap commands;
        struct strmap event_hooks;
        struct string_list disabled_hooks;
+       unsigned int jobs;
 };
 
 /* repo_config() callback that collects all hook.* configuration in one pass. */
@@ -143,6 +145,20 @@ static int hook_config_lookup_all(const char *key, const char *value,
        if (parse_config_key(key, "hook", &name, &name_len, &subkey))
                return 0;
 
+       /* Handle plain hook.<key> entries that have no hook name component. */
+       if (!name) {
+               if (!strcmp(subkey, "jobs") && value) {
+                       unsigned int v;
+                       if (!git_parse_uint(value, &v))
+                               warning(_("hook.jobs must be a positive integer, ignoring: '%s'"), value);
+                       else if (!v)
+                               warning(_("hook.jobs must be positive, ignoring: 0"));
+                       else
+                               data->jobs = v;
+               }
+               return 0;
+       }
+
        if (!value)
                return config_error_nonbool(key);
 
@@ -240,7 +256,7 @@ void hook_cache_clear(struct strmap *cache)
 /* Populate `cache` with the complete hook configuration */
 static void build_hook_config_map(struct repository *r, struct strmap *cache)
 {
-       struct hook_all_config_cb cb_data;
+       struct hook_all_config_cb cb_data = { 0 };
        struct hashmap_iter iter;
        struct strmap_entry *e;
 
@@ -248,7 +264,7 @@ static void build_hook_config_map(struct repository *r, struct strmap *cache)
        strmap_init(&cb_data.event_hooks);
        string_list_init_dup(&cb_data.disabled_hooks);
 
-       /* Parse all configs in one run. */
+       /* Parse all configs in one run, capturing hook.* including hook.jobs. */
        repo_config(r, hook_config_lookup_all, &cb_data);
 
        /* Construct the cache from parsed configs. */
@@ -292,6 +308,9 @@ static void build_hook_config_map(struct repository *r, struct strmap *cache)
                strmap_put(cache, e->key, hooks);
        }
 
+       if (r)
+               r->hook_jobs = cb_data.jobs;
+
        strmap_clear(&cb_data.commands, 1);
        string_list_clear(&cb_data.disabled_hooks, 0);
        strmap_for_each_entry(&cb_data.event_hooks, &iter, e) {
index 078059a6e02b109f7925be6f1a7acf84a1a63b59..58e46853d089bf60d9456360c3127d94fd166a6f 100644 (file)
@@ -172,6 +172,9 @@ struct repository {
         */
        struct strmap *hook_config_cache;
 
+       /* Cached value of hook.jobs config (0 if unset, defaults to serial). */
+       unsigned int hook_jobs;
+
        /* Configurations related to promisor remotes. */
        char *repository_format_partial_clone;
        struct promisor_remote_config *promisor_remote_config;