aboutsummaryrefslogtreecommitdiff
path: root/hook.c
diff options
context:
space:
mode:
authorAdrian Ratiu <adrian.ratiu@collabora.com>2026-02-19 00:23:50 +0200
committerJunio C Hamano <gitster@pobox.com>2026-02-19 13:23:41 -0800
commitd084fa2a915784d65257fbaff43f00b3ea5c8a44 (patch)
treea21cc77ed137445de0ff142b3c609a1585f4c643 /hook.c
parent1ecce722cdb9c42dd4c69e45e02cb850cd558ef2 (diff)
downloadgit-d084fa2a915784d65257fbaff43f00b3ea5c8a44.tar.xz
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 <ps@pks.im> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hook.c')
-rw-r--r--hook.c29
1 files changed, 19 insertions, 10 deletions
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;
- if (!hooks) {
- hooks = xcalloc(1, sizeof(*hooks));
- string_list_init_dup(hooks);
- strmap_put(&data->event_hooks, value, hooks);
- }
+ 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);
+ }
- /* 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,