Skip to content

Commit b9a4c9a

Browse files
10ne1gitster
authored andcommitted
hook: parse the hook.jobs config
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>
1 parent 1c9e5b3 commit b9a4c9a

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

Documentation/config/hook.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ hook.<friendly-name>.enabled::
2222
configuration. This is particularly useful when a hook is defined
2323
in a system or global config file and needs to be disabled for a
2424
specific repository. See linkgit:git-hook[1].
25+
26+
hook.jobs::
27+
Specifies how many hooks can be run simultaneously during parallelized
28+
hook execution. If unspecified, defaults to 1 (serial execution).

hook.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ struct hook_config_cache_entry {
123123
* commands: friendly-name to command map.
124124
* event_hooks: event-name to list of friendly-names map.
125125
* disabled_hooks: set of friendly-names with hook.<friendly-name>.enabled = false.
126+
* jobs: value of the global hook.jobs key. Defaults to 0 if unset (stored in r->hook_jobs).
126127
*/
127128
struct hook_all_config_cb {
128129
struct strmap commands;
129130
struct strmap event_hooks;
130131
struct string_list disabled_hooks;
132+
unsigned int jobs;
131133
};
132134

133135
/* 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,
143145
if (parse_config_key(key, "hook", &name, &name_len, &subkey))
144146
return 0;
145147

148+
/* Handle plain hook.<key> entries that have no hook name component. */
149+
if (!name) {
150+
if (!strcmp(subkey, "jobs") && value) {
151+
unsigned int v;
152+
if (!git_parse_uint(value, &v))
153+
warning(_("hook.jobs must be a positive integer, ignoring: '%s'"), value);
154+
else if (!v)
155+
warning(_("hook.jobs must be positive, ignoring: 0"));
156+
else
157+
data->jobs = v;
158+
}
159+
return 0;
160+
}
161+
146162
if (!value)
147163
return config_error_nonbool(key);
148164

@@ -240,15 +256,15 @@ void hook_cache_clear(struct strmap *cache)
240256
/* Populate `cache` with the complete hook configuration */
241257
static void build_hook_config_map(struct repository *r, struct strmap *cache)
242258
{
243-
struct hook_all_config_cb cb_data;
259+
struct hook_all_config_cb cb_data = { 0 };
244260
struct hashmap_iter iter;
245261
struct strmap_entry *e;
246262

247263
strmap_init(&cb_data.commands);
248264
strmap_init(&cb_data.event_hooks);
249265
string_list_init_dup(&cb_data.disabled_hooks);
250266

251-
/* Parse all configs in one run. */
267+
/* Parse all configs in one run, capturing hook.* including hook.jobs. */
252268
repo_config(r, hook_config_lookup_all, &cb_data);
253269

254270
/* Construct the cache from parsed configs. */
@@ -292,6 +308,9 @@ static void build_hook_config_map(struct repository *r, struct strmap *cache)
292308
strmap_put(cache, e->key, hooks);
293309
}
294310

311+
if (r)
312+
r->hook_jobs = cb_data.jobs;
313+
295314
strmap_clear(&cb_data.commands, 1);
296315
string_list_clear(&cb_data.disabled_hooks, 0);
297316
strmap_for_each_entry(&cb_data.event_hooks, &iter, e) {

repository.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ struct repository {
172172
*/
173173
struct strmap *hook_config_cache;
174174

175+
/* Cached value of hook.jobs config (0 if unset, defaults to serial). */
176+
unsigned int hook_jobs;
177+
175178
/* Configurations related to promisor remotes. */
176179
char *repository_format_partial_clone;
177180
struct promisor_remote_config *promisor_remote_config;

0 commit comments

Comments
 (0)