4 #include "parse-options.h"
5 #include "string-list.h"
8 static const char * const check_mailmap_usage
[] = {
9 N_("git check-mailmap [<options>] <contact>..."),
13 static const struct option check_mailmap_options
[] = {
14 OPT_BOOL(0, "stdin", &use_stdin
, N_("also read contacts from stdin")),
18 static void check_mailmap(struct string_list
*mailmap
, const char *contact
)
20 const char *name
, *mail
;
21 size_t namelen
, maillen
;
22 struct ident_split ident
;
24 if (split_ident_line(&ident
, contact
, strlen(contact
)))
25 die(_("unable to parse contact: %s"), contact
);
27 name
= ident
.name_begin
;
28 namelen
= ident
.name_end
- ident
.name_begin
;
29 mail
= ident
.mail_begin
;
30 maillen
= ident
.mail_end
- ident
.mail_begin
;
32 map_user(mailmap
, &mail
, &maillen
, &name
, &namelen
);
35 printf("%.*s ", (int)namelen
, name
);
36 printf("<%.*s>\n", (int)maillen
, mail
);
39 int cmd_check_mailmap(int argc
, const char **argv
, const char *prefix
)
42 struct string_list mailmap
= STRING_LIST_INIT_NODUP
;
44 git_config(git_default_config
, NULL
);
45 argc
= parse_options(argc
, argv
, prefix
, check_mailmap_options
,
46 check_mailmap_usage
, 0);
47 if (argc
== 0 && !use_stdin
)
48 die(_("no contacts specified"));
50 read_mailmap(&mailmap
, NULL
);
52 for (i
= 0; i
< argc
; ++i
)
53 check_mailmap(&mailmap
, argv
[i
]);
54 maybe_flush_or_die(stdout
, "stdout");
57 struct strbuf buf
= STRBUF_INIT
;
58 while (strbuf_getline_lf(&buf
, stdin
) != EOF
) {
59 check_mailmap(&mailmap
, buf
.buf
);
60 maybe_flush_or_die(stdout
, "stdout");
65 clear_mailmap(&mailmap
);