Merge branch 'sb/submodule-config-parse'
[gitweb.git] / mailmap.c
index 91a7532506328ff5d65c049d32a9e23a6d849b8b..9e9589730fa44c94d122dfdb50172baf95e2578d 100644 (file)
--- a/mailmap.c
+++ b/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)
@@ -167,8 +161,7 @@ static void read_mailmap_line(struct string_list *map, char *buffer,
                if (!strncmp(buffer, abbrev, abblen)) {
                        char *cp;
 
-                       if (repo_abbrev)
-                               free(*repo_abbrev);
+                       free(*repo_abbrev);
                        *repo_abbrev = xmalloc(len);
 
                        for (cp = buffer + abblen; isspace(*cp); cp++)
@@ -207,20 +200,17 @@ static int read_mailmap_file(struct string_list *map, const char *filename,
        return 0;
 }
 
-static void read_mailmap_buf(struct string_list *map,
-                            const char *buf, unsigned long len,
-                            char **repo_abbrev)
+static void read_mailmap_string(struct string_list *map, char *buf,
+                               char **repo_abbrev)
 {
-       while (len) {
-               const char *end = strchrnul(buf, '\n');
-               unsigned long linelen = end - buf + 1;
-               char *line = xmemdupz(buf, linelen);
+       while (*buf) {
+               char *end = strchrnul(buf, '\n');
 
-               read_mailmap_line(map, line, repo_abbrev);
+               if (*end)
+                       *end++ = '\0';
 
-               free(line);
-               buf += linelen;
-               len -= linelen;
+               read_mailmap_line(map, buf, repo_abbrev);
+               buf = end;
        }
 }
 
@@ -244,7 +234,7 @@ static int read_mailmap_blob(struct string_list *map,
        if (type != OBJ_BLOB)
                return error("mailmap is not a blob: %s", name);
 
-       read_mailmap_buf(map, buf, size, repo_abbrev);
+       read_mailmap_string(map, buf, repo_abbrev);
 
        free(buf);
        return 0;