From d084fa2a915784d65257fbaff43f00b3ea5c8a44 Mon Sep 17 00:00:00 2001 From: Adrian Ratiu Date: Thu, 19 Feb 2026 00:23:50 +0200 Subject: hook: allow event = "" to overwrite previous values Add the ability for empty events to clear previously set multivalue variables, so the newly added "hook.*.event" behave like the other multivalued keys. Suggested-by: Patrick Steinhardt Signed-off-by: Adrian Ratiu Signed-off-by: Junio C Hamano --- hook.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'hook.c') diff --git a/hook.c b/hook.c index 35c24bf33d..fee0a7ab4f 100644 --- a/hook.c +++ b/hook.c @@ -147,18 +147,27 @@ static int hook_config_lookup_all(const char *key, const char *value, hook_name = xmemdupz(name, name_len); if (!strcmp(subkey, "event")) { - struct string_list *hooks = - strmap_get(&data->event_hooks, value); + if (!*value) { + /* Empty values reset previous events for this hook. */ + struct hashmap_iter iter; + struct strmap_entry *e; + + strmap_for_each_entry(&data->event_hooks, &iter, e) + unsorted_string_list_remove(e->value, hook_name); + } else { + struct string_list *hooks = + strmap_get(&data->event_hooks, value); + + if (!hooks) { + hooks = xcalloc(1, sizeof(*hooks)); + string_list_init_dup(hooks); + strmap_put(&data->event_hooks, value, hooks); + } - if (!hooks) { - hooks = xcalloc(1, sizeof(*hooks)); - string_list_init_dup(hooks); - strmap_put(&data->event_hooks, value, hooks); + /* Re-insert if necessary to preserve last-seen order. */ + unsorted_string_list_remove(hooks, hook_name); + string_list_append(hooks, hook_name); } - - /* Re-insert if necessary to preserve last-seen order. */ - unsorted_string_list_remove(hooks, hook_name); - string_list_append(hooks, hook_name); } else if (!strcmp(subkey, "command")) { /* Store command overwriting the old value */ char *old = strmap_put(&data->commands, hook_name, -- cgit v1.3