Skip to content

Commit f54ca6a

Browse files
jacob-kellergitster
authored andcommitted
check-mailmap: add options for additional mailmap sources
The git check-mailmap command reads the mailmap from either the default .mailmap location and then from the mailmap.blob and mailmap.file configurations. A following change to git send-email will want to support new configuration options based on the configured identity. The identity-based configuration and options only make sense in the context of git send-email. Expose the read_mailmap_file and read_mailmap_blob functions from mailmap.c. Teach git check-mailmap the --mailmap-file and --mailmap-blob options which load the additional mailmap sources. Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3a27e99 commit f54ca6a

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

Documentation/git-check-mailmap.txt

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ OPTIONS
2727
Read contacts, one per line, from the standard input after exhausting
2828
contacts provided on the command-line.
2929

30+
--mailmap-file=<file>::
31+
In addition to any configured mailmap files, read the specified
32+
mailmap file. Entries in this file take precedence over entries in
33+
either the default mailmap file or any configured mailmap file.
34+
35+
--mailmap-blob=<blob>::
36+
Like `--mailmap-file`, but consider the value as a reference to a
37+
blob in the repository. If both `--mailmap-file` and
38+
`--mailmap-blob` are specified, entries in `--mailmap-file` will
39+
take precedence.
3040

3141
OUTPUT
3242
------

builtin/check-mailmap.c

+7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
#include "write-or-die.h"
1010

1111
static int use_stdin;
12+
static const char *mailmap_file, *mailmap_blob;
1213
static const char * const check_mailmap_usage[] = {
1314
N_("git check-mailmap [<options>] <contact>..."),
1415
NULL
1516
};
1617

1718
static const struct option check_mailmap_options[] = {
1819
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")),
1922
OPT_END()
2023
};
2124

@@ -56,6 +59,10 @@ int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
5659
die(_("no contacts specified"));
5760

5861
read_mailmap(&mailmap);
62+
if (mailmap_blob)
63+
read_mailmap_blob(&mailmap, mailmap_blob);
64+
if (mailmap_file)
65+
read_mailmap_file(&mailmap, mailmap_file, 0);
5966

6067
for (i = 0; i < argc; ++i)
6168
check_mailmap(&mailmap, argv[i]);

mailmap.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,8 @@ static void read_mailmap_line(struct string_list *map, char *buffer)
142142
add_mapping(map, name1, email1, name2, email2);
143143
}
144144

145-
/* Flags for read_mailmap_file() */
146-
#define MAILMAP_NOFOLLOW (1<<0)
147-
148-
static int read_mailmap_file(struct string_list *map, const char *filename,
149-
unsigned flags)
145+
int read_mailmap_file(struct string_list *map, const char *filename,
146+
unsigned flags)
150147
{
151148
char buffer[1024];
152149
FILE *f;
@@ -186,7 +183,7 @@ static void read_mailmap_string(struct string_list *map, char *buf)
186183
}
187184
}
188185

189-
static int read_mailmap_blob(struct string_list *map, const char *name)
186+
int read_mailmap_blob(struct string_list *map, const char *name)
190187
{
191188
struct object_id oid;
192189
char *buf;

mailmap.h

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ struct string_list;
66
extern char *git_mailmap_file;
77
extern char *git_mailmap_blob;
88

9+
/* Flags for read_mailmap_file() */
10+
#define MAILMAP_NOFOLLOW (1<<0)
11+
12+
int read_mailmap_file(struct string_list *map, const char *filename,
13+
unsigned flags);
14+
int read_mailmap_blob(struct string_list *map, const char *name);
15+
916
int read_mailmap(struct string_list *map);
1017
void clear_mailmap(struct string_list *map);
1118

0 commit comments

Comments
 (0)