Code

completion: --edit and --no-edit for git-merge
[git.git] / mailmap.c
index 4892d497343a2d04812e331b379af2f8403db139..8c3196c7d76ff90e90a9fb4ff569aff6a429861a 100644 (file)
--- a/mailmap.c
+++ b/mailmap.c
@@ -50,6 +50,15 @@ static void add_mapping(struct string_list *map,
 {
        struct mailmap_entry *me;
        int index;
+       char *p;
+
+       if (old_email)
+               for (p = old_email; *p; p++)
+                       *p = tolower(*p);
+       if (new_email)
+               for (p = new_email; *p; p++)
+                       *p = tolower(*p);
+
        if (old_email == NULL) {
                old_email = new_email;
                new_email = NULL;
@@ -60,7 +69,7 @@ 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);
+               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;
        }
@@ -69,12 +78,14 @@ 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 = xcalloc(1, sizeof(struct mailmap_info));
                debug_mm("mailmap: adding (complex) entry for %s at index %d\n", old_email, index);
@@ -82,23 +93,24 @@ static void add_mapping(struct string_list *map,
                        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",
                 old_name, old_email, new_name, new_email);
 }
 
-static char *parse_name_and_email(char *buffer, char **name, char **email)
+static char *parse_name_and_email(char *buffer, char **name,
+               char **email, int allow_empty_email)
 {
        char *left, *right, *nstart, *nend;
-       *name = *email = 0;
+       *name = *email = NULL;
 
        if ((left = strchr(buffer, '<')) == NULL)
                return NULL;
        if ((right = strchr(left+1, '>')) == NULL)
                return NULL;
-       if (left+1 == right)
+       if (!allow_empty_email && (left+1 == right))
                return NULL;
 
        /* remove whitespace from beginning and end of name */
@@ -125,7 +137,7 @@ static int read_single_mailmap(struct string_list *map, const char *filename, ch
        if (f == NULL)
                return 1;
        while (fgets(buffer, sizeof(buffer), f) != NULL) {
-               char *name1 = 0, *email1 = 0, *name2 = 0, *email2 = 0;
+               char *name1 = NULL, *email1 = NULL, *name2 = NULL, *email2 = NULL;
                if (buffer[0] == '#') {
                        static const char abbrev[] = "# repo-abbrev:";
                        int abblen = sizeof(abbrev) - 1;
@@ -149,8 +161,8 @@ static int read_single_mailmap(struct string_list *map, const char *filename, ch
                        }
                        continue;
                }
-               if ((name2 = parse_name_and_email(buffer, &name1, &email1)) != NULL)
-                       parse_name_and_email(name2, &name2, &email2);
+               if ((name2 = parse_name_and_email(buffer, &name1, &email1, 0)) != NULL)
+                       parse_name_and_email(name2, &name2, &email2, 1);
 
                if (email1)
                        add_mapping(map, name1, email1, name2, email2);
@@ -189,7 +201,7 @@ int map_user(struct string_list *map,
        if (!p) {
                /* email passed in might not be wrapped in <>, but end with a \0 */
                p = memchr(email, '\0', maxlen_email);
-               if (p == 0)
+               if (!p)
                        return 0;
        }
        if (p - email + 1 < sizeof(buf))
@@ -203,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;
                }
@@ -232,8 +244,3 @@ int map_user(struct string_list *map,
        debug_mm("map_user:  --\n");
        return 0;
 }
-
-int map_email(struct string_list *map, const char *email, char *name, int maxlen)
-{
-       return map_user(map, (char *)email, 0, name, maxlen);
-}