1 #define USE_THE_REPOSITORY_VARIABLE
7 #include "parse-options.h"
9 #include "string-list.h"
10 #include "write-or-die.h"
13 static const char *mailmap_file
, *mailmap_blob
;
14 static const char * const check_mailmap_usage
[] = {
15 N_("git check-mailmap [<options>] <contact>..."),
19 static const struct option check_mailmap_options
[] = {
20 OPT_BOOL(0, "stdin", &use_stdin
, N_("also read contacts from stdin")),
21 OPT_FILENAME(0, "mailmap-file", &mailmap_file
, N_("read additional mailmap entries from file")),
22 OPT_STRING(0, "mailmap-blob", &mailmap_blob
, N_("blob"), N_("read additional mailmap entries from blob")),
26 static void check_mailmap(struct string_list
*mailmap
, const char *contact
)
28 const char *name
, *mail
;
29 size_t namelen
, maillen
;
30 struct ident_split ident
;
32 if (!split_ident_line(&ident
, contact
, strlen(contact
))) {
33 name
= ident
.name_begin
;
34 namelen
= ident
.name_end
- ident
.name_begin
;
35 mail
= ident
.mail_begin
;
36 maillen
= ident
.mail_end
- ident
.mail_begin
;
41 maillen
= strlen(contact
);
44 map_user(mailmap
, &mail
, &maillen
, &name
, &namelen
);
47 printf("%.*s ", (int)namelen
, name
);
48 printf("<%.*s>\n", (int)maillen
, mail
);
51 int cmd_check_mailmap(int argc
,
54 struct repository
*repo UNUSED
)
57 struct string_list mailmap
= STRING_LIST_INIT_NODUP
;
59 git_config(git_default_config
, NULL
);
60 argc
= parse_options(argc
, argv
, prefix
, check_mailmap_options
,
61 check_mailmap_usage
, 0);
62 if (argc
== 0 && !use_stdin
)
63 die(_("no contacts specified"));
65 read_mailmap(&mailmap
);
67 read_mailmap_blob(&mailmap
, mailmap_blob
);
69 read_mailmap_file(&mailmap
, mailmap_file
, 0);
71 for (i
= 0; i
< argc
; ++i
)
72 check_mailmap(&mailmap
, argv
[i
]);
73 maybe_flush_or_die(stdout
, "stdout");
76 struct strbuf buf
= STRBUF_INIT
;
77 while (strbuf_getline_lf(&buf
, stdin
) != EOF
) {
78 check_mailmap(&mailmap
, buf
.buf
);
79 maybe_flush_or_die(stdout
, "stdout");
84 clear_mailmap(&mailmap
);