mailmap: drop global config variables

The 'mailmap.file' and 'mailmap.blob' configurations are currently parsed and stored in the global variables 'git_mailmap_file' and 'git_mailmap_blob'. Since these values are typically only needed once when initializing a mailmap, there is no need to keep them as global state throughout the lifetime of the Git process. To reduce global state, remove these global variables and instead use 'repo_config_get_*' functions to read the configuration on demand. Signed-off-by: Burak Kaan Karaçay <bkkaracay@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Burak Kaan Karaçay committed Feb 20, 2026 at 09:04 UTC 6aea51bc3bf3c5318b97b5bddc405c29f1b23e8e
3 files changed +14 -29
environment.c
-19
@@ -647,22 +647,6 @@ static int git_default_push_config(const char *var, const char *value)
647 return 0;
648 }
649
650 -static int git_default_mailmap_config(const char *var, const char *value)
651 -{
652 - if (!strcmp(var, "mailmap.file")) {
653 - FREE_AND_NULL(git_mailmap_file);
654 - return git_config_pathname(&git_mailmap_file, var, value);
655 - }
656 -
657 - if (!strcmp(var, "mailmap.blob")) {
658 - FREE_AND_NULL(git_mailmap_blob);
659 - return git_config_string(&git_mailmap_blob, var, value);
660 - }
661 -
662 - /* Add other config variables here and to Documentation/config.adoc. */
663 - return 0;
664 -}
665 -
650 static int git_default_attr_config(const char *var, const char *value)
651 {
652 if (!strcmp(var, "attr.tree")) {
@@ -697,9 +681,6 @@ int git_default_config(const char *var, const char *value,
681 if (starts_with(var, "push."))
682 return git_default_push_config(var, value);
683
700 - if (starts_with(var, "mailmap."))
701 - return git_default_mailmap_config(var, value);
702 -
684 if (starts_with(var, "attr."))
685 return git_default_attr_config(var, value);
686
mailmap.c
+14 -7
@@ -7,9 +7,7 @@
7 #include "object-name.h"
8 #include "odb.h"
9 #include "setup.h"
10 -
11 -char *git_mailmap_file;
12 -char *git_mailmap_blob;
10 +#include "config.h"
11
12 struct mailmap_info {
13 char *name;
@@ -213,20 +211,29 @@ int read_mailmap_blob(struct repository *repo, struct string_list *map,
211 int read_mailmap(struct repository *repo, struct string_list *map)
212 {
213 int err = 0;
214 + char *mailmap_file = NULL, *mailmap_blob = NULL;
215 +
216 + repo_config_get_pathname(repo, "mailmap.file", &mailmap_file);
217 + repo_config_get_string(repo, "mailmap.blob", &mailmap_blob);
218
219 map->strdup_strings = 1;
220 map->cmp = namemap_cmp;
221
220 - if (!git_mailmap_blob && is_bare_repository())
221 - git_mailmap_blob = xstrdup("HEAD:.mailmap");
222 + if (!mailmap_blob && is_bare_repository())
223 + mailmap_blob = xstrdup("HEAD:.mailmap");
224
225 if (!startup_info->have_repository || !is_bare_repository())
226 err |= read_mailmap_file(map, ".mailmap",
227 startup_info->have_repository ?
228 MAILMAP_NOFOLLOW : 0);
229 if (startup_info->have_repository)
228 - err |= read_mailmap_blob(repo, map, git_mailmap_blob);
229 - err |= read_mailmap_file(map, git_mailmap_file, 0);
230 + err |= read_mailmap_blob(repo, map, mailmap_blob);
231 +
232 + err |= read_mailmap_file(map, mailmap_file, 0);
233 +
234 + free(mailmap_file);
235 + free(mailmap_blob);
236 +
237 return err;
238 }
239
mailmap.h
-3
@@ -4,9 +4,6 @@
4 struct repository;
5 struct string_list;
6
7 -extern char *git_mailmap_file;
8 -extern char *git_mailmap_blob;
9 -
7 /* Flags for read_mailmap_file() */
8 #define MAILMAP_NOFOLLOW (1<<0)
9