Code

Merge branch 'jn/gitweb-unspecified-action' into maint-1.7.8
[git.git] / mailmap.c
index b68c1fec9c2ca69f313bc3fa16461c6c9150c53d..8c3196c7d76ff90e90a9fb4ff569aff6a429861a 100644 (file)
--- a/mailmap.c
+++ b/mailmap.c
@@ -69,9 +69,8 @@ static void add_mapping(struct string_list *map,
                index = -1 - index;
        } else {
                /* create mailmap entry */
-               struct string_list_item *item = string_list_insert_at_index(index, old_email, map);
-               item->util = xmalloc(sizeof(struct mailmap_entry));
-               memset(item->util, 0, sizeof(struct mailmap_entry));
+               struct string_list_item *item = string_list_insert_at_index(map, index, old_email);
+               item->util = xcalloc(1, sizeof(struct mailmap_entry));
                ((struct mailmap_entry *)item->util)->namemap.strdup_strings = 1;
        }
        me = (struct mailmap_entry *)map->items[index].util;
@@ -79,20 +78,22 @@ 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);
                /* Replace current name and new email for simple entry */
-               free(me->name);
-               free(me->email);
-               if (new_name)
+               if (new_name) {
+                       free(me->name);
                        me->name = xstrdup(new_name);
-               if (new_email)
+               }
+               if (new_email) {
+                       free(me->email);
                        me->email = xstrdup(new_email);
+               }
        } else {
-               struct mailmap_info *mi = xmalloc(sizeof(struct mailmap_info));
+               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);
                if (new_name)
                        mi->name = xstrdup(new_name);
                if (new_email)
                        mi->email = xstrdup(new_email);
-               string_list_insert(old_name, &me->namemap)->util = mi;
+               string_list_insert(&me->namemap, old_name)->util = mi;
        }
 
        debug_mm("mailmap:  '%s' <%s> -> '%s' <%s>\n",
@@ -214,13 +215,13 @@ int map_user(struct string_list *map,
        mailbuf[i] = 0;
 
        debug_mm("map_user: map '%s' <%s>\n", name, mailbuf);
-       item = string_list_lookup(mailbuf, map);
+       item = string_list_lookup(map, mailbuf);
        if (item != NULL) {
                me = (struct mailmap_entry *)item->util;
                if (me->namemap.nr) {
                        /* The item has multiple items, so we'll look up on name too */
                        /* If the name is not found, we choose the simple entry      */
-                       struct string_list_item *subitem = string_list_lookup(name, &me->namemap);
+                       struct string_list_item *subitem = string_list_lookup(&me->namemap, name);
                        if (subitem)
                                item = subitem;
                }