/src/git/builtin/check-mailmap.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include "builtin.h" |
2 | | #include "config.h" |
3 | | #include "gettext.h" |
4 | | #include "ident.h" |
5 | | #include "mailmap.h" |
6 | | #include "parse-options.h" |
7 | | #include "strbuf.h" |
8 | | #include "string-list.h" |
9 | | #include "write-or-die.h" |
10 | | |
11 | | static int use_stdin; |
12 | | static const char *mailmap_file, *mailmap_blob; |
13 | | static const char * const check_mailmap_usage[] = { |
14 | | N_("git check-mailmap [<options>] <contact>..."), |
15 | | NULL |
16 | | }; |
17 | | |
18 | | static const struct option check_mailmap_options[] = { |
19 | | OPT_BOOL(0, "stdin", &use_stdin, N_("also read contacts from stdin")), |
20 | | OPT_FILENAME(0, "mailmap-file", &mailmap_file, N_("read additional mailmap entries from file")), |
21 | | OPT_STRING(0, "mailmap-blob", &mailmap_blob, N_("blob"), N_("read additional mailmap entries from blob")), |
22 | | OPT_END() |
23 | | }; |
24 | | |
25 | | static void check_mailmap(struct string_list *mailmap, const char *contact) |
26 | 0 | { |
27 | 0 | const char *name, *mail; |
28 | 0 | size_t namelen, maillen; |
29 | 0 | struct ident_split ident; |
30 | |
|
31 | 0 | if (!split_ident_line(&ident, contact, strlen(contact))) { |
32 | 0 | name = ident.name_begin; |
33 | 0 | namelen = ident.name_end - ident.name_begin; |
34 | 0 | mail = ident.mail_begin; |
35 | 0 | maillen = ident.mail_end - ident.mail_begin; |
36 | 0 | } else { |
37 | 0 | name = NULL; |
38 | 0 | namelen = 0; |
39 | 0 | mail = contact; |
40 | 0 | maillen = strlen(contact); |
41 | 0 | } |
42 | |
|
43 | 0 | map_user(mailmap, &mail, &maillen, &name, &namelen); |
44 | |
|
45 | 0 | if (namelen) |
46 | 0 | printf("%.*s ", (int)namelen, name); |
47 | 0 | printf("<%.*s>\n", (int)maillen, mail); |
48 | 0 | } |
49 | | |
50 | | int cmd_check_mailmap(int argc, const char **argv, const char *prefix) |
51 | 0 | { |
52 | 0 | int i; |
53 | 0 | struct string_list mailmap = STRING_LIST_INIT_NODUP; |
54 | |
|
55 | 0 | git_config(git_default_config, NULL); |
56 | 0 | argc = parse_options(argc, argv, prefix, check_mailmap_options, |
57 | 0 | check_mailmap_usage, 0); |
58 | 0 | if (argc == 0 && !use_stdin) |
59 | 0 | die(_("no contacts specified")); |
60 | | |
61 | 0 | read_mailmap(&mailmap); |
62 | 0 | if (mailmap_blob) |
63 | 0 | read_mailmap_blob(&mailmap, mailmap_blob); |
64 | 0 | if (mailmap_file) |
65 | 0 | read_mailmap_file(&mailmap, mailmap_file, 0); |
66 | |
|
67 | 0 | for (i = 0; i < argc; ++i) |
68 | 0 | check_mailmap(&mailmap, argv[i]); |
69 | 0 | maybe_flush_or_die(stdout, "stdout"); |
70 | |
|
71 | 0 | if (use_stdin) { |
72 | 0 | struct strbuf buf = STRBUF_INIT; |
73 | 0 | while (strbuf_getline_lf(&buf, stdin) != EOF) { |
74 | 0 | check_mailmap(&mailmap, buf.buf); |
75 | 0 | maybe_flush_or_die(stdout, "stdout"); |
76 | 0 | } |
77 | 0 | strbuf_release(&buf); |
78 | 0 | } |
79 | |
|
80 | 0 | clear_mailmap(&mailmap); |
81 | 0 | return 0; |
82 | 0 | } |