Subject: Re: [PATCH 6/9] rev-parse: allow printing compatibility hash

From: Junio C Hamano <[email-masked]>
Date: Fri, 19 Sep 2025 16:24:50 -0700

"brian m. carlson" <[email-masked]> writes:

> Right now, we have a way to print the storage hash, the input hash, and
> the output hash, but we lack a way to print the compatibility hash.  Add
> a new type to --show-object-format, compat, which prints this value.
>
> If no compatibility hash exists, simply print a newline.  This is
> important to allow users to use multiple options at once while still
> getting unambiguous output.
>
> Signed-off-by: brian m. carlson <[email-masked]>
> ---

Nice.

At first I somehow thought 

    $ git rev-parse --show-object-format=compat HEAD

in a SHA-1 primary repository would give the equivalent object name
for the commit at HEAD in SHA-256 world, but that is expecting too
much out of a simple 50-line patch ;-).

>  
>  				if (strcmp(val, "storage") &&
> +				    strcmp(val, "compat") &&
>  				    strcmp(val, "input") &&
>  				    strcmp(val, "output"))
>  					die(_("unknown mode for --show-object-format: %s"),
>  					    arg);
> -				puts(the_hash_algo->name);
> +
> +				if (!strcmp(val, "compat")) {
> +					if (the_repository->compat_hash_algo)
> +						puts(the_repository->compat_hash_algo->name);
> +					else
> +						putchar('\n');
> +				} else {
> +					puts(the_hash_algo->name);
> +				}
>  				continue;
>  			}
>  			if (!strcmp(arg, "--show-ref-format")) {

Pretty straight-forward.

Thanks.