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>
Stefan Beller committed
Nov 24, 2014 at 19:44 UTC
63226218ba39e971c8a75d9419a7668b075ad85e
1 file changed
+7
-13
mailmap.c
+7
-13
@@ -71,22 +71,17 @@ static void add_mapping(struct string_list *map,
71
char *old_name, char *old_email)
72
{
73
struct mailmap_entry *me;
74
- int index;
74
+ struct string_list_item *item;
75
76
if (old_email == NULL) {
77
old_email = new_email;
78
new_email = NULL;
79
}
80
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;
84
} else {
86
- /* create mailmap entry */
87
- struct string_list_item *item;
88
-
89
- item = string_list_insert_at_index(map, index, old_email);
85
me = xcalloc(1, sizeof(struct mailmap_entry));
86
me->namemap.strdup_strings = 1;
87
me->namemap.cmp = namemap_cmp;
@@ -94,8 +89,8 @@ static void add_mapping(struct string_list *map,
89
}
90
91
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
+
94
/* Replace current name and new email for simple entry */
95
if (new_name) {
96
free(me->name);
@@ -107,8 +102,7 @@ static void add_mapping(struct string_list *map,
102
}
103
} else {
104
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);
106
if (new_name)
107
mi->name = xstrdup(new_name);
108
if (new_email)