Skip to content

Commit 6322621

Browse files
stefanbellergitster
authored andcommitted
mailmap: use higher level string list functions
No functional changes intended. This commit makes use of higher level and better documented functions of the string list API, so the code is more understandable. Note that also the required computational amount should not change in principal as we need to look up the item no matter if it is already part of the list or not. Once looked up, insertion comes for free. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent fc66505 commit 6322621

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

mailmap.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,26 @@ static void add_mapping(struct string_list *map,
7171
char *old_name, char *old_email)
7272
{
7373
struct mailmap_entry *me;
74-
int index;
74+
struct string_list_item *item;
7575

7676
if (old_email == NULL) {
7777
old_email = new_email;
7878
new_email = NULL;
7979
}
8080

81-
if ((index = string_list_find_insert_index(map, old_email, 1)) < 0) {
82-
/* mailmap entry exists, invert index value */
83-
index = -1 - index;
84-
me = (struct mailmap_entry *)map->items[index].util;
81+
item = string_list_insert(map, old_email);
82+
if (item->util) {
83+
me = (struct mailmap_entry *)item->util;
8584
} else {
86-
/* create mailmap entry */
87-
struct string_list_item *item;
88-
89-
item = string_list_insert_at_index(map, index, old_email);
9085
me = xcalloc(1, sizeof(struct mailmap_entry));
9186
me->namemap.strdup_strings = 1;
9287
me->namemap.cmp = namemap_cmp;
9388
item->util = me;
9489
}
9590

9691
if (old_name == NULL) {
97-
debug_mm("mailmap: adding (simple) entry for %s at index %d\n",
98-
old_email, index);
92+
debug_mm("mailmap: adding (simple) entry for '%s'\n", old_email);
93+
9994
/* Replace current name and new email for simple entry */
10095
if (new_name) {
10196
free(me->name);
@@ -107,8 +102,7 @@ static void add_mapping(struct string_list *map,
107102
}
108103
} else {
109104
struct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info));
110-
debug_mm("mailmap: adding (complex) entry for %s at index %d\n",
111-
old_email, index);
105+
debug_mm("mailmap: adding (complex) entry for '%s'\n", old_email);
112106
if (new_name)
113107
mi->name = xstrdup(new_name);
114108
if (new_email)

0 commit comments

Comments
 (0)