[PATCH v4 0/1] cat-file: add mailmap subcommand to --batch-command
- From
Siddharth Asthana <siddharthasthana31@gmail.com>
- Date
- Apr 15, 2026, 15:09 UTC
- Message-ID
- <20260415150943.40493-1-siddharthasthana31@gmail.com>
- In-Reply-To
- <20260331121111.9614-1-siddharthasthana31@gmail.com>
git-cat-file(1)'s --batch-command works with the --use-mailmap option, but this option needs to be set when the process is created. This means we cannot change this option mid-operation.
At GitLab, Gitaly keeps interacting with a long-lived git-cat-file process and it would be useful if --batch-command supported toggling mailmap dynamically on an existing process.
This patch adds a `mailmap` subcommand to --batch-command that accepts a boolean argument and toggles mailmap dynamically for subsequent commands.
The series is based on top of 5361983c07 (The 22nd batch, 2026-03-21).
CI: https://gitlab.com/gitlab-org/git/-/pipelines/2455043368
Changes in v4: - Reword commit message: describe boolean support without mentioning internal function names, following Junio's suggestion. - Add an in-code comment explaining why `mailmap.strdup_strings` can be used as the "already loaded" check in `load_mailmap()`. - Drop local `value` variable in `parse_cmd_mailmap()` and assign directly to `use_mailmap`. - Fix documentation syntax: place the closing backtick before `::` and break the description into a `;;` sub-list for `true`/`false` effects. - Link to v3: https://lore.kernel.org/git/xmqqv7dyoei6.fsf@gitster.g/T/#m0a109f3eb5129e619ecec5f2d58ead0c5a49a4f3 - Link to v2: https://lore.kernel.org/git/xmqqv7dyoei6.fsf@gitster.g/T/#m445eab3b309bded92d1b130d225b882c73988ff2 - Link to v1: https://public-inbox.org/git/a4ec7bfa-f16b-4505-9b37-d3dd137e93cb@gmail.com/T/#m5c62fb6ad0fbcc99a706dba4c78b66359c247acd
Thanks, Siddharth
--- Siddharth Asthana (1): cat-file: add mailmap subcommand to --batch-command
Documentation/git-cat-file.adoc | 12 +++++ builtin/cat-file.c | 37 ++++++++++++-- t/t4203-mailmap.sh | 105 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 4 deletions(-)
Range-diff versus v3:
1: dbc1a003a5 ! 1: 25ebffe39e cat-file: add mailmap subcommand to --batch-command
@@ Commit message
mailmap dynamically on an existing process.
Add a `mailmap` subcommand to --batch-command that takes a boolean
- argument. The command now uses `git_parse_maybe_bool()` and supports all
- standard Git boolean values. Mailmap data is loaded lazily and kept in
- memory, while a helper centralizes the one-time load path used both at
- startup and from the batch-command handler.
+ argument (usual ways you can specify a boolean value like 'yes', 'true',
+ etc., are supported). Mailmap data is loaded lazily and kept in memory,
+ while a helper centralizes the one-time load path used both at startup
+ and from the batch-command handler.
Extend tests to cover runtime toggling, startup option interactions
(`--mailmap`/`--no-mailmap`), accepted boolean forms, and invalid values.
@@ Documentation/git-cat-file.adoc: flush::
is used, no output will come until a `flush` is issued. When `--buffer`
is not used, commands are flushed each time without issuing `flush`.
+
-+mailmap <bool>::
-+ Enable or disable mailmap for subsequent commands.
++`mailmap (<bool>)`::
++ Enable or disable mailmap for subsequent commands. The `<bool>`
++ argument accepts the same boolean values as linkgit:git-config[1].
++ Possible effects are:
++
-+The `<bool>` argument accepts the same boolean values as
-+linkgit:git-config[1]. When enabled, mailmap data is loaded on first
-+use and kept in memory until the process exits.
++`true`;;
++ Mailmap data is loaded on first use and kept in memory until the
++ process exits. Passing `true` again does not reload the data.
++`false`;;
++ Mailmap replacements are disabled for subsequent commands, but data
++ already loaded stays in memory.
--
+
@@ builtin/cat-file.c: static int use_mailmap;
static char *replace_idents_using_mailmap(char *, size_t *);
++/*
++ * The mailmap is initialized with .strdup_strings set to 0,
++ * but read_mailmap() sets the bit to 1 (this is true even when
++ * not a single mailmap entry is read), so it can be used for
++ * lazy loading.
++ */
+static void load_mailmap(void)
+{
+ if (mailmap.strdup_strings)
@@ builtin/cat-file.c: static void parse_cmd_info(struct batch_options *opt,
+ struct strbuf *output UNUSED,
+ struct expand_data *data UNUSED)
+{
-+ int value = git_parse_maybe_bool(line);
++ use_mailmap = git_parse_maybe_bool(line);
+
-+ if (value < 0)
++ if (use_mailmap < 0)
+ die(_("mailmap: invalid boolean '%s'"), line);
+
-+ if (value > 0)
++ if (use_mailmap)
+ load_mailmap();
-+ use_mailmap = value;
+}
+
static void dispatch_calls(struct batch_options *opt,base-commit: 5361983c075154725be47b65cca9a2421789e410
-- 2.53.0