Skip to content

Commit a37b837

Browse files
bkkaracaygitster
authored andcommitted
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>
1 parent 92754c6 commit a37b837

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

environment.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -647,22 +647,6 @@ static int git_default_push_config(const char *var, const char *value)
647647
return 0;
648648
}
649649

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-
666650
static int git_default_attr_config(const char *var, const char *value)
667651
{
668652
if (!strcmp(var, "attr.tree")) {
@@ -697,9 +681,6 @@ int git_default_config(const char *var, const char *value,
697681
if (starts_with(var, "push."))
698682
return git_default_push_config(var, value);
699683

700-
if (starts_with(var, "mailmap."))
701-
return git_default_mailmap_config(var, value);
702-
703684
if (starts_with(var, "attr."))
704685
return git_default_attr_config(var, value);
705686

mailmap.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#include "object-name.h"
88
#include "odb.h"
99
#include "setup.h"
10-
11-
char *git_mailmap_file;
12-
char *git_mailmap_blob;
10+
#include "config.h"
1311

1412
struct mailmap_info {
1513
char *name;
@@ -213,20 +211,29 @@ int read_mailmap_blob(struct repository *repo, struct string_list *map,
213211
int read_mailmap(struct repository *repo, struct string_list *map)
214212
{
215213
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);
216218

217219
map->strdup_strings = 1;
218220
map->cmp = namemap_cmp;
219221

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");
222224

223225
if (!startup_info->have_repository || !is_bare_repository())
224226
err |= read_mailmap_file(map, ".mailmap",
225227
startup_info->have_repository ?
226228
MAILMAP_NOFOLLOW : 0);
227229
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+
230237
return err;
231238
}
232239

mailmap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
struct string_list;
55

6-
extern char *git_mailmap_file;
7-
extern char *git_mailmap_blob;
8-
96
/* Flags for read_mailmap_file() */
107
#define MAILMAP_NOFOLLOW (1<<0)
118

0 commit comments

Comments
 (0)