2013-07-13 00:53:10 +00:00
|
|
|
#include "builtin.h"
|
2017-06-14 18:07:36 +00:00
|
|
|
#include "config.h"
|
2023-03-21 06:25:54 +00:00
|
|
|
#include "gettext.h"
|
2023-02-24 00:09:29 +00:00
|
|
|
#include "ident.h"
|
2013-07-13 00:53:10 +00:00
|
|
|
#include "mailmap.h"
|
|
|
|
#include "parse-options.h"
|
2023-05-16 06:34:02 +00:00
|
|
|
#include "strbuf.h"
|
2013-07-13 00:53:10 +00:00
|
|
|
#include "string-list.h"
|
2023-03-21 06:26:07 +00:00
|
|
|
#include "write-or-die.h"
|
2013-07-13 00:53:10 +00:00
|
|
|
|
|
|
|
static int use_stdin;
|
|
|
|
static const char * const check_mailmap_usage[] = {
|
2015-01-13 07:44:47 +00:00
|
|
|
N_("git check-mailmap [<options>] <contact>..."),
|
2013-07-13 00:53:10 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct option check_mailmap_options[] = {
|
|
|
|
OPT_BOOL(0, "stdin", &use_stdin, N_("also read contacts from stdin")),
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
static void check_mailmap(struct string_list *mailmap, const char *contact)
|
|
|
|
{
|
|
|
|
const char *name, *mail;
|
|
|
|
size_t namelen, maillen;
|
|
|
|
struct ident_split ident;
|
|
|
|
|
|
|
|
if (split_ident_line(&ident, contact, strlen(contact)))
|
|
|
|
die(_("unable to parse contact: %s"), contact);
|
|
|
|
|
|
|
|
name = ident.name_begin;
|
|
|
|
namelen = ident.name_end - ident.name_begin;
|
|
|
|
mail = ident.mail_begin;
|
|
|
|
maillen = ident.mail_end - ident.mail_begin;
|
|
|
|
|
|
|
|
map_user(mailmap, &mail, &maillen, &name, &namelen);
|
|
|
|
|
|
|
|
if (namelen)
|
|
|
|
printf("%.*s ", (int)namelen, name);
|
|
|
|
printf("<%.*s>\n", (int)maillen, mail);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct string_list mailmap = STRING_LIST_INIT_NODUP;
|
|
|
|
|
|
|
|
git_config(git_default_config, NULL);
|
|
|
|
argc = parse_options(argc, argv, prefix, check_mailmap_options,
|
|
|
|
check_mailmap_usage, 0);
|
|
|
|
if (argc == 0 && !use_stdin)
|
|
|
|
die(_("no contacts specified"));
|
|
|
|
|
2021-01-12 20:18:06 +00:00
|
|
|
read_mailmap(&mailmap);
|
2013-07-13 00:53:10 +00:00
|
|
|
|
|
|
|
for (i = 0; i < argc; ++i)
|
|
|
|
check_mailmap(&mailmap, argv[i]);
|
|
|
|
maybe_flush_or_die(stdout, "stdout");
|
|
|
|
|
|
|
|
if (use_stdin) {
|
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2016-01-13 23:31:17 +00:00
|
|
|
while (strbuf_getline_lf(&buf, stdin) != EOF) {
|
2013-07-13 00:53:10 +00:00
|
|
|
check_mailmap(&mailmap, buf.buf);
|
|
|
|
maybe_flush_or_die(stdout, "stdout");
|
|
|
|
}
|
|
|
|
strbuf_release(&buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
clear_mailmap(&mailmap);
|
|
|
|
return 0;
|
|
|
|
}
|