mirror of
https://github.com/git/git.git
synced 2024-11-18 23:13:58 +01:00
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>
This commit is contained in:
parent
fc66505c53
commit
63226218ba
20
mailmap.c
20
mailmap.c
@ -71,22 +71,17 @@ static void add_mapping(struct string_list *map,
|
||||
char *old_name, char *old_email)
|
||||
{
|
||||
struct mailmap_entry *me;
|
||||
int index;
|
||||
struct string_list_item *item;
|
||||
|
||||
if (old_email == NULL) {
|
||||
old_email = new_email;
|
||||
new_email = NULL;
|
||||
}
|
||||
|
||||
if ((index = string_list_find_insert_index(map, old_email, 1)) < 0) {
|
||||
/* mailmap entry exists, invert index value */
|
||||
index = -1 - index;
|
||||
me = (struct mailmap_entry *)map->items[index].util;
|
||||
item = string_list_insert(map, old_email);
|
||||
if (item->util) {
|
||||
me = (struct mailmap_entry *)item->util;
|
||||
} else {
|
||||
/* create mailmap entry */
|
||||
struct string_list_item *item;
|
||||
|
||||
item = string_list_insert_at_index(map, index, old_email);
|
||||
me = xcalloc(1, sizeof(struct mailmap_entry));
|
||||
me->namemap.strdup_strings = 1;
|
||||
me->namemap.cmp = namemap_cmp;
|
||||
@ -94,8 +89,8 @@ static void add_mapping(struct string_list *map,
|
||||
}
|
||||
|
||||
if (old_name == NULL) {
|
||||
debug_mm("mailmap: adding (simple) entry for %s at index %d\n",
|
||||
old_email, index);
|
||||
debug_mm("mailmap: adding (simple) entry for '%s'\n", old_email);
|
||||
|
||||
/* Replace current name and new email for simple entry */
|
||||
if (new_name) {
|
||||
free(me->name);
|
||||
@ -107,8 +102,7 @@ static void add_mapping(struct string_list *map,
|
||||
}
|
||||
} else {
|
||||
struct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info));
|
||||
debug_mm("mailmap: adding (complex) entry for %s at index %d\n",
|
||||
old_email, index);
|
||||
debug_mm("mailmap: adding (complex) entry for '%s'\n", old_email);
|
||||
if (new_name)
|
||||
mi->name = xstrdup(new_name);
|
||||
if (new_email)
|
||||
|
Loading…
Reference in New Issue
Block a user