In 036876a106 (config: hide functions using `the_repository` by
default, 2024-08-13) we have moved around a bunch of functions in the
config subsystem that depend on `the_repository`. Those function have
been converted into mere wrappers around their equivalent function that
takes in a repository as parameter, and the intent was that we'll
eventually remove those wrappers to make the dependency on the global
repository variable explicit at the callsite.
Follow through with that intent and remove `git_config()`. All callsites
are adjusted so that they use `repo_config(the_repository, ...)`
instead. While some callsites might already have a repository available,
this mechanical conversion is the exact same as the current situation
and thus cannot cause any regression. Those sites should eventually be
cleaned up in a later patch series.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
87 lines
2.2 KiB
C
87 lines
2.2 KiB
C
#define USE_THE_REPOSITORY_VARIABLE
|
|
#include "builtin.h"
|
|
#include "config.h"
|
|
#include "gettext.h"
|
|
#include "ident.h"
|
|
#include "mailmap.h"
|
|
#include "parse-options.h"
|
|
#include "strbuf.h"
|
|
#include "string-list.h"
|
|
#include "write-or-die.h"
|
|
|
|
static int use_stdin;
|
|
static const char *mailmap_file, *mailmap_blob;
|
|
static const char * const check_mailmap_usage[] = {
|
|
N_("git check-mailmap [<options>] <contact>..."),
|
|
NULL
|
|
};
|
|
|
|
static const struct option check_mailmap_options[] = {
|
|
OPT_BOOL(0, "stdin", &use_stdin, N_("also read contacts from stdin")),
|
|
OPT_FILENAME(0, "mailmap-file", &mailmap_file, N_("read additional mailmap entries from file")),
|
|
OPT_STRING(0, "mailmap-blob", &mailmap_blob, N_("blob"), N_("read additional mailmap entries from blob")),
|
|
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))) {
|
|
name = ident.name_begin;
|
|
namelen = ident.name_end - ident.name_begin;
|
|
mail = ident.mail_begin;
|
|
maillen = ident.mail_end - ident.mail_begin;
|
|
} else {
|
|
name = "";
|
|
namelen = 0;
|
|
mail = contact;
|
|
maillen = strlen(contact);
|
|
}
|
|
|
|
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,
|
|
struct repository *repo UNUSED)
|
|
{
|
|
int i;
|
|
struct string_list mailmap = STRING_LIST_INIT_NODUP;
|
|
|
|
repo_config(the_repository, 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"));
|
|
|
|
read_mailmap(&mailmap);
|
|
if (mailmap_blob)
|
|
read_mailmap_blob(&mailmap, mailmap_blob);
|
|
if (mailmap_file)
|
|
read_mailmap_file(&mailmap, mailmap_file, 0);
|
|
|
|
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;
|
|
while (strbuf_getline_lf(&buf, stdin) != EOF) {
|
|
check_mailmap(&mailmap, buf.buf);
|
|
maybe_flush_or_die(stdout, "stdout");
|
|
}
|
|
strbuf_release(&buf);
|
|
}
|
|
|
|
clear_mailmap(&mailmap);
|
|
return 0;
|
|
}
|