From: Karthik Nayak <karthik.188@gmail.com>
To: Siddharth Asthana <siddharthasthana31@gmail.com>, git@vger.kernel.org
Cc: christian.couder@gmail.com, ps@pks.im, gitster@pobox.com, toon@iotcl.com
Subject: Re: [PATCH v2 1/1] cat-file: add mailmap subcommand to --batch-command
Date: Mon, 30 Mar 2026 02:44:01 -0700 [thread overview]
Message-ID: <CAOLa=ZTqk3rG21e5H5HLDCw6MWK2ndgi=4pC0ZUWn98z39SSEQ@mail.gmail.com> (raw)
In-Reply-To: <20260329082808.12609-2-siddharthasthana31@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 7486 bytes --]
Siddharth Asthana <siddharthasthana31@gmail.com> writes:
> 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 caches git-cat-file processes and it would be useful
> if --batch-command supported toggling mailmap dynamically with existing
> processes.
>
> 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.
>
> Suggested-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Siddharth Asthana <siddharthasthana31@gmail.com>
> ---
> CI: https://gitlab.com/gitlab-org/git/-/pipelines/2416081861
>
> Documentation/git-cat-file.adoc | 7 +++++
> builtin/cat-file.c | 30 ++++++++++++++++++---
> t/t4203-mailmap.sh | 48 +++++++++++++++++++++++++++++++++
> 3 files changed, 81 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/git-cat-file.adoc b/Documentation/git-cat-file.adoc
> index c139f55a16..af32e929a8 100644
> --- a/Documentation/git-cat-file.adoc
> +++ b/Documentation/git-cat-file.adoc
> @@ -174,6 +174,13 @@ flush::
> since the beginning or since the last flush was issued. When `--buffer`
> 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 <yes|no>::
> + Enable or disable mailmap for subsequent `contents` and `info`
> + commands. When `yes` is given, mailmap data is loaded from disk on
Are there any commands that the mailmap wouldn't apply to? Would it make
sense to simply say
Enable or disable mailmap for subsequent commands.
also we can s/is given//.
> + 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.
I think the first sentense here jumps directly into the the caching
mechanism on using `yes`. It's more important for users to know what
`yes` implies. So perhaps:
When `yes` mailmap data is used and disabled on `no`. The first
`yes` caches the mailmap data until the command exits.
> --
> +
>
> diff --git a/builtin/cat-file.c b/builtin/cat-file.c
> index b6f12f41d6..a53926d2bb 100644
> --- a/builtin/cat-file.c
> +++ b/builtin/cat-file.c
> @@ -54,6 +54,7 @@ static const char *force_path;
>
> static struct string_list mailmap = STRING_LIST_INIT_NODUP;
> static int use_mailmap;
> +static int mailmap_loaded;
>
Nit: should we use a 'bool' here?
So we use a variable and not simple rely on checking `mailmap.nr`
because it is possible that we do load the mailmap but there are no
entries. I assume we could rely on `maimap.cmp` being non-NULL, but
that's getting into implementation details.
> static char *replace_idents_using_mailmap(char *, size_t *);
>
> @@ -692,6 +693,24 @@ static void parse_cmd_info(struct batch_options *opt,
> batch_one_object(line, output, opt, data);
> }
>
> +static void parse_cmd_mailmap(struct batch_options *opt UNUSED,
> + const char *line,
> + struct strbuf *output UNUSED,
> + struct expand_data *data UNUSED)
> +{
> + 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);
> + }
> +}
> +
> static void dispatch_calls(struct batch_options *opt,
> struct strbuf *output,
> struct expand_data *data,
> @@ -725,9 +744,10 @@ static const struct parse_cmd {
> parse_cmd_fn_t fn;
> unsigned takes_args;
> } commands[] = {
> - { "contents", parse_cmd_contents, 1},
> - { "info", parse_cmd_info, 1},
> - { "flush", NULL, 0},
> + { "contents", parse_cmd_contents, 1 },
> + { "info", parse_cmd_info, 1 },
> + { "flush", NULL, 0 },
> + { "mailmap", parse_cmd_mailmap, 1 },
> };
>
> static void batch_objects_command(struct batch_options *opt,
> @@ -1127,8 +1147,10 @@ int cmd_cat_file(int argc,
> opt_cw = (opt == 'c' || opt == 'w');
> opt_epts = (opt == 'e' || opt == 'p' || opt == 't' || opt == 's');
>
> - if (use_mailmap)
> + if (use_mailmap) {
> read_mailmap(the_repository, &mailmap);
> + mailmap_loaded = 1;
> + }
>
The rest of the code looks good.
> switch (batch.objects_filter.choice) {
> case LOFC_DISABLED:
> diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh
> index 74b7ddccb2..f66637cd86 100755
> --- a/t/t4203-mailmap.sh
> +++ b/t/t4203-mailmap.sh
> @@ -1133,6 +1133,54 @@ test_expect_success 'git cat-file --batch-command returns correct size with --us
> test_cmp expect actual
> '
>
> +test_expect_success 'git cat-file --batch-command mailmap yes enables mailmap mid-stream' '
> + test_when_finished "rm .mailmap" &&
> + cat >.mailmap <<-\EOF &&
> + C O Mitter <committer@example.com> Orig <orig@example.com>
> + EOF
> + commit_sha=$(git rev-parse HEAD) &&
> + git cat-file commit HEAD >commit_no_mailmap.out &&
> + git cat-file --use-mailmap commit HEAD >commit_mailmap.out &&
> + size_no_mailmap=$(wc -c <commit_no_mailmap.out) &&
> + size_mailmap=$(wc -c <commit_mailmap.out) &&
> + printf "info HEAD\nmailmap yes\ninfo HEAD\n" | git cat-file --batch-command >actual &&
> + echo $commit_sha commit $size_no_mailmap >expect &&
> + echo $commit_sha commit $size_mailmap >>expect &&
> + test_cmp expect actual
> +'
> +
> +test_expect_success 'git cat-file --batch-command mailmap no disables mailmap mid-stream' '
> + test_when_finished "rm .mailmap" &&
> + cat >.mailmap <<-\EOF &&
> + C O Mitter <committer@example.com> Orig <orig@example.com>
> + EOF
> + commit_sha=$(git rev-parse HEAD) &&
> + git cat-file commit HEAD >commit_no_mailmap.out &&
> + git cat-file --use-mailmap commit HEAD >commit_mailmap.out &&
> + size_no_mailmap=$(wc -c <commit_no_mailmap.out) &&
> + size_mailmap=$(wc -c <commit_mailmap.out) &&
> + printf "mailmap yes\ninfo HEAD\nmailmap no\ninfo HEAD\n" | git cat-file --batch-command >actual &&
> + echo $commit_sha commit $size_mailmap >expect &&
> + echo $commit_sha commit $size_no_mailmap >>expect &&
> + test_cmp expect actual
> +'
> +
> +test_expect_success 'git cat-file --batch-command mailmap works in --buffer mode' '
> + test_when_finished "rm .mailmap" &&
> + cat >.mailmap <<-\EOF &&
> + C O Mitter <committer@example.com> Orig <orig@example.com>
> + EOF
> + commit_sha=$(git rev-parse HEAD) &&
> + git cat-file commit HEAD >commit_no_mailmap.out &&
> + git cat-file --use-mailmap commit HEAD >commit_mailmap.out &&
> + size_no_mailmap=$(wc -c <commit_no_mailmap.out) &&
> + size_mailmap=$(wc -c <commit_mailmap.out) &&
> + printf "mailmap yes\ninfo HEAD\nmailmap no\ninfo HEAD\nflush\n" | git cat-file --batch-command --buffer >actual &&
> + echo $commit_sha commit $size_mailmap >expect &&
> + echo $commit_sha commit $size_no_mailmap >>expect &&
> + test_cmp expect actual
> +'
Shouldn't we also add tests for how this interacts with '--mailmap' and
'--no-mailmap'?
> test_expect_success 'git cat-file --mailmap works with different author and committer' '
> test_when_finished "rm .mailmap" &&
> cat >.mailmap <<-\EOF &&
> --
> 2.51.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
next prev parent reply other threads:[~2026-03-30 9:46 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-28 20:36 [PATCH v1 1/1] cat-file: add use-mailmap/no-use-mailmap to --batch-command Siddharth Asthana
2026-03-29 0:50 ` Junio C Hamano
2026-03-29 7:25 ` Siddharth Asthana
2026-03-29 20:55 ` Junio C Hamano
2026-03-29 8:28 ` [PATCH v2 0/1] cat-file: add mailmap subcommand " Siddharth Asthana
2026-03-29 8:28 ` [PATCH v2 1/1] " Siddharth Asthana
2026-03-30 2:12 ` Junio C Hamano
2026-03-31 1:40 ` Siddharth Asthana
2026-03-31 3:41 ` Junio C Hamano
2026-03-30 9:44 ` Karthik Nayak [this message]
2026-03-31 1:42 ` Siddharth Asthana
2026-03-30 10:37 ` Patrick Steinhardt
2026-03-30 14:53 ` Junio C Hamano
2026-03-31 1:43 ` Siddharth Asthana
2026-03-31 17:11 ` Jean-Noël AVILA
2026-03-31 17:49 ` Junio C Hamano
2026-04-01 10:11 ` Jean-Noël Avila
2026-03-31 12:11 ` [PATCH v3 0/1] " Siddharth Asthana
2026-03-31 12:11 ` [PATCH v3 1/1] " Siddharth Asthana
2026-03-31 19:21 ` Junio C Hamano
2026-04-10 18:29 ` Junio C Hamano
2026-04-15 15:09 ` [PATCH v4 0/1] " Siddharth Asthana
2026-04-15 15:09 ` [PATCH v4 1/1] " Siddharth Asthana
2026-04-15 18:28 ` Junio C Hamano
2026-04-16 3:08 ` Siddharth Asthana
2026-04-16 3:32 ` [PATCH v5 0/1] " Siddharth Asthana
2026-04-16 3:32 ` [PATCH v5 1/1] " Siddharth Asthana
2026-05-20 3:26 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOLa=ZTqk3rG21e5H5HLDCw6MWK2ndgi=4pC0ZUWn98z39SSEQ@mail.gmail.com' \
--to=karthik.188@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ps@pks.im \
--cc=siddharthasthana31@gmail.com \
--cc=toon@iotcl.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).