6 #include "parse-options.h"
7 #include "string-list.h"
8 #include "write-or-die.h"
11 static const char * const check_mailmap_usage
[] = {
12 N_("git check-mailmap [<options>] <contact>..."),
16 static const struct option check_mailmap_options
[] = {
17 OPT_BOOL(0, "stdin", &use_stdin
, N_("also read contacts from stdin")),
21 static void check_mailmap(struct string_list
*mailmap
, const char *contact
)
23 const char *name
, *mail
;
24 size_t namelen
, maillen
;
25 struct ident_split ident
;
27 if (split_ident_line(&ident
, contact
, strlen(contact
)))
28 die(_("unable to parse contact: %s"), contact
);
30 name
= ident
.name_begin
;
31 namelen
= ident
.name_end
- ident
.name_begin
;
32 mail
= ident
.mail_begin
;
33 maillen
= ident
.mail_end
- ident
.mail_begin
;
35 map_user(mailmap
, &mail
, &maillen
, &name
, &namelen
);
38 printf("%.*s ", (int)namelen
, name
);
39 printf("<%.*s>\n", (int)maillen
, mail
);
42 int cmd_check_mailmap(int argc
, const char **argv
, const char *prefix
)
45 struct string_list mailmap
= STRING_LIST_INIT_NODUP
;
47 git_config(git_default_config
, NULL
);
48 argc
= parse_options(argc
, argv
, prefix
, check_mailmap_options
,
49 check_mailmap_usage
, 0);
50 if (argc
== 0 && !use_stdin
)
51 die(_("no contacts specified"));
53 read_mailmap(&mailmap
);
55 for (i
= 0; i
< argc
; ++i
)
56 check_mailmap(&mailmap
, argv
[i
]);
57 maybe_flush_or_die(stdout
, "stdout");
60 struct strbuf buf
= STRBUF_INIT
;
61 while (strbuf_getline_lf(&buf
, stdin
) != EOF
) {
62 check_mailmap(&mailmap
, buf
.buf
);
63 maybe_flush_or_die(stdout
, "stdout");
68 clear_mailmap(&mailmap
);