]> git.ipfire.org Git - thirdparty/git.git/commitdiff
check-mailmap: add options for additional mailmap sources
authorJacob Keller <jacob.keller@gmail.com>
Tue, 27 Aug 2024 21:27:17 +0000 (14:27 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Aug 2024 21:51:29 +0000 (14:51 -0700)
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>
Documentation/git-check-mailmap.txt
builtin/check-mailmap.c
mailmap.c
mailmap.h

index 7747e38e25e3ca675cee0ac417592fe006e19d79..966c91c46af7d30d88f780c44eb0d8c590251087 100644 (file)
@@ -27,6 +27,16 @@ OPTIONS
        Read contacts, one per line, from the standard input after exhausting
        contacts provided on the command-line.
 
+--mailmap-file=<file>::
+       In addition to any configured mailmap files, read the specified
+       mailmap file. Entries in this file take precedence over entries in
+       either the default mailmap file or any configured mailmap file.
+
+--mailmap-blob=<blob>::
+       Like `--mailmap-file`, but consider the value as a reference to a
+       blob in the repository. If both `--mailmap-file` and
+       `--mailmap-blob` are specified, entries in `--mailmap-file` will
+       take precedence.
 
 OUTPUT
 ------
index 6b7fb53494f0cb2715b56dfbf77435d58fec4217..2334b5722275cc25ba5697c4dc84c3d40bea2246 100644 (file)
@@ -9,6 +9,7 @@
 #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
@@ -16,6 +17,8 @@ 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()
 };
 
@@ -56,6 +59,10 @@ int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
                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]);
index 2d0212f4441d5d1f8e464fbc542d596902953543..4212e553e77e0ef8663bf1de0fd6817c10f36797 100644 (file)
--- a/mailmap.c
+++ b/mailmap.c
@@ -142,11 +142,8 @@ static void read_mailmap_line(struct string_list *map, char *buffer)
                add_mapping(map, name1, email1, name2, email2);
 }
 
-/* Flags for read_mailmap_file() */
-#define MAILMAP_NOFOLLOW (1<<0)
-
-static int read_mailmap_file(struct string_list *map, const char *filename,
-                            unsigned flags)
+int read_mailmap_file(struct string_list *map, const char *filename,
+                     unsigned flags)
 {
        char buffer[1024];
        FILE *f;
@@ -186,7 +183,7 @@ static void read_mailmap_string(struct string_list *map, char *buf)
        }
 }
 
-static int read_mailmap_blob(struct string_list *map, const char *name)
+int read_mailmap_blob(struct string_list *map, const char *name)
 {
        struct object_id oid;
        char *buf;
index cbda9bc5e0c18544316448c637891fc5597db4ef..908365e1bffafc6a8acaffd891d69a292fa78ad2 100644 (file)
--- a/mailmap.h
+++ b/mailmap.h
@@ -6,6 +6,13 @@ struct string_list;
 extern char *git_mailmap_file;
 extern char *git_mailmap_blob;
 
+/* Flags for read_mailmap_file() */
+#define MAILMAP_NOFOLLOW (1<<0)
+
+int read_mailmap_file(struct string_list *map, const char *filename,
+                     unsigned flags);
+int read_mailmap_blob(struct string_list *map, const char *name);
+
 int read_mailmap(struct string_list *map);
 void clear_mailmap(struct string_list *map);