bulk-checkin: convert index_bulk_checkin to struct object_id
[git.git] / builtin / check-mailmap.c
blobcdce144f3b7f160f508721ed4f4afc69d683262a
1 #include "builtin.h"
2 #include "config.h"
3 #include "mailmap.h"
4 #include "parse-options.h"
5 #include "string-list.h"
7 static int use_stdin;
8 static const char * const check_mailmap_usage[] = {
9 N_("git check-mailmap [<options>] <contact>..."),
10 NULL
13 static const struct option check_mailmap_options[] = {
14 OPT_BOOL(0, "stdin", &use_stdin, N_("also read contacts from stdin")),
15 OPT_END()
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);
34 if (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)
41 int i;
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");
56 if (use_stdin) {
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");
62 strbuf_release(&buf);
65 clear_mailmap(&mailmap);
66 return 0;