3 #include "parse-options.h"
4 #include "string-list.h"
7 static const char * const check_mailmap_usage
[] = {
8 N_("git check-mailmap [<options>] <contact>..."),
12 static const struct option check_mailmap_options
[] = {
13 OPT_BOOL(0, "stdin", &use_stdin
, N_("also read contacts from stdin")),
17 static void check_mailmap(struct string_list
*mailmap
, const char *contact
)
19 const char *name
, *mail
;
20 size_t namelen
, maillen
;
21 struct ident_split ident
;
23 if (split_ident_line(&ident
, contact
, strlen(contact
)))
24 die(_("unable to parse contact: %s"), contact
);
26 name
= ident
.name_begin
;
27 namelen
= ident
.name_end
- ident
.name_begin
;
28 mail
= ident
.mail_begin
;
29 maillen
= ident
.mail_end
- ident
.mail_begin
;
31 map_user(mailmap
, &mail
, &maillen
, &name
, &namelen
);
34 printf("%.*s ", (int)namelen
, name
);
35 printf("<%.*s>\n", (int)maillen
, mail
);
38 int cmd_check_mailmap(int argc
, const char **argv
, const char *prefix
)
41 struct string_list mailmap
= STRING_LIST_INIT_NODUP
;
43 git_config(git_default_config
, NULL
);
44 argc
= parse_options(argc
, argv
, prefix
, check_mailmap_options
,
45 check_mailmap_usage
, 0);
46 if (argc
== 0 && !use_stdin
)
47 die(_("no contacts specified"));
49 read_mailmap(&mailmap
, NULL
);
51 for (i
= 0; i
< argc
; ++i
)
52 check_mailmap(&mailmap
, argv
[i
]);
53 maybe_flush_or_die(stdout
, "stdout");
56 struct strbuf buf
= STRBUF_INIT
;
57 while (strbuf_getline_lf(&buf
, stdin
) != EOF
) {
58 check_mailmap(&mailmap
, buf
.buf
);
59 maybe_flush_or_die(stdout
, "stdout");
64 clear_mailmap(&mailmap
);