]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/check-mailmap.c
Start the 2.46 cycle
[thirdparty/git.git] / builtin / check-mailmap.c
CommitLineData
226ad348 1#include "builtin.h"
b2141fc1 2#include "config.h"
f394e093 3#include "gettext.h"
b5fa6081 4#include "ident.h"
226ad348
ES
5#include "mailmap.h"
6#include "parse-options.h"
88e4e183 7#include "strbuf.h"
226ad348 8#include "string-list.h"
d48be35c 9#include "write-or-die.h"
226ad348
ES
10
11static int use_stdin;
12static const char * const check_mailmap_usage[] = {
9c9b4f2f 13N_("git check-mailmap [<options>] <contact>..."),
226ad348
ES
14NULL
15};
16
17static const struct option check_mailmap_options[] = {
18 OPT_BOOL(0, "stdin", &use_stdin, N_("also read contacts from stdin")),
19 OPT_END()
20};
21
22static void check_mailmap(struct string_list *mailmap, const char *contact)
23{
24 const char *name, *mail;
25 size_t namelen, maillen;
26 struct ident_split ident;
27
28 if (split_ident_line(&ident, contact, strlen(contact)))
29 die(_("unable to parse contact: %s"), contact);
30
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;
35
36 map_user(mailmap, &mail, &maillen, &name, &namelen);
37
38 if (namelen)
39 printf("%.*s ", (int)namelen, name);
40 printf("<%.*s>\n", (int)maillen, mail);
41}
42
43int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
44{
45 int i;
46 struct string_list mailmap = STRING_LIST_INIT_NODUP;
47
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"));
53
4e168333 54 read_mailmap(&mailmap);
226ad348
ES
55
56 for (i = 0; i < argc; ++i)
57 check_mailmap(&mailmap, argv[i]);
58 maybe_flush_or_die(stdout, "stdout");
59
60 if (use_stdin) {
61 struct strbuf buf = STRBUF_INIT;
8f309aeb 62 while (strbuf_getline_lf(&buf, stdin) != EOF) {
226ad348
ES
63 check_mailmap(&mailmap, buf.buf);
64 maybe_flush_or_die(stdout, "stdout");
65 }
66 strbuf_release(&buf);
67 }
68
69 clear_mailmap(&mailmap);
70 return 0;
71}