110
111
/*
112
* Cache entry stored as the .util pointer of string_list items inside the
113
- * hook config cache. For now carries only the command for the hook. Next
114
- * commits will add more data.
113
+ * hook config cache.
114
*/
115
struct hook_config_cache_entry {
116
char *command;
117
+ enum config_scope scope;
118
};
119
120
/*
131
132
/* repo_config() callback that collects all hook.* configuration in one pass. */
133
static int hook_config_lookup_all(const char *key, const char *value,
134
- const struct config_context *ctx UNUSED,
134
+ const struct config_context *ctx,
135
void *cb_data)
136
{
137
struct hook_all_config_cb *data = cb_data;
168
169
/* Re-insert if necessary to preserve last-seen order. */
170
unsorted_string_list_remove(hooks, hook_name, 0);
171
- string_list_append(hooks, hook_name);
171
+
172
+ if (!ctx->kvi)
173
+ BUG("hook config callback called without key-value info");
174
+
175
+ /*
176
+ * Stash the config scope in the util pointer for
177
+ * later retrieval in build_hook_config_map(). This
178
+ * intermediate struct is transient and never leaves
179
+ * that function, so we pack the enum value into the
180
+ * pointer rather than heap-allocating a wrapper.
181
+ */
182
+ string_list_append(hooks, hook_name)->util =
183
+ (void *)(uintptr_t)ctx->kvi->scope;
184
}
185
} else if (!strcmp(subkey, "command")) {
186
/* Store command overwriting the old value */
258
259
for (size_t i = 0; i < hook_names->nr; i++) {
260
const char *hname = hook_names->items[i].string;
261
+ enum config_scope scope =
262
+ (enum config_scope)(uintptr_t)hook_names->items[i].util;
263
struct hook_config_cache_entry *entry;
264
char *command;
265
277
/* util stores a cache entry; owned by the cache. */
278
CALLOC_ARRAY(entry, 1);
279
entry->command = xstrdup(command);
280
+ entry->scope = scope;
281
string_list_append(hooks, hname)->util = entry;
282
}
283
359
hook->kind = HOOK_CONFIGURED;
360
hook->u.configured.friendly_name = xstrdup(friendly_name);
361
hook->u.configured.command = xstrdup(entry->command);
362
+ hook->u.configured.scope = entry->scope;
363
364
string_list_append(list, friendly_name)->util = hook;
365
}