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 <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jacob Keller committed
Aug 27, 2024 at 14:27 UTC
f54ca6ae72e32e34f2042a93f92949e3ded11a36
4 files changed
+27
-6
Documentation/git-check-mailmap.txt
+10
@@ -27,6 +27,16 @@ OPTIONS
27
Read contacts, one per line, from the standard input after exhausting
28
contacts provided on the command-line.
29
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.
40
41
OUTPUT
42
------
builtin/check-mailmap.c
+7
@@ -9,6 +9,7 @@
9
#include "write-or-die.h"
10
11
static int use_stdin;
12
+static const char *mailmap_file, *mailmap_blob;
13
static const char * const check_mailmap_usage[] = {
14
N_("git check-mailmap [<options>] <contact>..."),
15
NULL
@@ -16,6 +17,8 @@ NULL
17
18
static const struct option check_mailmap_options[] = {
19
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")),
22
OPT_END()
23
};
24
@@ -56,6 +59,10 @@ int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
59
die(_("no contacts specified"));
60
61
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);
66
67
for (i = 0; i < argc; ++i)
68
check_mailmap(&mailmap, argv[i]);
mailmap.c
+3
-6
@@ -142,11 +142,8 @@ static void read_mailmap_line(struct string_list *map, char *buffer)
142
add_mapping(map, name1, email1, name2, email2);
143
}
144
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)
147
{
148
char buffer[1024];
149
FILE *f;
@@ -186,7 +183,7 @@ static void read_mailmap_string(struct string_list *map, char *buf)
183
}
184
}
185
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)
187
{
188
struct object_id oid;
189
char *buf;
mailmap.h
+7
@@ -6,6 +6,13 @@ struct string_list;
6
extern char *git_mailmap_file;
7
extern char *git_mailmap_blob;
8
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
+
16
int read_mailmap(struct string_list *map);
17
void clear_mailmap(struct string_list *map);
18