From: Siddharth Asthana Date: Tue, 31 Mar 2026 12:11:10 GMT Subject: [PATCH v3 0/1] cat-file: add mailmap subcommand to --batch-command Message-ID: <20260331121111.9614-1-siddharthasthana31@gmail.com> In-Reply-To: <20260329082808.12609-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/2419600519 Changes in v3: - Use "keeps interacting with a long-lived git-cat-file process" wording in the commit message and cover letter. - Drop the `Suggested-by` trailer. - Avoid style-only churn in the `commands[]` table by keeping existing initializer style and only adding the new command entry. - Introduce a `load_mailmap()` helper used by both startup and `parse_cmd_mailmap()`. - Parse `mailmap ` using `git_parse_maybe_bool()` instead of handling only `yes`/`no`. - Update docs to describe `mailmap ` and reference Git's boolean syntax from `git-config(1)`. - Add tests for startup option interaction (`--mailmap`/`--no-mailmap`), accepted boolean values (`true`/`false`), and invalid boolean input. - Link to v2: https://public-inbox.org/git/20260329082804.53400-1-siddharthasthana31@gmail.com/ - 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 | 7 +++ builtin/cat-file.c | 32 ++++++++++-- t/t4203-mailmap.sh | 105 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 4 deletions(-) Range-diff versus v2: 1: 936ca27419 ! 1: df446d7ca3 cat-file: add mailmap subcommand to --batch-command @@ Commit message but this option needs to be set when the process is created. This means we cannot change this option mid-operation. - At GitLab, Gitaly caches git-cat-file processes and it would be useful - if --batch-command supported toggling mailmap dynamically with existing - processes. + 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. - Add a `mailmap` subcommand to --batch-command that takes a single - argument: `yes` to enable mailmap and `no` to disable it. When enabled, - mailmap data is loaded from disk on first use and kept in memory so that - toggling back on does not require reloading. + 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. + + Extend tests to cover runtime toggling, startup option interactions + (`--mailmap`/`--no-mailmap`), accepted boolean forms, and invalid values. - Suggested-by: Junio C Hamano Signed-off-by: Siddharth Asthana ## Documentation/git-cat-file.adoc ## @@ 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 :: -+ Enable or disable mailmap for subsequent `contents` and `info` -+ commands. When `yes` is given, mailmap data is loaded from disk on -+ first use and kept in memory; passing `yes` again does not reload it. -+ When `no` is given, mailmap is disabled but the data stays in memory -+ so that a later `mailmap yes` does not need to reload it from disk. ++mailmap :: ++ Enable or disable mailmap for subsequent commands. +++ ++The `` 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. -- ## builtin/cat-file.c ## +@@ builtin/cat-file.c: static int use_mailmap; + +static void load_mailmap(void) +{ + if (mailmap.strdup_strings) + return; + + read_mailmap(the_repository, &mailmap); +} + @@ builtin/cat-file.c: static void parse_cmd_info(struct batch_options *opt, batch_one_object(line, output, opt, data); } @@ builtin/cat-file.c: static void parse_cmd_info(struct batch_options *opt, +{ -+ if (!strcmp(line, "yes")) { -+ if (!mailmap_loaded) { -+ read_mailmap(the_repository, &mailmap); -+ mailmap_loaded = 1; -+ } -+ use_mailmap = 1; -+ } else if (!strcmp(line, "no")) { -+ use_mailmap = 0; -+ } else { -+ die(_("mailmap: unknown argument '%s', expected 'yes' or 'no'"), line); -+ } ++ int value = git_parse_maybe_bool(line); ++ ++ if (value < 0) ++ die(_("mailmap: invalid boolean '%s'"), line); ++ ++ if (value > 0) ++ load_mailmap(); ++ use_mailmap = value; +} + @@ builtin/cat-file.c: static const struct parse_cmd { -+ { "use-mailmap", parse_cmd_use_mailmap, 0 }, -+ { "no-use-mailmap", parse_cmd_disable_mailmap, 0 }, ++ { "mailmap", parse_cmd_mailmap, 1 }, +}; @@ builtin/cat-file.c: int cmd_cat_file(int argc, if (use_mailmap) -+ read_mailmap(the_repository, &mailmap); ++ load_mailmap(); base-commit: 5361983c075154725be47b65cca9a2421789e410 -- 2.53.0