Git development
 help / color / mirror / Atom feed
From: Siddharth Asthana <siddharthasthana31@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, karthik.188@gmail.com,
	christian.couder@gmail.com, ps@pks.im, toon@iotcl.com
Subject: Re: [PATCH v2 1/1] cat-file: add mailmap subcommand to --batch-command
Date: Tue, 31 Mar 2026 07:10:35 +0530	[thread overview]
Message-ID: <72543649-7994-4220-86fb-e3c84faf0b6a@gmail.com> (raw)
In-Reply-To: <xmqqtstyf4lj.fsf@gitster.g>



On 30/03/26 07:42, Junio C Hamano wrote:
> 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
> 
> Would "keeps interacting with a single 'cat-file' process" be more
> accurate than "caches"?  The latter gives, at least to me,


Thanks Junio

Make sense, I will update that wording in v3!


> connotations that may not be necessarily true, like (1) there is a
> pool of cat-file processes waiting for Gitaly to connect and serve,
> (2) a running Gitaly may decide to disconnect from cat-file from
> time to time, and then reconnect to one of them when it becomes
> necessary again, etc.
> 
>> 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>
> 
> This is over-crediting me.  The idea to unify the two commands into
> one may have come from me, but that is at most helped-by but it is
> perfectly fine without any credit.


Got it, thanks for pointing that out.


> 
>> Signed-off-by: Siddharth Asthana <siddharthasthana31@gmail.com>
>> ---
> 
>> 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;
> 
> Not part of this topic, but in case less experienced developers who
> are watching from the sidelines wonder if we want to add this
> file-scope global variable, this is perfectly fine.  Anything under
> builtin/foo.c are meant to serve a single command "git foo" and does
> not benefit from "let's sift globals into classes that belong to
> different concepts in the system; most of which will be per
> repository, so make them some part of the repository object"
> movement as much as more library-ish parts of the system.
> 
> Until a specific command starts working on multiple repositories at
> one time, that is.
> 
> 
>> @@ -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);
>> +	}
>> +}
> 
> OK.
> 
>> @@ -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 },
>>   };
> 
> Mixing style fixes to existing entries in the same patch that adds a
> new feature by adding a new entry to the table is annoying than
> having a preliminary clean-up patch that only fixes style and then
> the main patch that adds the feature.


Agreed. I will avoid mixing style-only cleanup with the feature change 
in v3.


> 
>>   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;
>> +	}
> 
> Hmph, interesting.  Two points.
> 
>   * It would make it easier to follow if these two lines are made
>     into a small helper function to be called from here and from the
>     "parse_cmd_mailmap()"?
> 
>   * Can we somehow make mailmap object itself slightly smarter so
>     that it knows if it has already been asked to read the data from
>     its sources?  It is a pretty dumb string_list, but from a cursory
>     read of the code flow, it seems that mailmap.strdup_strings is
>     initialized to be false in builtin/cat-file.c and then one of the
>     first things done in mailmap.c::read_mailmap() is to flip that
>     bit on, so the "yes" part of the parse_cmd_mailmap() might become
> 
> 	if (yes)
> 		load_mailmap();
> 
>     with the helper load_mailmap() that may look like:
> 
> 	static void load_mailmap(void)
> 	{
> 		if (mailmap.strdup_strings)
> 			return; /* we know read_mailmap() flips it on */
> 		read_mailmap(the_repository, &mailmap);
> 	}
> 
>     The first bullet point to introduce a small common helper will
>     help hiding such an ugly implementation detail there.


Thanks, this is helpful.

I will introduce a small helper and call it from both places so the flow 
is easier to follow. I will also avoid publicating the load check in 
each callsite

  reply	other threads:[~2026-03-31  1:40 UTC|newest]

Thread overview: 27+ 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 [this message]
2026-03-31  3:41         ` Junio C Hamano
2026-03-30  9:44     ` Karthik Nayak
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

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=72543649-7994-4220-86fb-e3c84faf0b6a@gmail.com \
    --to=siddharthasthana31@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karthik.188@gmail.com \
    --cc=ps@pks.im \
    --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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox