5 int read_mailmap(struct path_list *map, const char *filename, char **repo_abbrev)
8 FILE *f = fopen(filename, "r");
12 while (fgets(buffer, sizeof(buffer), f) != NULL) {
13 char *end_of_name, *left_bracket, *right_bracket;
16 if (buffer[0] == '#') {
17 static const char abbrev[] = "# repo-abbrev:";
18 int abblen = sizeof(abbrev) - 1;
19 int len = strlen(buffer);
24 if (len && buffer[len - 1] == '\n')
26 if (!strncmp(buffer, abbrev, abblen)) {
31 *repo_abbrev = xmalloc(len);
33 for (cp = buffer + abblen; isspace(*cp); cp++)
35 strcpy(*repo_abbrev, cp);
39 if ((left_bracket = strchr(buffer, '<')) == NULL)
41 if ((right_bracket = strchr(left_bracket + 1, '>')) == NULL)
43 if (right_bracket == left_bracket + 1)
45 for (end_of_name = left_bracket;
46 end_of_name != buffer && isspace(end_of_name[-1]);
48 ; /* keep on looking */
49 if (end_of_name == buffer)
51 name = xmalloc(end_of_name - buffer + 1);
52 strlcpy(name, buffer, end_of_name - buffer + 1);
53 email = xmalloc(right_bracket - left_bracket);
54 for (i = 0; i < right_bracket - left_bracket - 1; i++)
55 email[i] = tolower(left_bracket[i + 1]);
56 email[right_bracket - left_bracket - 1] = '\0';
57 path_list_insert(email, map)->util = name;
63 int map_email(struct path_list *map, const char *email, char *name, int maxlen)
66 struct path_list_item *item;
67 char buf[1024], *mailbuf;
70 /* autocomplete common developers */
71 p = strchr(email, '>');
74 if (p - email + 1 < sizeof(buf))
77 mailbuf = xmalloc(p - email + 1);
79 /* downcase the email address */
80 for (i = 0; i < p - email; i++)
81 mailbuf[i] = tolower(email[i]);
83 item = path_list_lookup(mailbuf, map);
87 const char *realname = (const char *)item->util;
88 strlcpy(name, realname, maxlen);