6 #include "parse-options.h"
8 #include "string-list.h"
9 #include "write-or-die.h"
12 static const char * const check_mailmap_usage
[] = {
13 N_("git check-mailmap [<options>] <contact>..."),
17 static const struct option check_mailmap_options
[] = {
18 OPT_BOOL(0, "stdin", &use_stdin
, N_("also read contacts from stdin")),
22 static void check_mailmap(struct string_list
*mailmap
, const char *contact
)
24 const char *name
, *mail
;
25 size_t namelen
, maillen
;
26 struct ident_split ident
;
28 if (split_ident_line(&ident
, contact
, strlen(contact
)))
29 die(_("unable to parse contact: %s"), contact
);
31 name
= ident
.name_begin
;
32 namelen
= ident
.name_end
- ident
.name_begin
;
33 mail
= ident
.mail_begin
;
34 maillen
= ident
.mail_end
- ident
.mail_begin
;
36 map_user(mailmap
, &mail
, &maillen
, &name
, &namelen
);
39 printf("%.*s ", (int)namelen
, name
);
40 printf("<%.*s>\n", (int)maillen
, mail
);
43 int cmd_check_mailmap(int argc
, const char **argv
, const char *prefix
)
46 struct string_list mailmap
= STRING_LIST_INIT_NODUP
;
48 git_config(git_default_config
, NULL
);
49 argc
= parse_options(argc
, argv
, prefix
, check_mailmap_options
,
50 check_mailmap_usage
, 0);
51 if (argc
== 0 && !use_stdin
)
52 die(_("no contacts specified"));
54 read_mailmap(&mailmap
);
56 for (i
= 0; i
< argc
; ++i
)
57 check_mailmap(&mailmap
, argv
[i
]);
58 maybe_flush_or_die(stdout
, "stdout");
61 struct strbuf buf
= STRBUF_INIT
;
62 while (strbuf_getline_lf(&buf
, stdin
) != EOF
) {
63 check_mailmap(&mailmap
, buf
.buf
);
64 maybe_flush_or_die(stdout
, "stdout");
69 clear_mailmap(&mailmap
);