dir.h: move struct exclude declaration to top level
[git.git] / builtin / check-mailmap.c
blob8f4d809bd8c00558b34022cc0c46423a6b19243c
1 #include "builtin.h"
2 #include "mailmap.h"
3 #include "parse-options.h"
4 #include "string-list.h"
6 static int use_stdin;
7 static const char * const check_mailmap_usage[] = {
8 N_("git check-mailmap [options] <contact>..."),
9 NULL
12 static const struct option check_mailmap_options[] = {
13 OPT_BOOL(0, "stdin", &use_stdin, N_("also read contacts from stdin")),
14 OPT_END()
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);
33 if (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)
40 int i;
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");
55 if (use_stdin) {
56 struct strbuf buf = STRBUF_INIT;
57 while (strbuf_getline(&buf, stdin, '\n') != EOF) {
58 check_mailmap(&mailmap, buf.buf);
59 maybe_flush_or_die(stdout, "stdout");
61 strbuf_release(&buf);
64 clear_mailmap(&mailmap);
65 return 0;