Skip to content

Commit 1e75fbf

Browse files
committed
Merge branch 'bk/mailmap-wo-the-repository' into jch
* bk/mailmap-wo-the-repository: mailmap: drop global config variables mailmap: stop using the_repository
2 parents 2f119cd + a37b837 commit 1e75fbf

File tree

11 files changed

+31
-44
lines changed

11 files changed

+31
-44
lines changed

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ int cmd_blame(int argc,
12521252
sb.xdl_opts = xdl_opts;
12531253
sb.no_whole_file_rename = no_whole_file_rename;
12541254

1255-
read_mailmap(&mailmap);
1255+
read_mailmap(the_repository, &mailmap);
12561256

12571257
sb.found_guilty_entry = &found_guilty_entry;
12581258
sb.found_guilty_entry_data = π

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ int cmd_cat_file(int argc,
11271127
opt_epts = (opt == 'e' || opt == 'p' || opt == 't' || opt == 's');
11281128

11291129
if (use_mailmap)
1130-
read_mailmap(&mailmap);
1130+
read_mailmap(the_repository, &mailmap);
11311131

11321132
switch (batch.objects_filter.choice) {
11331133
case LOFC_DISABLED:

builtin/check-mailmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ int cmd_check_mailmap(int argc,
6363
if (argc == 0 && !use_stdin)
6464
die(_("no contacts specified"));
6565

66-
read_mailmap(&mailmap);
66+
read_mailmap(the_repository, &mailmap);
6767
if (mailmap_blob)
68-
read_mailmap_blob(&mailmap, mailmap_blob);
68+
read_mailmap_blob(the_repository, &mailmap, mailmap_blob);
6969
if (mailmap_file)
7070
read_mailmap_file(&mailmap, mailmap_file, 0);
7171

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ static const char *find_author_by_nickname(const char *name)
11551155
setup_revisions(ac, av, &revs, NULL);
11561156
revs.mailmap = xmalloc(sizeof(struct string_list));
11571157
string_list_init_nodup(revs.mailmap);
1158-
read_mailmap(revs.mailmap);
1158+
read_mailmap(the_repository, revs.mailmap);
11591159

11601160
if (prepare_revision_walk(&revs))
11611161
die(_("revision walk setup failed"));

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
336336
if (mailmap) {
337337
rev->mailmap = xmalloc(sizeof(struct string_list));
338338
string_list_init_nodup(rev->mailmap);
339-
read_mailmap(rev->mailmap);
339+
read_mailmap(the_repository, rev->mailmap);
340340
}
341341

342342
if (rev->pretty_given && rev->commit_format == CMIT_FMT_RAW) {

builtin/shortlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ void shortlog_init(struct shortlog *log)
357357
{
358358
memset(log, 0, sizeof(*log));
359359

360-
read_mailmap(&log->mailmap);
360+
read_mailmap(the_repository, &log->mailmap);
361361

362362
log->list.strdup_strings = 1;
363363
log->wrap = DEFAULT_WRAPLEN;

environment.c

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

651-
static int git_default_mailmap_config(const char *var, const char *value)
652-
{
653-
if (!strcmp(var, "mailmap.file")) {
654-
FREE_AND_NULL(git_mailmap_file);
655-
return git_config_pathname(&git_mailmap_file, var, value);
656-
}
657-
658-
if (!strcmp(var, "mailmap.blob")) {
659-
FREE_AND_NULL(git_mailmap_blob);
660-
return git_config_string(&git_mailmap_blob, var, value);
661-
}
662-
663-
/* Add other config variables here and to Documentation/config.adoc. */
664-
return 0;
665-
}
666-
667651
static int git_default_attr_config(const char *var, const char *value)
668652
{
669653
if (!strcmp(var, "attr.tree")) {
@@ -698,9 +682,6 @@ int git_default_config(const char *var, const char *value,
698682
if (starts_with(var, "push."))
699683
return git_default_push_config(var, value);
700684

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

mailmap.c

Lines changed: 19 additions & 11 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;
@@ -183,7 +181,8 @@ static void read_mailmap_string(struct string_list *map, char *buf)
183181
}
184182
}
185183

186-
int read_mailmap_blob(struct string_list *map, const char *name)
184+
int read_mailmap_blob(struct repository *repo, struct string_list *map,
185+
const char *name)
187186
{
188187
struct object_id oid;
189188
char *buf;
@@ -192,10 +191,10 @@ int read_mailmap_blob(struct string_list *map, const char *name)
192191

193192
if (!name)
194193
return 0;
195-
if (repo_get_oid(the_repository, name, &oid) < 0)
194+
if (repo_get_oid(repo, name, &oid) < 0)
196195
return 0;
197196

198-
buf = odb_read_object(the_repository->objects, &oid, &type, &size);
197+
buf = odb_read_object(repo->objects, &oid, &type, &size);
199198
if (!buf)
200199
return error("unable to read mailmap object at %s", name);
201200
if (type != OBJ_BLOB) {
@@ -209,23 +208,32 @@ int read_mailmap_blob(struct string_list *map, const char *name)
209208
return 0;
210209
}
211210

212-
int read_mailmap(struct string_list *map)
211+
int read_mailmap(struct repository *repo, struct string_list *map)
213212
{
214213
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);
215218

216219
map->strdup_strings = 1;
217220
map->cmp = namemap_cmp;
218221

219-
if (!git_mailmap_blob && is_bare_repository())
220-
git_mailmap_blob = xstrdup("HEAD:.mailmap");
222+
if (!mailmap_blob && is_bare_repository())
223+
mailmap_blob = xstrdup("HEAD:.mailmap");
221224

222225
if (!startup_info->have_repository || !is_bare_repository())
223226
err |= read_mailmap_file(map, ".mailmap",
224227
startup_info->have_repository ?
225228
MAILMAP_NOFOLLOW : 0);
226229
if (startup_info->have_repository)
227-
err |= read_mailmap_blob(map, git_mailmap_blob);
228-
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+
229237
return err;
230238
}
231239

mailmap.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
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

129
int read_mailmap_file(struct string_list *map, const char *filename,
1310
unsigned flags);
14-
int read_mailmap_blob(struct string_list *map, const char *name);
11+
int read_mailmap_blob(struct repository *repo, struct string_list *map,
12+
const char *name);
1513

16-
int read_mailmap(struct string_list *map);
14+
int read_mailmap(struct repository *repo, struct string_list *map);
1715
void clear_mailmap(struct string_list *map);
1816

1917
int map_user(struct string_list *map,

pretty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ static int mailmap_name(const char **email, size_t *email_len,
781781
static struct string_list *mail_map;
782782
if (!mail_map) {
783783
CALLOC_ARRAY(mail_map, 1);
784-
read_mailmap(mail_map);
784+
read_mailmap(the_repository, mail_map);
785785
}
786786
return mail_map->nr && map_user(mail_map, email, email_len, name, name_len);
787787
}

0 commit comments

Comments
 (0)