Merge branch 'ml/mailmap' into maint-1.7.6
authorJunio C Hamano <gitster@pobox.com>
Wed, 14 Dec 2011 05:12:14 +0000 (21:12 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Dec 2011 05:12:14 +0000 (21:12 -0800)
* ml/mailmap:
mailmap: xcalloc mailmap_info

Conflicts:
mailmap.c

1  2 
mailmap.c
diff --combined mailmap.c
index 02fcfde0b0b786af5229559586cf8ff5758429bc,4892d497343a2d04812e331b379af2f8403db139..8c3196c7d76ff90e90a9fb4ff569aff6a429861a
+++ b/mailmap.c
@@@ -50,15 -50,6 +50,15 @@@ static void add_mapping(struct string_l
  {
        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;
@@@ -69,9 -60,8 +69,8 @@@
                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 = xmalloc(sizeof(struct mailmap_entry));
-               memset(item->util, 0, sizeof(struct mailmap_entry));
+               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;
        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",
                 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 */
@@@ -138,7 -125,7 +137,7 @@@ static int read_single_mailmap(struct s
        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;
                        }
                        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);
@@@ -202,7 -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))
        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;
                }
        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);
 -}