4 int read_mailmap(struct path_list
*map
, const char *filename
, char **repo_abbrev
)
7 FILE *f
= fopen(filename
, "r");
11 while (fgets(buffer
, sizeof(buffer
), f
) != NULL
) {
12 char *end_of_name
, *left_bracket
, *right_bracket
;
15 if (buffer
[0] == '#') {
16 static const char abbrev
[] = "# repo-abbrev:";
17 int abblen
= sizeof(abbrev
) - 1;
18 int len
= strlen(buffer
);
20 if (len
&& buffer
[len
- 1] == '\n')
22 if (!strncmp(buffer
, abbrev
, abblen
)) {
27 *repo_abbrev
= xmalloc(len
);
29 for (cp
= buffer
+ abblen
; isspace(*cp
); cp
++)
31 strcpy(*repo_abbrev
, cp
);
35 if ((left_bracket
= strchr(buffer
, '<')) == NULL
)
37 if ((right_bracket
= strchr(left_bracket
+ 1, '>')) == NULL
)
39 if (right_bracket
== left_bracket
+ 1)
41 for (end_of_name
= left_bracket
; end_of_name
!= buffer
42 && isspace(end_of_name
[-1]); end_of_name
--)
44 if (end_of_name
== buffer
)
46 name
= xmalloc(end_of_name
- buffer
+ 1);
47 strlcpy(name
, buffer
, end_of_name
- buffer
+ 1);
48 email
= xmalloc(right_bracket
- left_bracket
);
49 for (i
= 0; i
< right_bracket
- left_bracket
- 1; i
++)
50 email
[i
] = tolower(left_bracket
[i
+ 1]);
51 email
[right_bracket
- left_bracket
- 1] = '\0';
52 path_list_insert(email
, map
)->util
= name
;
58 int map_email(struct path_list
*map
, const char *email
, char *name
, int maxlen
)
61 struct path_list_item
*item
;
62 char buf
[1024], *mailbuf
;
65 /* autocomplete common developers */
66 p
= strchr(email
, '>');
69 if (p
- email
+ 1 < sizeof(buf
))
72 mailbuf
= xmalloc(p
- email
+ 1);
74 /* downcase the email address */
75 for (i
= 0; i
< p
- email
; i
++)
76 mailbuf
[i
] = tolower(email
[i
]);
78 item
= path_list_lookup(mailbuf
, map
);
82 const char *realname
= (const char *)item
->util
;
83 strncpy(name
, realname
, maxlen
);