Skip to content

Commit 70be80e

Browse files
committed
stuff mailmap into struct
1 parent 0c8c628 commit 70be80e

15 files changed

Lines changed: 57 additions & 40 deletions

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static int mark_ignored_lines;
7474
static struct date_mode blame_date_mode = { DATE_ISO8601 };
7575
static size_t blame_date_width;
7676

77-
static struct string_list mailmap = STRING_LIST_INIT_NODUP;
77+
static struct mailmap mailmap = MAILMAP_INIT;
7878

7979
#ifndef DEBUG_BLAME
8080
#define DEBUG_BLAME 0

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct batch_options {
5252

5353
static const char *force_path;
5454

55-
static struct string_list mailmap = STRING_LIST_INIT_NODUP;
55+
static struct mailmap mailmap = MAILMAP_INIT;
5656
static int use_mailmap;
5757

5858
static char *replace_idents_using_mailmap(char *, size_t *);

builtin/check-mailmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static const struct option check_mailmap_options[] = {
2424
OPT_END()
2525
};
2626

27-
static void check_mailmap(struct string_list *mailmap, const char *contact)
27+
static void check_mailmap(struct mailmap *mailmap, const char *contact)
2828
{
2929
const char *name, *mail;
3030
size_t namelen, maillen;
@@ -55,7 +55,7 @@ int cmd_check_mailmap(int argc,
5555
struct repository *repo UNUSED)
5656
{
5757
int i;
58-
struct string_list mailmap = STRING_LIST_INIT_NODUP;
58+
struct mailmap mailmap = MAILMAP_INIT;
5959

6060
repo_config(the_repository, git_default_config, NULL);
6161
argc = parse_options(argc, argv, prefix, check_mailmap_options,

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,8 +1153,8 @@ static const char *find_author_by_nickname(const char *name)
11531153
av[++ac] = buf.buf;
11541154
av[++ac] = NULL;
11551155
setup_revisions(ac, av, &revs, NULL);
1156-
revs.mailmap = xmalloc(sizeof(struct string_list));
1157-
string_list_init_nodup(revs.mailmap);
1156+
revs.mailmap = xmalloc(sizeof(*revs.mailmap));
1157+
mailmap_init(revs.mailmap);
11581158
read_mailmap(the_repository, revs.mailmap);
11591159

11601160
if (prepare_revision_walk(&revs))

builtin/log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
336336
}
337337

338338
if (mailmap) {
339-
rev->mailmap = xmalloc(sizeof(struct string_list));
340-
string_list_init_nodup(rev->mailmap);
339+
rev->mailmap = xmalloc(sizeof(*rev->mailmap));
340+
mailmap_init(rev->mailmap);
341341
read_mailmap(the_repository, rev->mailmap);
342342
}
343343

ident.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ int split_ident_line(struct ident_split *split, const char *line, size_t len)
354354
*/
355355
static ssize_t rewrite_ident_line(const char *person, size_t len,
356356
struct strbuf *buf,
357-
struct string_list *mailmap)
357+
struct mailmap *mailmap)
358358
{
359359
size_t namelen, maillen;
360360
const char *name;
@@ -390,7 +390,7 @@ static ssize_t rewrite_ident_line(const char *person, size_t len,
390390
}
391391

392392
void apply_mailmap_to_header(struct strbuf *buf, const char **header,
393-
struct string_list *mailmap)
393+
struct mailmap *mailmap)
394394
{
395395
size_t buf_offset = 0;
396396

ident.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef IDENT_H
22
#define IDENT_H
33

4-
#include "string-list.h"
4+
#include "mailmap.h"
55

66
struct ident_split {
77
const char *name_begin;
@@ -41,7 +41,7 @@ int split_ident_line(struct ident_split *, const char *, size_t);
4141
* Given a commit or tag object buffer and the commit or tag headers, replaces
4242
* the idents in the headers with their canonical versions using the mailmap mechanism.
4343
*/
44-
void apply_mailmap_to_header(struct strbuf *, const char **, struct string_list *);
44+
void apply_mailmap_to_header(struct strbuf *, const char **, struct mailmap *);
4545

4646
/*
4747
* Compare split idents for equality or strict ordering. Note that we

mailmap.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
#include "setup.h"
1010
#include "config.h"
1111

12+
void mailmap_init(struct mailmap *map)
13+
{
14+
struct mailmap blank = MAILMAP_INIT;
15+
memcpy(map, &blank, sizeof(*map));
16+
}
17+
1218
struct mailmap_info {
1319
char *name;
1420
char *email;
@@ -56,7 +62,7 @@ static int namemap_cmp(const char *a, const char *b)
5662
return strcasecmp(a, b);
5763
}
5864

59-
static void add_mapping(struct string_list *map,
65+
static void add_mapping(struct mailmap *map,
6066
char *new_name, char *new_email,
6167
char *old_name, char *old_email)
6268
{
@@ -68,7 +74,7 @@ static void add_mapping(struct string_list *map,
6874
new_email = NULL;
6975
}
7076

71-
item = string_list_insert(map, old_email);
77+
item = string_list_insert(&map->map, old_email);
7278
if (item->util) {
7379
me = (struct mailmap_entry *)item->util;
7480
} else {
@@ -125,7 +131,7 @@ static char *parse_name_and_email(char *buffer, char **name,
125131
return (*right == '\0' ? NULL : right);
126132
}
127133

128-
static void read_mailmap_line(struct string_list *map, char *buffer)
134+
static void read_mailmap_line(struct mailmap *map, char *buffer)
129135
{
130136
char *name1 = NULL, *email1 = NULL, *name2 = NULL, *email2 = NULL;
131137

@@ -139,7 +145,7 @@ static void read_mailmap_line(struct string_list *map, char *buffer)
139145
add_mapping(map, name1, email1, name2, email2);
140146
}
141147

142-
int read_mailmap_file(struct string_list *map, const char *filename,
148+
int read_mailmap_file(struct mailmap *map, const char *filename,
143149
unsigned flags)
144150
{
145151
char buffer[1024];
@@ -167,7 +173,7 @@ int read_mailmap_file(struct string_list *map, const char *filename,
167173
return 0;
168174
}
169175

170-
static void read_mailmap_string(struct string_list *map, char *buf)
176+
static void read_mailmap_string(struct mailmap *map, char *buf)
171177
{
172178
while (*buf) {
173179
char *end = strchrnul(buf, '\n');
@@ -180,7 +186,7 @@ static void read_mailmap_string(struct string_list *map, char *buf)
180186
}
181187
}
182188

183-
int read_mailmap_blob(struct repository *repo, struct string_list *map,
189+
int read_mailmap_blob(struct repository *repo, struct mailmap *map,
184190
const char *name)
185191
{
186192
struct object_id oid;
@@ -207,16 +213,16 @@ int read_mailmap_blob(struct repository *repo, struct string_list *map,
207213
return 0;
208214
}
209215

210-
int read_mailmap(struct repository *repo, struct string_list *map)
216+
int read_mailmap(struct repository *repo, struct mailmap *map)
211217
{
212218
int err = 0;
213219
char *mailmap_file = NULL, *mailmap_blob = NULL;
214220

215221
repo_config_get_pathname(repo, "mailmap.file", &mailmap_file);
216222
repo_config_get_string(repo, "mailmap.blob", &mailmap_blob);
217223

218-
string_list_init_dup(map);
219-
map->cmp = namemap_cmp;
224+
string_list_init_dup(&map->map);
225+
map->map.cmp = namemap_cmp;
220226

221227
if (!mailmap_blob && is_bare_repository())
222228
mailmap_blob = xstrdup("HEAD:.mailmap");
@@ -236,9 +242,9 @@ int read_mailmap(struct repository *repo, struct string_list *map)
236242
return err;
237243
}
238244

239-
void clear_mailmap(struct string_list *map)
245+
void clear_mailmap(struct mailmap *map)
240246
{
241-
string_list_clear_func(map, free_mailmap_entry);
247+
string_list_clear_func(&map->map, free_mailmap_entry);
242248
}
243249

244250
/*
@@ -291,14 +297,14 @@ static struct string_list_item *lookup_prefix(struct string_list *map,
291297
return NULL;
292298
}
293299

294-
int map_user(struct string_list *map,
300+
int map_user(struct mailmap *map,
295301
const char **email, size_t *emaillen,
296302
const char **name, size_t *namelen)
297303
{
298304
struct string_list_item *item;
299305
struct mailmap_entry *me;
300306

301-
item = lookup_prefix(map, *email, *emaillen);
307+
item = lookup_prefix(&map->map, *email, *emaillen);
302308
if (item) {
303309
me = (struct mailmap_entry *)item->util;
304310
if (me->namemap.nr) {

mailmap.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
#ifndef MAILMAP_H
22
#define MAILMAP_H
33

4+
#include "string-list.h"
5+
46
struct repository;
5-
struct string_list;
7+
8+
struct mailmap {
9+
struct string_list map;
10+
};
11+
12+
#define MAILMAP_INIT { STRING_LIST_INIT_DUP }
13+
14+
void mailmap_init(struct mailmap *map);
615

716
/* Flags for read_mailmap_file() */
817
#define MAILMAP_NOFOLLOW (1<<0)
918

10-
int read_mailmap_file(struct string_list *map, const char *filename,
19+
int read_mailmap_file(struct mailmap *map, const char *filename,
1120
unsigned flags);
12-
int read_mailmap_blob(struct repository *repo, struct string_list *map,
21+
int read_mailmap_blob(struct repository *repo, struct mailmap *map,
1322
const char *name);
1423

15-
int read_mailmap(struct repository *repo, struct string_list *map);
16-
void clear_mailmap(struct string_list *map);
24+
int read_mailmap(struct repository *repo, struct mailmap *map);
25+
void clear_mailmap(struct mailmap *map);
1726

18-
int map_user(struct string_list *map,
27+
int map_user(struct mailmap *map,
1928
const char **email, size_t *emaillen, const char **name, size_t *namelen);
2029

2130
#endif

pretty.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,12 +777,13 @@ const char *repo_logmsg_reencode(struct repository *r,
777777
static int mailmap_name(const char **email, size_t *email_len,
778778
const char **name, size_t *name_len)
779779
{
780-
static struct string_list *mail_map;
780+
static struct mailmap *mail_map;
781781
if (!mail_map) {
782-
CALLOC_ARRAY(mail_map, 1);
782+
ALLOC_ARRAY(mail_map, 1);
783+
mailmap_init(mail_map);
783784
read_mailmap(the_repository, mail_map);
784785
}
785-
return mail_map->nr && map_user(mail_map, email, email_len, name, name_len);
786+
return mail_map->map.nr && map_user(mail_map, email, email_len, name, name_len);
786787
}
787788

788789
static size_t format_person_part(struct strbuf *sb, char part,

0 commit comments

Comments
 (0)