threads / patch / 63995

patch, 2 partsrepo: add -z and objects.format

Subject: [GSoC PATCH 0/2] repo: add -z and objects.format

## tl;dr

37 messages between Aug 20, 2025 and Sep 4, 2025. Diffs are folded; open one to read it.

replies: 36people: 5as markdown or json

Lucas Seiki Oshiro· Aug 20, 2025, 14:42 UTC · lore
Hi!

This patchset adds two features to `git repo info`. They are unrelated, but I preferred to send them together to avoid merge conflicts and because they are small.

- The first patch adds the `-z` as an alias for `--format=null`, as
  requested in [1]
- The second patch adds `objects.format`, which retrieves the same value
  as `git rev-parse --show-object-format`
  
Thanks!
[1] https://lore.kernel.org/git/mgdervgp34m6ipfbodsfn7cztcl7gdeggzemfgivzvuyk7qtba@wdijebkuioxg/
Lucas Seiki Oshiro (2):
  repo: add the flag -z as an alias for --format=nul
  repo: add the field objects.format
 Documentation/git-repo.adoc |  9 +++++++--
 builtin/repo.c              | 24 +++++++++++++++++++-----
 t/t1900-repo.sh             | 18 ++++++++++++++++++
 3 files changed, 44 insertions(+), 7 deletions(-)
-- 
2.39.5 (Apple Git-154)
Lucas Seiki Oshiro· Aug 20, 2025, 14:42 UTC · re: Lucas Seiki Oshiro · lore

[GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

Other Git commands that have nul-terminated output (e.g. git-config, git-status, git-ls-files) have a flag `-z` for using the null character as the record separator.

Add the `-z` flag to git-repo-info as an alias for `--format=nul`, making it consistent with the behavior of the other commands.

Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 Documentation/git-repo.adoc |  6 ++++--
 builtin/repo.c              | 17 ++++++++++++-----
 t/t1900-repo.sh             | 12 ++++++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)
Show changes to 3 files +28 −7

Documentation/git-repo.adoc, builtin/repo.c, t/t1900-repo.sh

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 2870828d93..f2dc71193c 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
 SYNOPSIS
 --------
 [synopsis]
-git repo info [--format=(keyvalue|nul)] [<key>...]
+git repo info [--format=(keyvalue|nul)|-z] [<key>...]
 
 DESCRIPTION
 -----------
@@ -18,7 +18,7 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
 
 COMMANDS
 --------
-`info [--format=(keyvalue|nul)] [<key>...]`::
+`info [--format=(keyvalue|nul)|-z] [<key>...]`::
 	Retrieve metadata-related information about the current repository. Only
 	the requested data will be returned based on their keys (see "INFO KEYS"
 	section below).
@@ -40,6 +40,8 @@ supported:
 	between the key and the value and using a NUL character after each value.
 	This format is better suited for being parsed by another applications than
 	`keyvalue`. Unlike in the `keyvalue` format, the values are never quoted.
++
+`-z` is an alias for `--format=nul`.
 
 INFO KEYS
 ---------
diff --git a/builtin/repo.c b/builtin/repo.c
index 8c6e7f42ab..b2ec66e454 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -9,7 +9,7 @@
 #include "shallow.h"
 
 static const char *const repo_usage[] = {
-	"git repo info [--format=(keyvalue|nul)] [<key>...]",
+	"git repo info [--format=(keyvalue|nul)|-z] [<key>...]",
 	NULL
 };
 
@@ -115,20 +115,27 @@ static int print_fields(int argc, const char **argv,
 static int repo_info(int argc, const char **argv, const char *prefix,
 		     struct repository *repo)
 {
-	const char *format_str = "keyvalue";
+	const char *format_str = NULL;
 	enum output_format format;
+	int format_nul = 0;
 	struct option options[] = {
 		OPT_STRING(0, "format", &format_str, N_("format"),
 			   N_("output format")),
+		OPT_BOOL('z', NULL, &format_nul, N_("alias for --format=nul")),
 		OPT_END()
 	};
 
 	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
 
-	if (!strcmp(format_str, "keyvalue"))
-		format = FORMAT_KEYVALUE;
-	else if (!strcmp(format_str, "nul"))
+	die_for_incompatible_opt2(!!format_nul, "-z",
+				  !!format_str, "--format");
+
+	format_str = format_str ? format_str : "keyvalue";
+
+	if (format_nul || !strcmp(format_str, "nul"))
 		format = FORMAT_NUL_TERMINATED;
+	else if (!strcmp(format_str, "keyvalue"))
+		format = FORMAT_KEYVALUE;
 	else
 		die(_("invalid format '%s'"), format_str);
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index a69c715357..3df55dcc79 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -92,4 +92,16 @@ test_expect_success 'git-repo-info aborts when requesting an invalid format' '
 	test_cmp expect actual
 '
 
+test_expect_success '-z uses nul-terminated format' '
+	printf "layout.bare\nfalse\0layout.shallow\nfalse\0" >expected &&
+	git repo info -z layout.bare layout.shallow >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'git repo info fails when using --format and -z' '
+	echo "fatal: options ${SQ}-z${SQ} and ${SQ}--format${SQ} cannot be used together" >expected &&
+	test_must_fail git repo info -z --format=keyvalue 2>actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.39.5 (Apple Git-154)
Karthik Nayak· Aug 21, 2025, 10:12 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
Show 27 quoted lines
> Other Git commands that have nul-terminated output (e.g. git-config,
> git-status, git-ls-files) have a flag `-z` for using the null character
> as the record separator.
>
> Add the `-z` flag to git-repo-info as an alias for `--format=nul`,
> making it consistent with the behavior of the other commands.
>
> Mentored-by: Karthik Nayak <karthik.188@gmail.com>
> Mentored-by: Patrick Steinhardt <ps@pks.im>
> Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
> ---
>  Documentation/git-repo.adoc |  6 ++++--
>  builtin/repo.c              | 17 ++++++++++++-----
>  t/t1900-repo.sh             | 12 ++++++++++++
>  3 files changed, 28 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> index 2870828d93..f2dc71193c 100644
> --- a/Documentation/git-repo.adoc
> +++ b/Documentation/git-repo.adoc
> @@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
>  SYNOPSIS
>  --------
>  [synopsis]
> -git repo info [--format=(keyvalue|nul)] [<key>...]
> +git repo info [--format=(keyvalue|nul)|-z] [<key>...]
>
Nit: Perhaps we can leave a space around '|' to make it easier to read?
Show 88 quoted lines
>  DESCRIPTION
>  -----------
> @@ -18,7 +18,7 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
>
>  COMMANDS
>  --------
> -`info [--format=(keyvalue|nul)] [<key>...]`::
> +`info [--format=(keyvalue|nul)|-z] [<key>...]`::
>  	Retrieve metadata-related information about the current repository. Only
>  	the requested data will be returned based on their keys (see "INFO KEYS"
>  	section below).
> @@ -40,6 +40,8 @@ supported:
>  	between the key and the value and using a NUL character after each value.
>  	This format is better suited for being parsed by another applications than
>  	`keyvalue`. Unlike in the `keyvalue` format, the values are never quoted.
> ++
> +`-z` is an alias for `--format=nul`.
>
>  INFO KEYS
>  ---------
> diff --git a/builtin/repo.c b/builtin/repo.c
> index 8c6e7f42ab..b2ec66e454 100644
> --- a/builtin/repo.c
> +++ b/builtin/repo.c
> @@ -9,7 +9,7 @@
>  #include "shallow.h"
>
>  static const char *const repo_usage[] = {
> -	"git repo info [--format=(keyvalue|nul)] [<key>...]",
> +	"git repo info [--format=(keyvalue|nul)|-z] [<key>...]",
>  	NULL
>  };
>
> @@ -115,20 +115,27 @@ static int print_fields(int argc, const char **argv,
>  static int repo_info(int argc, const char **argv, const char *prefix,
>  		     struct repository *repo)
>  {
> -	const char *format_str = "keyvalue";
> +	const char *format_str = NULL;
>  	enum output_format format;
> +	int format_nul = 0;
>  	struct option options[] = {
>  		OPT_STRING(0, "format", &format_str, N_("format"),
>  			   N_("output format")),
> +		OPT_BOOL('z', NULL, &format_nul, N_("alias for --format=nul")),
>  		OPT_END()
>  	};
>
>  	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
>
> -	if (!strcmp(format_str, "keyvalue"))
> -		format = FORMAT_KEYVALUE;
> -	else if (!strcmp(format_str, "nul"))
> +	die_for_incompatible_opt2(!!format_nul, "-z",
> +				  !!format_str, "--format");
> +
> +	format_str = format_str ? format_str : "keyvalue";
> +
> +	if (format_nul || !strcmp(format_str, "nul"))
>  		format = FORMAT_NUL_TERMINATED;
> +	else if (!strcmp(format_str, "keyvalue"))
> +		format = FORMAT_KEYVALUE;
>  	else
>  		die(_("invalid format '%s'"), format_str);
>
> diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
> index a69c715357..3df55dcc79 100755
> --- a/t/t1900-repo.sh
> +++ b/t/t1900-repo.sh
> @@ -92,4 +92,16 @@ test_expect_success 'git-repo-info aborts when requesting an invalid format' '
>  	test_cmp expect actual
>  '
>
> +test_expect_success '-z uses nul-terminated format' '
> +	printf "layout.bare\nfalse\0layout.shallow\nfalse\0" >expected &&
> +	git repo info -z layout.bare layout.shallow >actual &&
> +	test_cmp expected actual
> +'
> +
> +test_expect_success 'git repo info fails when using --format and -z' '
> +	echo "fatal: options ${SQ}-z${SQ} and ${SQ}--format${SQ} cannot be used together" >expected &&
> +	test_must_fail git repo info -z --format=keyvalue 2>actual &&
> +	test_cmp expected actual
> +'
> +
>  test_done
> --
> 2.39.5 (Apple Git-154)
The rest looks good.
Junio C Hamano· Aug 21, 2025, 16:09 UTC · re: Karthik Nayak · lore

Re: [GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

Karthik Nayak <karthik.188@gmail.com> writes:
Show 5 quoted lines
>> -git repo info [--format=(keyvalue|nul)] [<key>...]
>> +git repo info [--format=(keyvalue|nul)|-z] [<key>...]
>>
>
> Nit: Perhaps we can leave a space around '|' to make it easier to read?

Documentation/CodingGuidelines (Synopsis Syntax) has explicit guidelines about these things.

     Don't use spacing around "|" tokens when they're used to separate the
     alternate arguments of an option:
        Do: --track[=(direct|inherit)]
        Don't: --track[=(direct | inherit)]
Karthik Nayak· Aug 21, 2025, 16:52 UTC · re: Junio C Hamano · lore

Re: [GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

On Thu, Aug 21, 2025 at 6:09 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 17 quoted lines
>
> Karthik Nayak <karthik.188@gmail.com> writes:
>
> >> -git repo info [--format=(keyvalue|nul)] [<key>...]
> >> +git repo info [--format=(keyvalue|nul)|-z] [<key>...]
> >>
> >
> > Nit: Perhaps we can leave a space around '|' to make it easier to read?
>
> Documentation/CodingGuidelines (Synopsis Syntax) has explicit
> guidelines about these things.
>
>      Don't use spacing around "|" tokens when they're used to separate the
>      alternate arguments of an option:
>         Do: --track[=(direct|inherit)]
>         Don't: --track[=(direct | inherit)]
>
I stand corrected, thanks!
Patrick Steinhardt· Aug 21, 2025, 10:29 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

On Wed, Aug 20, 2025 at 11:42:46AM -0300, Lucas Seiki Oshiro wrote:
Show 6 quoted lines
> Other Git commands that have nul-terminated output (e.g. git-config,
> git-status, git-ls-files) have a flag `-z` for using the null character
> as the record separator.
> 
> Add the `-z` flag to git-repo-info as an alias for `--format=nul`,
> making it consistent with the behavior of the other commands.
Yeah, it's common indeed to have `-z` for nul-terminated output.
Show 10 quoted lines
> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> index 2870828d93..f2dc71193c 100644
> --- a/Documentation/git-repo.adoc
> +++ b/Documentation/git-repo.adoc
> @@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
>  SYNOPSIS
>  --------
>  [synopsis]
> -git repo info [--format=(keyvalue|nul)] [<key>...]
> +git repo info [--format=(keyvalue|nul)|-z] [<key>...]
Not a 100% sure, but I think this would actually need to be formatted as
    [(--format=(keyvalue|nul)|-z)]

Looks a bit ugly though, so maybe the existent version is good enough? Others may have a more informed opinion.

Show 26 quoted lines
> diff --git a/builtin/repo.c b/builtin/repo.c
> index 8c6e7f42ab..b2ec66e454 100644
> --- a/builtin/repo.c
> +++ b/builtin/repo.c
> @@ -115,20 +115,27 @@ static int print_fields(int argc, const char **argv,
>  static int repo_info(int argc, const char **argv, const char *prefix,
>  		     struct repository *repo)
>  {
> -	const char *format_str = "keyvalue";
> +	const char *format_str = NULL;
>  	enum output_format format;
> +	int format_nul = 0;
>  	struct option options[] = {
>  		OPT_STRING(0, "format", &format_str, N_("format"),
>  			   N_("output format")),
> +		OPT_BOOL('z', NULL, &format_nul, N_("alias for --format=nul")),
>  		OPT_END()
>  	};
>  
>  	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
>  
> -	if (!strcmp(format_str, "keyvalue"))
> -		format = FORMAT_KEYVALUE;
> -	else if (!strcmp(format_str, "nul"))
> +	die_for_incompatible_opt2(!!format_nul, "-z",
> +				  !!format_str, "--format");
Makes sense, we only want one of "--format=" or "-z".
Show 9 quoted lines
> +	format_str = format_str ? format_str : "keyvalue";
> +
> +	if (format_nul || !strcmp(format_str, "nul"))
>  		format = FORMAT_NUL_TERMINATED;
> +	else if (!strcmp(format_str, "keyvalue"))
> +		format = FORMAT_KEYVALUE;
>  	else
>  		die(_("invalid format '%s'"), format_str);
>  
And here we then determine which format was picked. Looks reasonable.
Patrick
Lucas Seiki Oshiro· Aug 21, 2025, 13:29 UTC · re: Patrick Steinhardt · lore

Re: [GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

Show 6 quoted lines
> Not a 100% sure, but I think this would actually need to be formatted as
> 
>    [(--format=(keyvalue|nul)|-z)]
> 
> Looks a bit ugly though, so maybe the existent version is good enough?
> Others may have a more informed opinion.

I couldn't find other usage strings following that syntax in Git (I tried `git grep '\[[(].*|.*[)]\]' -- 'Documentation/git-*.adoc'`).

But I don't have any strong opinion about that. I'm open to suggestions.
Thanks!
Junio C Hamano· Aug 21, 2025, 17:28 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
> But I don't have any strong opinion about that. I'm open to suggestions.

Don't ask for suggestions before consulting CodingGuidelines, perhaps?

Lucas Seiki Oshiro· Aug 21, 2025, 20:57 UTC · re: Junio C Hamano · lore

Re: [GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

>> But I don't have any strong opinion about that. I'm open to suggestions.
> 
> Don't ask for suggestions before consulting CodingGuidelines,
> perhaps?

I think that Patrick was unsure about adding the external parentheses to make it look like [(--format=(keyvalue|nul) | -z)]. CodingGuideLines is not explicit about that specific case of having alternate flags with nested alternate arguments, but I don't see a reason for using parentheses as it isn't ambiguous...

Junio C Hamano· Aug 21, 2025, 21:50 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
Show 10 quoted lines
>>> But I don't have any strong opinion about that. I'm open to suggestions.
>> 
>> Don't ask for suggestions before consulting CodingGuidelines,
>> perhaps?
>
> I think that Patrick was unsure about adding the external parentheses
> to make it look like [(--format=(keyvalue|nul) | -z)]. CodingGuideLines
> is not explicit about that specific case of having alternate flags
> with nested alternate arguments, but I don't see a reason for using
> parentheses as it isn't ambiguous...
 Parentheses are used for grouping:
   [(<rev>|<range>)...]
   (Any number of either <rev> or <range>.  Parens are needed to make
   it clear that "..." pertains to both <rev> and <range>.)
   [(-p <parent>)...]
   (Any number of option -p, each with one <parent> argument.)

If we were saying that these things can occur multiple times, it may benefit from such a grouping by doing

    [(--format=(keyvalue|nul) | -z)...]
But the outer () without these extra things, i.e.
    [(--format=(keyvalue|nul) | -z)]
does not look like serving any useful purpose at all to me...
Jean-Noël AVILA· Aug 21, 2025, 18:23 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

On Wednesday, 20 August 2025 16:42:46 CEST Lucas Seiki Oshiro wrote:
Show 27 quoted lines
> Other Git commands that have nul-terminated output (e.g. git-config,
> git-status, git-ls-files) have a flag `-z` for using the null character
> as the record separator.
> 
> Add the `-z` flag to git-repo-info as an alias for `--format=nul`,
> making it consistent with the behavior of the other commands.
> 
> Mentored-by: Karthik Nayak <karthik.188@gmail.com>
> Mentored-by: Patrick Steinhardt <ps@pks.im>
> Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
> ---
>  Documentation/git-repo.adoc |  6 ++++--
>  builtin/repo.c              | 17 ++++++++++++-----
>  t/t1900-repo.sh             | 12 ++++++++++++
>  3 files changed, 28 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> index 2870828d93..f2dc71193c 100644
> --- a/Documentation/git-repo.adoc
> +++ b/Documentation/git-repo.adoc
> @@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
>  SYNOPSIS
>  --------
>  [synopsis]
> -git repo info [--format=(keyvalue|nul)] [<key>...]
> +git repo info [--format=(keyvalue|nul)|-z] [<key>...]
> 
In fact the correct formatting is:
[--format=(keyvalue|nul) | -z] [<key>...]
As stated in "CodingGuidelines:
 Use spacing around "|" token(s), but not immediately after opening or
 before closing a [] or () pair:
   Do: [-q | --quiet]
   Don't: [-q|--quiet]
 Don't use spacing around "|" tokens when they're used to separate the
 alternate arguments of an option:
    Do: --track[=(direct|inherit)]
    Don't: --track[=(direct | inherit)]
Junio C Hamano· Aug 21, 2025, 19:52 UTC · re: Jean-Noël AVILA · lore

Re: [GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

Jean-Noël AVILA <jn.avila@free.fr> writes:
Show 19 quoted lines
>> -git repo info [--format=(keyvalue|nul)] [<key>...]
>> +git repo info [--format=(keyvalue|nul)|-z] [<key>...]
>> 
>
> In fact the correct formatting is:
>
> [--format=(keyvalue|nul) | -z] [<key>...]
>
> As stated in "CodingGuidelines:
>
>  Use spacing around "|" token(s), but not immediately after opening or
>  before closing a [] or () pair:
>    Do: [-q | --quiet]
>    Don't: [-q|--quiet]
>
>  Don't use spacing around "|" tokens when they're used to separate the
>  alternate arguments of an option:
>     Do: --track[=(direct|inherit)]
>     Don't: --track[=(direct | inherit)]
Yup, thanks!
Lucas Seiki Oshiro· Aug 20, 2025, 14:42 UTC · re: Lucas Seiki Oshiro · lore

[GSoC PATCH 2/2] repo: add the field objects.format

The flag `--show-object-format` from git-rev-parse is used for retrieving the object storage format. This way, it is used for querying repository metadata, fitting in the purpose of git-repo-info.

Add a new field `objects.format` to the git-repo-info subcommand containing that information.

Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 Documentation/git-repo.adoc | 3 +++
 builtin/repo.c              | 7 +++++++
 t/t1900-repo.sh             | 6 ++++++
 3 files changed, 16 insertions(+)
Show changes to 3 files +16 −0

Documentation/git-repo.adoc, builtin/repo.c, t/t1900-repo.sh

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index f2dc71193c..b6ec423d12 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -55,6 +55,9 @@ values that they return:
 `layout.shallow`::
 	`true` if this is a shallow repository, otherwise `false`.
 
+`objects.format`::
+	The object format (hash algorithm) used in the repository.
+
 `references.format`::
 	The reference storage format. The valid values are:
 +
diff --git a/builtin/repo.c b/builtin/repo.c
index b2ec66e454..71ddc5e8c6 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -38,6 +38,12 @@ static int get_layout_shallow(struct repository *repo, struct strbuf *buf)
 	return 0;
 }
 
+static int get_objects_format(struct repository *repo, struct strbuf *buf)
+{
+	strbuf_addstr(buf, repo->hash_algo->name);
+	return 0;
+}
+
 static int get_references_format(struct repository *repo, struct strbuf *buf)
 {
 	strbuf_addstr(buf,
@@ -49,6 +55,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
 static const struct field repo_info_fields[] = {
 	{ "layout.bare", get_layout_bare },
 	{ "layout.shallow", get_layout_shallow },
+	{ "objects.format", get_objects_format},
 	{ "references.format", get_references_format },
 };
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 3df55dcc79..aca2ed23f9 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -63,6 +63,12 @@ test_expect_success 'setup remote' '
 test_repo_info 'shallow repository = true is retrieved correctly' \
 	'git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true'
 
+test_repo_info 'objects.format = sha1 is retrieved correctly' \
+	'git init --object-format=sha1' 'sha1' 'objects.format' 'sha1'
+
+test_repo_info 'objects.format = sha256 is retrieved correctly' \
+	'git init --object-format=sha256' 'sha256' 'objects.format' 'sha256'
+
 test_expect_success 'values returned in order requested' '
 	cat >expect <<-\EOF &&
 	layout.bare=false
-- 
2.39.5 (Apple Git-154)
Patrick Steinhardt· Aug 21, 2025, 10:29 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH 2/2] repo: add the field objects.format

On Wed, Aug 20, 2025 at 11:42:47AM -0300, Lucas Seiki Oshiro wrote:
Show 9 quoted lines
> diff --git a/builtin/repo.c b/builtin/repo.c
> index b2ec66e454..71ddc5e8c6 100644
> --- a/builtin/repo.c
> +++ b/builtin/repo.c
> @@ -49,6 +55,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
>  static const struct field repo_info_fields[] = {
>  	{ "layout.bare", get_layout_bare },
>  	{ "layout.shallow", get_layout_shallow },
> +	{ "objects.format", get_objects_format},

There's a missing space here before the closing curly brace. Other than that this patch looks good to me.

Thanks!
Patrick
Junio C Hamano· Aug 21, 2025, 19:44 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH 2/2] repo: add the field objects.format

Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
> The flag `--show-object-format` from git-rev-parse is used for
> retrieving the object storage format. This way, it is used for
> querying repository metadata, fitting in the purpose of git-repo-info.

Yes, and extensions.objectFormat specifies the hash algorithm used in the repository, extensions.compatObjectFormat specifies a compatibility algorithm to use. So objectFormat is a good name to call this new "repository metadata".

> Add a new field `objects.format` to the git-repo-info subcommand
> containing that information.

Perhaps drop "s" from "objects.format" before it becomes too late? We may also want to reconsider references.format as that is not in line with either extensions.refStorage or --ref-format (taken by 'git init' and 'git clone').

Do these keys always have to be two words separated by dots? I am asking if there are other keys that would plausibly fit next to this object.format thing. object.count to report how many objects there are in the repository, or things like that, perhaps?

Show 7 quoted lines
> @@ -49,6 +55,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
>  static const struct field repo_info_fields[] = {
>  	{ "layout.bare", get_layout_bare },
>  	{ "layout.shallow", get_layout_shallow },
> +	{ "objects.format", get_objects_format},
>  	{ "references.format", get_references_format },
>  };
Lucas Seiki Oshiro· Aug 26, 2025, 14:51 UTC · re: Junio C Hamano · lore

Re: [GSoC PATCH 2/2] repo: add the field objects.format

> Yes, and extensions.objectFormat specifies the hash algorithm used
> in the repository, extensions.compatObjectFormat specifies a
> compatibility algorithm to use.  So objectFormat is a good name to
> call this new "repository metadata".

I was discussing with Patrick some weeks ago about the compatibility formats. By now, the "storage", "input", and "output" formats are the same. For example, rev-parse already has those options, even though they return the same value (2eabd38313 (rev-parse: add a --show-object-format option, 2019-10-28)).

Repo info is easy to handle this situation in the future by just adding a new field. By now, objects.format returns the storage format. If/when we have those formats implemented, I think a good approach would be add two more values to `objects`:

objects.input-format=... objects.output-format=...

> Perhaps drop "s" from "objects.format" before it becomes too late?
Ok!
> We may also want to reconsider references.format as that is not in
> line with either extensions.refStorage or --ref-format (taken by
> 'git init' and 'git clone').
What would be a better name? reference.format or ref.format? 
> Do these keys always have to be two words separated by dots?

The idea is to group everything into categories, than it will be easier. I have a future feature planned for that one could call, for example, `git repo layout` and then it will return both layout.bare and layout.shallow.

> I am asking if there are other keys that would plausibly fit next to this
> object.format thing.  object.count to report how many objects there
> are in the repository, or things like that, perhaps?

Given that it would survey how many objects exist in the repository, this would be better placed in the planned `git repo survey` that Justin is working on (we discussed a little more about that in https://lore.kernel.org/git/vygdkwopfzrbdpxpxebnq3xdlg3ow4i3w5y5evduae2zuelqcn@la2dikht2qrf/ ). I'm cc'ing Justin here for more info about it.

In the `info` side, by now I don't remember any other key to be placed under `object` aside from the aforementioned input and output format. Perhaps an idea is whether we're using packfiles or only loose objects, but I don't know if it would be useful.

Thanks!
Karthik Nayak· Aug 21, 2025, 10:14 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH 0/2] repo: add -z and objects.format

Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
Show 14 quoted lines
> Hi!
>
> This patchset adds two features to `git repo info`. They are unrelated,
> but I preferred to send them together to avoid merge conflicts and
> because they are small.
>
> - The first patch adds the `-z` as an alias for `--format=null`, as
>   requested in [1]
>
> - The second patch adds `objects.format`, which retrieves the same value
>   as `git rev-parse --show-object-format`
>
> Thanks!
>

Just a tip: It would be nice to mention which base branch this is based on top of and dependencies.

The patches themselves look good to me, just a small nit on the first commit.

Thanks!
[snip]
Junio C Hamano· Aug 21, 2025, 16:12 UTC · re: Karthik Nayak · lore

Re: [GSoC PATCH 0/2] repo: add -z and objects.format

Karthik Nayak <karthik.188@gmail.com> writes:
Show 19 quoted lines
> Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
>
>> Hi!
>>
>> This patchset adds two features to `git repo info`. They are unrelated,
>> but I preferred to send them together to avoid merge conflicts and
>> because they are small.
>>
>> - The first patch adds the `-z` as an alias for `--format=null`, as
>>   requested in [1]
>>
>> - The second patch adds `objects.format`, which retrieves the same value
>>   as `git rev-parse --show-object-format`
>>
>> Thanks!
>>
>
> Just a tip: It would be nice to mention which base branch this is based
> on top of and dependencies.

A very good suggestion. As this builds on top of lo/repo-info, which currently is at a81224d1 (repo: add the --format flag, 2025-08-16), I queued on top of a merge of that topic into Git 2.51

Thanks.
Patrick Steinhardt· Aug 21, 2025, 10:29 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH 0/2] repo: add -z and objects.format

On Wed, Aug 20, 2025 at 11:42:45AM -0300, Lucas Seiki Oshiro wrote:
Show 15 quoted lines
> Hi!
> 
> This patchset adds two features to `git repo info`. They are unrelated,
> but I preferred to send them together to avoid merge conflicts and
> because they are small.
> 
> - The first patch adds the `-z` as an alias for `--format=null`, as
>   requested in [1]
> 
> - The second patch adds `objects.format`, which retrieves the same value
>   as `git rev-parse --show-object-format`
>   
> Thanks!
> 
> [1] https://lore.kernel.org/git/mgdervgp34m6ipfbodsfn7cztcl7gdeggzemfgivzvuyk7qtba@wdijebkuioxg/

What this cover letter doesn't mention is the base of the topic. I assume it's v2.51.0 with lo/repo-info merged into it?

Patrick
Lucas Seiki Oshiro· Aug 21, 2025, 13:23 UTC · re: Patrick Steinhardt · lore

Re: [GSoC PATCH 0/2] repo: add -z and objects.format

> What this cover letter doesn't mention is the base of the topic. I
> assume it's v2.51.0 with lo/repo-info merged into it?

I was assuming next, but I'll make it more clear in the next version.

Patrick Steinhardt· Aug 21, 2025, 14:55 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH 0/2] repo: add -z and objects.format

On Thu, Aug 21, 2025 at 10:23:29AM -0300, Lucas Seiki Oshiro wrote:
Show 6 quoted lines
> 
> > What this cover letter doesn't mention is the base of the topic. I
> > assume it's v2.51.0 with lo/repo-info merged into it?
> 
> I was assuming next, but I'll make it more clear in the next
> version.

You shouldn't base your patch series on next, as next may be rewritten under your feet and it would hold any patch series that you built on hostage.

So the recommendation is rather to build on `master` with the specific patch series you depend on merged into it.

Patrick
Junio C Hamano· Aug 21, 2025, 17:28 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH 0/2] repo: add -z and objects.format

Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
Show 5 quoted lines
>> What this cover letter doesn't mention is the base of the topic. I
>> assume it's v2.51.0 with lo/repo-info merged into it?
>
> I was assuming next, but I'll make it more clear in the next
> version.
Learn the way how it is usually done by looking at:
https://lore.kernel.org/git/20250106-b4-pks-object-file-racy-collision-check-v2-0-8b3984ecbb18@pks.im/
Basically you would want to say
    This is built on top of <commit> with <topic*> merged into it.

where <commit> is a commit on 'master' (or 'maint' or an even older maintenance track, if the topic is about fixing a bug in a released version of Git), and <topic*> are topic branches in flight that can be merged to the same integration target ('master', or an older maintenance tracks you chose <commit> from). And keep the number of <topic*> to an absolute minimum in order for your changes to work.

Do not build on 'next'. You'll be taken hostage by all the other topics and have to wait until all of them and the merge commits that drew them into 'next' are merged to 'master', which will never happen.

Thanks.
Lucas Seiki Oshiro· Aug 26, 2025, 18:13 UTC · re: Junio C Hamano · lore

Re: [GSoC PATCH 0/2] repo: add -z and objects.format

> Basically you would want to say
> 
>    This is built on top of <commit> with <topic*> merged into it.
Thanks!

But given that lo/repo-info was already merged to master, now it won't be necessary... But I'll be more clear about that in future patches.

Lucas Seiki Oshiro· Aug 26, 2025, 18:32 UTC · re: Lucas Seiki Oshiro · lore

[GSoC PATCH v2 0/2] repo: add -z and objects.format

Hi!
This v2 contains small fixes pointed in the last version:
1. Adding two extra spaces in the usage string
2. Use `object.format` instead of `objects.format`
Here's the range-diff versus v1:
1:  4cb193f59c ! 1:  3ea40b1572 repo: add the flag -z as an alias for --format=nul
    @@ Documentation/git-repo.adoc: git-repo - Retrieve information about the repositor
      --------
      [synopsis]
     -git repo info [--format=(keyvalue|nul)] [<key>...]
    -+git repo info [--format=(keyvalue|nul)|-z] [<key>...]
    ++git repo info [--format=(keyvalue|nul) | -z] [<key>...]
      DESCRIPTION
      -----------
    @@ Documentation/git-repo.adoc: THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHAN
      COMMANDS
      --------
     -`info [--format=(keyvalue|nul)] [<key>...]`::
    -+`info [--format=(keyvalue|nul)|-z] [<key>...]`::
    ++`info [--format=(keyvalue|nul) | -z] [<key>...]`::
      	Retrieve metadata-related information about the current repository. Only
      	the requested data will be returned based on their keys (see "INFO KEYS"
      	section below).
    @@ builtin/repo.c
      static const char *const repo_usage[] = {
     -	"git repo info [--format=(keyvalue|nul)] [<key>...]",
    -+	"git repo info [--format=(keyvalue|nul)|-z] [<key>...]",
    ++	"git repo info [--format=(keyvalue|nul) | -z] [<key>...]",
      	NULL
      };
2:  37087dcc17 ! 2:  1d062e690e repo: add the field objects.format
    @@ Documentation/git-repo.adoc: values that they return:
      `layout.shallow`::
      	`true` if this is a shallow repository, otherwise `false`.
    -+`objects.format`::
    ++`object.format`::
     +	The object format (hash algorithm) used in the repository.
     +
      `references.format`::
    @@ builtin/repo.c: static int get_layout_shallow(struct repository *repo, struct st
      	return 0;
      }
    -+static int get_objects_format(struct repository *repo, struct strbuf *buf)
    ++static int get_object_format(struct repository *repo, struct strbuf *buf)
     +{
     +	strbuf_addstr(buf, repo->hash_algo->name);
     +	return 0;
    @@ builtin/repo.c: static int get_references_format(struct repository *repo, struct
      static const struct field repo_info_fields[] = {
      	{ "layout.bare", get_layout_bare },
      	{ "layout.shallow", get_layout_shallow },
    -+	{ "objects.format", get_objects_format},
    ++	{ "object.format", get_object_format },
      	{ "references.format", get_references_format },
      };
    @@ t/t1900-repo.sh: test_expect_success 'setup remote' '
      test_repo_info 'shallow repository = true is retrieved correctly' \
      	'git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true'
    -+test_repo_info 'objects.format = sha1 is retrieved correctly' \
    -+	'git init --object-format=sha1' 'sha1' 'objects.format' 'sha1'
    ++test_repo_info 'object.format = sha1 is retrieved correctly' \
    ++	'git init --object-format=sha1' 'sha1' 'object.format' 'sha1'
     +
    -+test_repo_info 'objects.format = sha256 is retrieved correctly' \
    -+	'git init --object-format=sha256' 'sha256' 'objects.format' 'sha256'
    ++test_repo_info 'object.format = sha256 is retrieved correctly' \
    ++	'git init --object-format=sha256' 'sha256' 'object.format' 'sha256'
     +
      test_expect_success 'values returned in order requested' '
      	cat >expect <<-\EOF &&
Lucas Seiki Oshiro (2):
  repo: add the flag -z as an alias for --format=nul
  repo: add the field objects.format
 Documentation/git-repo.adoc |  9 +++++++--
 builtin/repo.c              | 24 +++++++++++++++++++-----
 t/t1900-repo.sh             | 18 ++++++++++++++++++
 3 files changed, 44 insertions(+), 7 deletions(-)
-- 
2.39.5 (Apple Git-154)
Lucas Seiki Oshiro· Aug 26, 2025, 18:32 UTC · re: Lucas Seiki Oshiro · lore

[GSoC PATCH v2 1/2] repo: add the flag -z as an alias for --format=nul

Other Git commands that have nul-terminated output (e.g. git-config, git-status, git-ls-files) have a flag `-z` for using the null character as the record separator.

Add the `-z` flag to git-repo-info as an alias for `--format=nul`, making it consistent with the behavior of the other commands.

Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 Documentation/git-repo.adoc |  6 ++++--
 builtin/repo.c              | 17 ++++++++++++-----
 t/t1900-repo.sh             | 12 ++++++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)
Show changes to 3 files +28 −7

Documentation/git-repo.adoc, builtin/repo.c, t/t1900-repo.sh

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 2870828d93..8224a88bc8 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
 SYNOPSIS
 --------
 [synopsis]
-git repo info [--format=(keyvalue|nul)] [<key>...]
+git repo info [--format=(keyvalue|nul) | -z] [<key>...]
 
 DESCRIPTION
 -----------
@@ -18,7 +18,7 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
 
 COMMANDS
 --------
-`info [--format=(keyvalue|nul)] [<key>...]`::
+`info [--format=(keyvalue|nul) | -z] [<key>...]`::
 	Retrieve metadata-related information about the current repository. Only
 	the requested data will be returned based on their keys (see "INFO KEYS"
 	section below).
@@ -40,6 +40,8 @@ supported:
 	between the key and the value and using a NUL character after each value.
 	This format is better suited for being parsed by another applications than
 	`keyvalue`. Unlike in the `keyvalue` format, the values are never quoted.
++
+`-z` is an alias for `--format=nul`.
 
 INFO KEYS
 ---------
diff --git a/builtin/repo.c b/builtin/repo.c
index 8c6e7f42ab..5df33de42e 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -9,7 +9,7 @@
 #include "shallow.h"
 
 static const char *const repo_usage[] = {
-	"git repo info [--format=(keyvalue|nul)] [<key>...]",
+	"git repo info [--format=(keyvalue|nul) | -z] [<key>...]",
 	NULL
 };
 
@@ -115,20 +115,27 @@ static int print_fields(int argc, const char **argv,
 static int repo_info(int argc, const char **argv, const char *prefix,
 		     struct repository *repo)
 {
-	const char *format_str = "keyvalue";
+	const char *format_str = NULL;
 	enum output_format format;
+	int format_nul = 0;
 	struct option options[] = {
 		OPT_STRING(0, "format", &format_str, N_("format"),
 			   N_("output format")),
+		OPT_BOOL('z', NULL, &format_nul, N_("alias for --format=nul")),
 		OPT_END()
 	};
 
 	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
 
-	if (!strcmp(format_str, "keyvalue"))
-		format = FORMAT_KEYVALUE;
-	else if (!strcmp(format_str, "nul"))
+	die_for_incompatible_opt2(!!format_nul, "-z",
+				  !!format_str, "--format");
+
+	format_str = format_str ? format_str : "keyvalue";
+
+	if (format_nul || !strcmp(format_str, "nul"))
 		format = FORMAT_NUL_TERMINATED;
+	else if (!strcmp(format_str, "keyvalue"))
+		format = FORMAT_KEYVALUE;
 	else
 		die(_("invalid format '%s'"), format_str);
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index a69c715357..3df55dcc79 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -92,4 +92,16 @@ test_expect_success 'git-repo-info aborts when requesting an invalid format' '
 	test_cmp expect actual
 '
 
+test_expect_success '-z uses nul-terminated format' '
+	printf "layout.bare\nfalse\0layout.shallow\nfalse\0" >expected &&
+	git repo info -z layout.bare layout.shallow >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'git repo info fails when using --format and -z' '
+	echo "fatal: options ${SQ}-z${SQ} and ${SQ}--format${SQ} cannot be used together" >expected &&
+	test_must_fail git repo info -z --format=keyvalue 2>actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.39.5 (Apple Git-154)
Junio C Hamano· Aug 28, 2025, 23:08 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH v2 1/2] repo: add the flag -z as an alias for --format=nul

Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
> Other Git commands that have nul-terminated output (e.g. git-config,
> git-status, git-ls-files) have a flag `-z` for using the null character
> as the record separator.

Putting the devil's advocate hat on, "--format=<plain,nul>" was an attempt to avoid needless proliferation of options (e.g. presense of "-z" would tempt people into add "--json" when they introduce "--format=json"), so it may not be unconditionally a good idea to mimic these older commands where there are only two output formats.

But assuming that the short-and-sweet "-z" is something we want to add, the patch itself looks pretty well done, but not quite.

> Add the `-z` flag to git-repo-info as an alias for `--format=nul`,
> making it consistent with the behavior of the other commands.
Show 24 quoted lines
> diff --git a/builtin/repo.c b/builtin/repo.c
> index 8c6e7f42ab..5df33de42e 100644
> --- a/builtin/repo.c
> +++ b/builtin/repo.c
> @@ -115,20 +115,27 @@ static int print_fields(int argc, const char **argv,
>  static int repo_info(int argc, const char **argv, const char *prefix,
>  		     struct repository *repo)
>  {
> -	const char *format_str = "keyvalue";
> +	const char *format_str = NULL;
>  	enum output_format format;
> +	int format_nul = 0;
>  	struct option options[] = {
>  		OPT_STRING(0, "format", &format_str, N_("format"),
>  			   N_("output format")),
> +		OPT_BOOL('z', NULL, &format_nul, N_("alias for --format=nul")),
>  		OPT_END()
>  	};
>  
>  	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
>  
> -	if (!strcmp(format_str, "keyvalue"))
> -		format = FORMAT_KEYVALUE;
> -	else if (!strcmp(format_str, "nul"))
> +	die_for_incompatible_opt2(!!format_nul, "-z",
> +				  !!format_str, "--format");

Hmph, so "git repo info --format=nul -z" is now forbidden? That does not make much sense to me.

> +	format_str = format_str ? format_str : "keyvalue";
	if (!format_str)
		format_str = "keyvalue";

is probably easier to follow, but I suspect this becomes a bit of moot point as the general structure of this command line parsing may have to change when you fix the "-z is --format=nul so why are they incompatible?" problem.

Show 6 quoted lines
> +	if (format_nul || !strcmp(format_str, "nul"))
>  		format = FORMAT_NUL_TERMINATED;
> +	else if (!strcmp(format_str, "keyvalue"))
> +		format = FORMAT_KEYVALUE;
>  	else
>  		die(_("invalid format '%s'"), format_str);

You'd probably need to define a parseopt callback function for "format" and "-z", and remember the one that you saw the last. So giving "-z --format=nul --format=text" would first set an internal "format" to FORMAT_NUL_TERMINATED (due to "-z"), and then to the same FORMAT_NUL_TERMINATED again (due to "--format=nul"), and then finally to FORMAT_TEXT (due to "--format=text"), or something like that, which would give the familiar "the last one wins" semantics.

Something like (not even compile tested):
	static int parse_format_cb(const struct option *opt,
        			   const char *arg, int unset)
	{
		enum otuput_format *format = opt->value;
                if (opt->short_name == 'z')
                	*format = FORMAT_NUL_TERMINATED;
		else if (!strcmp(arg, "nul"))
                	*format = FORMAT_NUL_TERMINATED;
		else if (!strcmp(arg, "keyvalue"))
                	*format = FORMAT_KEYVALUE;
		else
			die(_("invalid format '--format=%s'", arg));
		return 0;
	}
with
	enum output_format format = FORMAT_KEYVALUE;
	struct option opt[] = {
		OPT_CALLBACK_F(0, "format", &format, N_("format"),
			       N_("output format"),
			       PARSE_OPT_NONEG, parse_format_cb),
		OPT_CALLBACK_F('z', NULL, &format, NULL,
			       N_("synonym for --format=nul"),
			       PARSE_OPT_NONEG|PARSE_OPT_NOARG,
			        parse_format_cb),
	};
perhaps?
Lucas Seiki Oshiro· Sep 1, 2025, 13:50 UTC · re: Junio C Hamano · lore

Re: [GSoC PATCH v2 1/2] repo: add the flag -z as an alias for --format=nul

Show 5 quoted lines
> Putting the devil's advocate hat on, "--format=<plain,nul>" was an
> attempt to avoid needless proliferation of options (e.g. presense of
> "-z" would tempt people into add "--json" when they introduce
> "--format=json"), so it may not be unconditionally a good idea to
> mimic these older commands where there are only two output formats.
Yeah, I understand...
Show 7 quoted lines
> You'd probably need to define a parseopt callback function for
> "format" and "-z", and remember the one that you saw the last.  So
> giving "-z --format=nul --format=text" would first set an internal
> "format" to FORMAT_NUL_TERMINATED (due to "-z"), and then to the
> same FORMAT_NUL_TERMINATED again (due to "--format=nul"), and then
> finally to FORMAT_TEXT (due to "--format=text"), or something like
> that, which would give the familiar "the last one wins" semantics.

Ok, accepted! I'll also replace the tests and the documentation in order to match this behavior. Thanks!

Lucas Seiki Oshiro· Aug 26, 2025, 18:32 UTC · re: Lucas Seiki Oshiro · lore

[GSoC PATCH v2 2/2] repo: add the field objects.format

The flag `--show-object-format` from git-rev-parse is used for retrieving the object storage format. This way, it is used for querying repository metadata, fitting in the purpose of git-repo-info.

Add a new field `objects.format` to the git-repo-info subcommand containing that information.

Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 Documentation/git-repo.adoc | 3 +++
 builtin/repo.c              | 7 +++++++
 t/t1900-repo.sh             | 6 ++++++
 3 files changed, 16 insertions(+)
Show changes to 3 files +16 −0

Documentation/git-repo.adoc, builtin/repo.c, t/t1900-repo.sh

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 8224a88bc8..2f9d696572 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -55,6 +55,9 @@ values that they return:
 `layout.shallow`::
 	`true` if this is a shallow repository, otherwise `false`.
 
+`object.format`::
+	The object format (hash algorithm) used in the repository.
+
 `references.format`::
 	The reference storage format. The valid values are:
 +
diff --git a/builtin/repo.c b/builtin/repo.c
index 5df33de42e..5c900d683e 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -38,6 +38,12 @@ static int get_layout_shallow(struct repository *repo, struct strbuf *buf)
 	return 0;
 }
 
+static int get_object_format(struct repository *repo, struct strbuf *buf)
+{
+	strbuf_addstr(buf, repo->hash_algo->name);
+	return 0;
+}
+
 static int get_references_format(struct repository *repo, struct strbuf *buf)
 {
 	strbuf_addstr(buf,
@@ -49,6 +55,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
 static const struct field repo_info_fields[] = {
 	{ "layout.bare", get_layout_bare },
 	{ "layout.shallow", get_layout_shallow },
+	{ "object.format", get_object_format },
 	{ "references.format", get_references_format },
 };
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 3df55dcc79..a83139f7ff 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -63,6 +63,12 @@ test_expect_success 'setup remote' '
 test_repo_info 'shallow repository = true is retrieved correctly' \
 	'git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true'
 
+test_repo_info 'object.format = sha1 is retrieved correctly' \
+	'git init --object-format=sha1' 'sha1' 'object.format' 'sha1'
+
+test_repo_info 'object.format = sha256 is retrieved correctly' \
+	'git init --object-format=sha256' 'sha256' 'object.format' 'sha256'
+
 test_expect_success 'values returned in order requested' '
 	cat >expect <<-\EOF &&
 	layout.bare=false
-- 
2.39.5 (Apple Git-154)
Lucas Seiki Oshiro· Sep 1, 2025, 17:27 UTC · re: Lucas Seiki Oshiro · lore

[GSoC PATCH v3 0/2] repo: add -z and objects.format

Hi!

The major change in this v3 is that it's now possible to use --format and -z together. If the user uses a combination of two or more --format or -z, only the last one will be considered.

Here's the range-diff versus v2:
1:  3ea40b1572 ! 1:  0323f1fa75 repo: add the flag -z as an alias for --format=nul
    @@ Documentation/git-repo.adoc: git-repo - Retrieve information about the repositor
      --------
      [synopsis]
     -git repo info [--format=(keyvalue|nul)] [<key>...]
    -+git repo info [--format=(keyvalue|nul) | -z] [<key>...]
    ++git repo info [--format=(keyvalue|nul)] [-z] [<key>...]
      
      DESCRIPTION
      -----------
    @@ Documentation/git-repo.adoc: THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHAN
      COMMANDS
      --------
     -`info [--format=(keyvalue|nul)] [<key>...]`::
    -+`info [--format=(keyvalue|nul) | -z] [<key>...]`::
    ++`info [--format=(keyvalue|nul)] [-z] [<key>...]`::
      	Retrieve metadata-related information about the current repository. Only
      	the requested data will be returned based on their keys (see "INFO KEYS"
      	section below).
    @@ builtin/repo.c
      
      static const char *const repo_usage[] = {
     -	"git repo info [--format=(keyvalue|nul)] [<key>...]",
    -+	"git repo info [--format=(keyvalue|nul) | -z] [<key>...]",
    ++	"git repo info [--format=(keyvalue|nul)] [-z] [<key>...]",
      	NULL
      };
      
     @@ builtin/repo.c: static int print_fields(int argc, const char **argv,
    + 	return ret;
    + }
    + 
    ++static int parse_format_cb(const struct option *opt,
    ++			   const char *arg, int unset UNUSED) {
    ++	enum output_format *format = opt->value;
    ++
    ++	if (opt->short_name == 'z')
    ++		*format = FORMAT_NUL_TERMINATED;
    ++	else if (!strcmp(arg, "nul"))
    ++		*format = FORMAT_NUL_TERMINATED;
    ++	else if (!strcmp(arg, "keyvalue"))
    ++		*format = FORMAT_KEYVALUE;
    ++	else
    ++		die(_("invalid format '%s'"), arg);
    ++
    ++	return 0;
    ++}
    ++
      static int repo_info(int argc, const char **argv, const char *prefix,
      		     struct repository *repo)
      {
     -	const char *format_str = "keyvalue";
    -+	const char *format_str = NULL;
    - 	enum output_format format;
    -+	int format_nul = 0;
    +-	enum output_format format;
    ++	enum output_format format = FORMAT_KEYVALUE;
      	struct option options[] = {
    - 		OPT_STRING(0, "format", &format_str, N_("format"),
    - 			   N_("output format")),
    -+		OPT_BOOL('z', NULL, &format_nul, N_("alias for --format=nul")),
    +-		OPT_STRING(0, "format", &format_str, N_("format"),
    +-			   N_("output format")),
    ++		OPT_CALLBACK_F(0, "format", &format, N_("format"),
    ++			       N_("output format"),
    ++			       PARSE_OPT_NONEG, parse_format_cb),
    ++		OPT_CALLBACK_F('z', NULL, &format, NULL,
    ++			       N_("synonym for --format=nul"),
    ++			       PARSE_OPT_NONEG|PARSE_OPT_NOARG,
    ++			       parse_format_cb),
      		OPT_END()
      	};
      
    @@ builtin/repo.c: static int print_fields(int argc, const char **argv,
     -	if (!strcmp(format_str, "keyvalue"))
     -		format = FORMAT_KEYVALUE;
     -	else if (!strcmp(format_str, "nul"))
    -+	die_for_incompatible_opt2(!!format_nul, "-z",
    -+				  !!format_str, "--format");
    -+
    -+	format_str = format_str ? format_str : "keyvalue";
    -+
    -+	if (format_nul || !strcmp(format_str, "nul"))
    - 		format = FORMAT_NUL_TERMINATED;
    -+	else if (!strcmp(format_str, "keyvalue"))
    -+		format = FORMAT_KEYVALUE;
    - 	else
    - 		die(_("invalid format '%s'"), format_str);
    +-		format = FORMAT_NUL_TERMINATED;
    +-	else
    +-		die(_("invalid format '%s'"), format_str);
    +-
    + 	return print_fields(argc, argv, repo, format);
    + }
      
     
      ## t/t1900-repo.sh ##
    @@ t/t1900-repo.sh: test_expect_success 'git-repo-info aborts when requesting an in
     +	test_cmp expected actual
     +'
     +
    -+test_expect_success 'git repo info fails when using --format and -z' '
    -+	echo "fatal: options ${SQ}-z${SQ} and ${SQ}--format${SQ} cannot be used together" >expected &&
    -+	test_must_fail git repo info -z --format=keyvalue 2>actual &&
    ++test_expect_success 'git repo info uses the last requested format' '
    ++	echo "layout.bare=false" >expected &&
    ++	git repo info --format=nul -z --format=keyvalue layout.bare >actual &&
     +	test_cmp expected actual
     +'
     +
2:  1d062e690e = 2:  b2b241f401 repo: add the field objects.format
Lucas Seiki Oshiro (2):
  repo: add the flag -z as an alias for --format=nul
  repo: add the field objects.format
 Documentation/git-repo.adoc |  9 ++++++--
 builtin/repo.c              | 44 +++++++++++++++++++++++++++----------
 t/t1900-repo.sh             | 18 +++++++++++++++
 3 files changed, 57 insertions(+), 14 deletions(-)
-- 
2.39.5 (Apple Git-154)
Lucas Seiki Oshiro· Sep 1, 2025, 17:27 UTC · re: Lucas Seiki Oshiro · lore

[GSoC PATCH v3 1/2] repo: add the flag -z as an alias for --format=nul

Other Git commands that have nul-terminated output (e.g. git-config, git-status, git-ls-files) have a flag `-z` for using the null character as the record separator.

Add the `-z` flag to git-repo-info as an alias for `--format=nul`, making it consistent with the behavior of the other commands.

Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 Documentation/git-repo.adoc |  6 ++++--
 builtin/repo.c              | 37 +++++++++++++++++++++++++------------
 t/t1900-repo.sh             | 12 ++++++++++++
 3 files changed, 41 insertions(+), 14 deletions(-)
Show changes to 3 files +41 −14

Documentation/git-repo.adoc, builtin/repo.c, t/t1900-repo.sh

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 2870828d93..6f5ee88215 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
 SYNOPSIS
 --------
 [synopsis]
-git repo info [--format=(keyvalue|nul)] [<key>...]
+git repo info [--format=(keyvalue|nul)] [-z] [<key>...]
 
 DESCRIPTION
 -----------
@@ -18,7 +18,7 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
 
 COMMANDS
 --------
-`info [--format=(keyvalue|nul)] [<key>...]`::
+`info [--format=(keyvalue|nul)] [-z] [<key>...]`::
 	Retrieve metadata-related information about the current repository. Only
 	the requested data will be returned based on their keys (see "INFO KEYS"
 	section below).
@@ -40,6 +40,8 @@ supported:
 	between the key and the value and using a NUL character after each value.
 	This format is better suited for being parsed by another applications than
 	`keyvalue`. Unlike in the `keyvalue` format, the values are never quoted.
++
+`-z` is an alias for `--format=nul`.
 
 INFO KEYS
 ---------
diff --git a/builtin/repo.c b/builtin/repo.c
index 8c6e7f42ab..13a34f68a5 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -9,7 +9,7 @@
 #include "shallow.h"
 
 static const char *const repo_usage[] = {
-	"git repo info [--format=(keyvalue|nul)] [<key>...]",
+	"git repo info [--format=(keyvalue|nul)] [-z] [<key>...]",
 	NULL
 };
 
@@ -112,26 +112,39 @@ static int print_fields(int argc, const char **argv,
 	return ret;
 }
 
+static int parse_format_cb(const struct option *opt,
+			   const char *arg, int unset UNUSED) {
+	enum output_format *format = opt->value;
+
+	if (opt->short_name == 'z')
+		*format = FORMAT_NUL_TERMINATED;
+	else if (!strcmp(arg, "nul"))
+		*format = FORMAT_NUL_TERMINATED;
+	else if (!strcmp(arg, "keyvalue"))
+		*format = FORMAT_KEYVALUE;
+	else
+		die(_("invalid format '%s'"), arg);
+
+	return 0;
+}
+
 static int repo_info(int argc, const char **argv, const char *prefix,
 		     struct repository *repo)
 {
-	const char *format_str = "keyvalue";
-	enum output_format format;
+	enum output_format format = FORMAT_KEYVALUE;
 	struct option options[] = {
-		OPT_STRING(0, "format", &format_str, N_("format"),
-			   N_("output format")),
+		OPT_CALLBACK_F(0, "format", &format, N_("format"),
+			       N_("output format"),
+			       PARSE_OPT_NONEG, parse_format_cb),
+		OPT_CALLBACK_F('z', NULL, &format, NULL,
+			       N_("synonym for --format=nul"),
+			       PARSE_OPT_NONEG|PARSE_OPT_NOARG,
+			       parse_format_cb),
 		OPT_END()
 	};
 
 	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
 
-	if (!strcmp(format_str, "keyvalue"))
-		format = FORMAT_KEYVALUE;
-	else if (!strcmp(format_str, "nul"))
-		format = FORMAT_NUL_TERMINATED;
-	else
-		die(_("invalid format '%s'"), format_str);
-
 	return print_fields(argc, argv, repo, format);
 }
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index a69c715357..ddf788d5a2 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -92,4 +92,16 @@ test_expect_success 'git-repo-info aborts when requesting an invalid format' '
 	test_cmp expect actual
 '
 
+test_expect_success '-z uses nul-terminated format' '
+	printf "layout.bare\nfalse\0layout.shallow\nfalse\0" >expected &&
+	git repo info -z layout.bare layout.shallow >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'git repo info uses the last requested format' '
+	echo "layout.bare=false" >expected &&
+	git repo info --format=nul -z --format=keyvalue layout.bare >actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.39.5 (Apple Git-154)
Junio C Hamano· Sep 2, 2025, 16:21 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH v3 1/2] repo: add the flag -z as an alias for --format=nul

Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
Show 26 quoted lines
> Other Git commands that have nul-terminated output (e.g. git-config,
> git-status, git-ls-files) have a flag `-z` for using the null character
> as the record separator.
>
> Add the `-z` flag to git-repo-info as an alias for `--format=nul`,
> making it consistent with the behavior of the other commands.
>
> Mentored-by: Karthik Nayak <karthik.188@gmail.com>
> Mentored-by: Patrick Steinhardt <ps@pks.im>
> Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
> ---
>  Documentation/git-repo.adoc |  6 ++++--
>  builtin/repo.c              | 37 +++++++++++++++++++++++++------------
>  t/t1900-repo.sh             | 12 ++++++++++++
>  3 files changed, 41 insertions(+), 14 deletions(-)
>
> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> index 2870828d93..6f5ee88215 100644
> --- a/Documentation/git-repo.adoc
> +++ b/Documentation/git-repo.adoc
> @@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
>  SYNOPSIS
>  --------
>  [synopsis]
> -git repo info [--format=(keyvalue|nul)] [<key>...]
> +git repo info [--format=(keyvalue|nul)] [-z] [<key>...]

This is OK and I do not want you to reroll only to revert this, but FWIW what you had in the previous iteration

    git repo info [--format=(keyvalue|nul) | -z] [<key>...]

would also work perfectly well here. It is not like you are forbidding the command line to mention "--format=nul" twice, or "--format=keyvalue --format=nul" to allow the later one to override the former ones.

The updated option parsing looks much nicer.  Thanks.
Lucas Seiki Oshiro· Sep 2, 2025, 21:51 UTC · re: Junio C Hamano · lore

Re: [GSoC PATCH v3 1/2] repo: add the flag -z as an alias for --format=nul

Show 9 quoted lines
> This is OK and I do not want you to reroll only to revert this, but
> FWIW what you had in the previous iteration
> 
>    git repo info [--format=(keyvalue|nul) | -z] [<key>...]
> 
> would also work perfectly well here.  It is not like you are
> forbidding the command line to mention "--format=nul" twice, or
> "--format=keyvalue --format=nul" to allow the later one to override
> the former ones.
Hmmm, ok!
> The updated option parsing looks much nicer.  Thanks.
Thanks, Junio!
Lucas Seiki Oshiro· Sep 1, 2025, 17:27 UTC · re: Lucas Seiki Oshiro · lore

[GSoC PATCH v3 2/2] repo: add the field objects.format

The flag `--show-object-format` from git-rev-parse is used for retrieving the object storage format. This way, it is used for querying repository metadata, fitting in the purpose of git-repo-info.

Add a new field `objects.format` to the git-repo-info subcommand containing that information.

Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 Documentation/git-repo.adoc | 3 +++
 builtin/repo.c              | 7 +++++++
 t/t1900-repo.sh             | 6 ++++++
 3 files changed, 16 insertions(+)
Show changes to 3 files +16 −0

Documentation/git-repo.adoc, builtin/repo.c, t/t1900-repo.sh

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 6f5ee88215..209afd1b61 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -55,6 +55,9 @@ values that they return:
 `layout.shallow`::
 	`true` if this is a shallow repository, otherwise `false`.
 
+`object.format`::
+	The object format (hash algorithm) used in the repository.
+
 `references.format`::
 	The reference storage format. The valid values are:
 +
diff --git a/builtin/repo.c b/builtin/repo.c
index 13a34f68a5..9b519426fe 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -38,6 +38,12 @@ static int get_layout_shallow(struct repository *repo, struct strbuf *buf)
 	return 0;
 }
 
+static int get_object_format(struct repository *repo, struct strbuf *buf)
+{
+	strbuf_addstr(buf, repo->hash_algo->name);
+	return 0;
+}
+
 static int get_references_format(struct repository *repo, struct strbuf *buf)
 {
 	strbuf_addstr(buf,
@@ -49,6 +55,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
 static const struct field repo_info_fields[] = {
 	{ "layout.bare", get_layout_bare },
 	{ "layout.shallow", get_layout_shallow },
+	{ "object.format", get_object_format },
 	{ "references.format", get_references_format },
 };
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index ddf788d5a2..2beba67889 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -63,6 +63,12 @@ test_expect_success 'setup remote' '
 test_repo_info 'shallow repository = true is retrieved correctly' \
 	'git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true'
 
+test_repo_info 'object.format = sha1 is retrieved correctly' \
+	'git init --object-format=sha1' 'sha1' 'object.format' 'sha1'
+
+test_repo_info 'object.format = sha256 is retrieved correctly' \
+	'git init --object-format=sha256' 'sha256' 'object.format' 'sha256'
+
 test_expect_success 'values returned in order requested' '
 	cat >expect <<-\EOF &&
 	layout.bare=false
-- 
2.39.5 (Apple Git-154)
Lucas Seiki Oshiro· Sep 4, 2025, 13:40 UTC · re: Lucas Seiki Oshiro · lore

[GSoC PATCH v4 0/2] repo: add -z and objects.format

Hi!
This v4 fixes two codestyle issues:
- Break line before opening a brace
- Add spaces surrounding a `|`
Here's the range-diff versus v3:
1:  0323f1fa75 ! 1:  19c84e1a48 repo: add the flag -z as an alias for --format=nul
    @@ builtin/repo.c: static int print_fields(int argc, const char **argv,
      }
     +static int parse_format_cb(const struct option *opt,
    -+                     const char *arg, int unset UNUSED) {
    ++                     const char *arg, int unset UNUSED)
    ++{
     +  enum output_format *format = opt->value;
     +
     +  if (opt->short_name == 'z')
    @@ builtin/repo.c: static int print_fields(int argc, const char **argv,
     +                         PARSE_OPT_NONEG, parse_format_cb),
     +          OPT_CALLBACK_F('z', NULL, &format, NULL,
     +                         N_("synonym for --format=nul"),
    -+                         PARSE_OPT_NONEG|PARSE_OPT_NOARG,
    ++                         PARSE_OPT_NONEG | PARSE_OPT_NOARG,
     +                         parse_format_cb),
                OPT_END()
        };
2:  b2b241f401 = 2:  6258316d93 repo: add the field objects.format
Lucas Seiki Oshiro (2):
  repo: add the flag -z as an alias for --format=nul
  repo: add the field objects.format
 Documentation/git-repo.adoc |  9 ++++++--
 builtin/repo.c              | 45 +++++++++++++++++++++++++++----------
 t/t1900-repo.sh             | 18 +++++++++++++++
 3 files changed, 58 insertions(+), 14 deletions(-)
-- 
2.39.5 (Apple Git-154)
Lucas Seiki Oshiro· Sep 4, 2025, 13:40 UTC · re: Lucas Seiki Oshiro · lore

[GSoC PATCH v4 1/2] repo: add the flag -z as an alias for --format=nul

Other Git commands that have nul-terminated output (e.g. git-config, git-status, git-ls-files) have a flag `-z` for using the null character as the record separator.

Add the `-z` flag to git-repo-info as an alias for `--format=nul`, making it consistent with the behavior of the other commands.

Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 Documentation/git-repo.adoc |  6 ++++--
 builtin/repo.c              | 38 +++++++++++++++++++++++++------------
 t/t1900-repo.sh             | 12 ++++++++++++
 3 files changed, 42 insertions(+), 14 deletions(-)
Show changes to 3 files +42 −14

Documentation/git-repo.adoc, builtin/repo.c, t/t1900-repo.sh

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 2870828d93..6f5ee88215 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
 SYNOPSIS
 --------
 [synopsis]
-git repo info [--format=(keyvalue|nul)] [<key>...]
+git repo info [--format=(keyvalue|nul)] [-z] [<key>...]
 
 DESCRIPTION
 -----------
@@ -18,7 +18,7 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
 
 COMMANDS
 --------
-`info [--format=(keyvalue|nul)] [<key>...]`::
+`info [--format=(keyvalue|nul)] [-z] [<key>...]`::
 	Retrieve metadata-related information about the current repository. Only
 	the requested data will be returned based on their keys (see "INFO KEYS"
 	section below).
@@ -40,6 +40,8 @@ supported:
 	between the key and the value and using a NUL character after each value.
 	This format is better suited for being parsed by another applications than
 	`keyvalue`. Unlike in the `keyvalue` format, the values are never quoted.
++
+`-z` is an alias for `--format=nul`.
 
 INFO KEYS
 ---------
diff --git a/builtin/repo.c b/builtin/repo.c
index 8c6e7f42ab..dc9a267469 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -9,7 +9,7 @@
 #include "shallow.h"
 
 static const char *const repo_usage[] = {
-	"git repo info [--format=(keyvalue|nul)] [<key>...]",
+	"git repo info [--format=(keyvalue|nul)] [-z] [<key>...]",
 	NULL
 };
 
@@ -112,26 +112,40 @@ static int print_fields(int argc, const char **argv,
 	return ret;
 }
 
+static int parse_format_cb(const struct option *opt,
+			   const char *arg, int unset UNUSED)
+{
+	enum output_format *format = opt->value;
+
+	if (opt->short_name == 'z')
+		*format = FORMAT_NUL_TERMINATED;
+	else if (!strcmp(arg, "nul"))
+		*format = FORMAT_NUL_TERMINATED;
+	else if (!strcmp(arg, "keyvalue"))
+		*format = FORMAT_KEYVALUE;
+	else
+		die(_("invalid format '%s'"), arg);
+
+	return 0;
+}
+
 static int repo_info(int argc, const char **argv, const char *prefix,
 		     struct repository *repo)
 {
-	const char *format_str = "keyvalue";
-	enum output_format format;
+	enum output_format format = FORMAT_KEYVALUE;
 	struct option options[] = {
-		OPT_STRING(0, "format", &format_str, N_("format"),
-			   N_("output format")),
+		OPT_CALLBACK_F(0, "format", &format, N_("format"),
+			       N_("output format"),
+			       PARSE_OPT_NONEG, parse_format_cb),
+		OPT_CALLBACK_F('z', NULL, &format, NULL,
+			       N_("synonym for --format=nul"),
+			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
+			       parse_format_cb),
 		OPT_END()
 	};
 
 	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
 
-	if (!strcmp(format_str, "keyvalue"))
-		format = FORMAT_KEYVALUE;
-	else if (!strcmp(format_str, "nul"))
-		format = FORMAT_NUL_TERMINATED;
-	else
-		die(_("invalid format '%s'"), format_str);
-
 	return print_fields(argc, argv, repo, format);
 }
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index a69c715357..ddf788d5a2 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -92,4 +92,16 @@ test_expect_success 'git-repo-info aborts when requesting an invalid format' '
 	test_cmp expect actual
 '
 
+test_expect_success '-z uses nul-terminated format' '
+	printf "layout.bare\nfalse\0layout.shallow\nfalse\0" >expected &&
+	git repo info -z layout.bare layout.shallow >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'git repo info uses the last requested format' '
+	echo "layout.bare=false" >expected &&
+	git repo info --format=nul -z --format=keyvalue layout.bare >actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.39.5 (Apple Git-154)
Lucas Seiki Oshiro· Sep 4, 2025, 13:40 UTC · re: Lucas Seiki Oshiro · lore

[GSoC PATCH v4 2/2] repo: add the field objects.format

The flag `--show-object-format` from git-rev-parse is used for retrieving the object storage format. This way, it is used for querying repository metadata, fitting in the purpose of git-repo-info.

Add a new field `objects.format` to the git-repo-info subcommand containing that information.

Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 Documentation/git-repo.adoc | 3 +++
 builtin/repo.c              | 7 +++++++
 t/t1900-repo.sh             | 6 ++++++
 3 files changed, 16 insertions(+)
Show changes to 3 files +16 −0

Documentation/git-repo.adoc, builtin/repo.c, t/t1900-repo.sh

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 6f5ee88215..209afd1b61 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -55,6 +55,9 @@ values that they return:
 `layout.shallow`::
 	`true` if this is a shallow repository, otherwise `false`.
 
+`object.format`::
+	The object format (hash algorithm) used in the repository.
+
 `references.format`::
 	The reference storage format. The valid values are:
 +
diff --git a/builtin/repo.c b/builtin/repo.c
index dc9a267469..bbb0966f2d 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -38,6 +38,12 @@ static int get_layout_shallow(struct repository *repo, struct strbuf *buf)
 	return 0;
 }
 
+static int get_object_format(struct repository *repo, struct strbuf *buf)
+{
+	strbuf_addstr(buf, repo->hash_algo->name);
+	return 0;
+}
+
 static int get_references_format(struct repository *repo, struct strbuf *buf)
 {
 	strbuf_addstr(buf,
@@ -49,6 +55,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
 static const struct field repo_info_fields[] = {
 	{ "layout.bare", get_layout_bare },
 	{ "layout.shallow", get_layout_shallow },
+	{ "object.format", get_object_format },
 	{ "references.format", get_references_format },
 };
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index ddf788d5a2..2beba67889 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -63,6 +63,12 @@ test_expect_success 'setup remote' '
 test_repo_info 'shallow repository = true is retrieved correctly' \
 	'git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true'
 
+test_repo_info 'object.format = sha1 is retrieved correctly' \
+	'git init --object-format=sha1' 'sha1' 'object.format' 'sha1'
+
+test_repo_info 'object.format = sha256 is retrieved correctly' \
+	'git init --object-format=sha256' 'sha256' 'object.format' 'sha256'
+
 test_expect_success 'values returned in order requested' '
 	cat >expect <<-\EOF &&
 	layout.bare=false
-- 
2.39.5 (Apple Git-154)
Junio C Hamano· Sep 4, 2025, 18:40 UTC · re: Lucas Seiki Oshiro · lore

Re: [GSoC PATCH v4 0/2] repo: add -z and objects.format

Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
> This v4 fixes two codestyle issues:
>
> - Break line before opening a brace
> - Add spaces surrounding a `|`
Looks good.  THese are the only things
    $ git clang-format --diff HEAD~2 HEAD
reports on the version that has been in my tree.
Will queue; let's mark it for 'next'.
Show 33 quoted lines
>
> Here's the range-diff versus v3:
>
> 1:  0323f1fa75 ! 1:  19c84e1a48 repo: add the flag -z as an alias for --format=nul
>     @@ builtin/repo.c: static int print_fields(int argc, const char **argv,
>       }
>
>      +static int parse_format_cb(const struct option *opt,
>     -+                     const char *arg, int unset UNUSED) {
>     ++                     const char *arg, int unset UNUSED)
>     ++{
>      +  enum output_format *format = opt->value;
>      +
>      +  if (opt->short_name == 'z')
>     @@ builtin/repo.c: static int print_fields(int argc, const char **argv,
>      +                         PARSE_OPT_NONEG, parse_format_cb),
>      +          OPT_CALLBACK_F('z', NULL, &format, NULL,
>      +                         N_("synonym for --format=nul"),
>     -+                         PARSE_OPT_NONEG|PARSE_OPT_NOARG,
>     ++                         PARSE_OPT_NONEG | PARSE_OPT_NOARG,
>      +                         parse_format_cb),
>                 OPT_END()
>         };
> 2:  b2b241f401 = 2:  6258316d93 repo: add the field objects.format
>
> Lucas Seiki Oshiro (2):
>   repo: add the flag -z as an alias for --format=nul
>   repo: add the field objects.format
>
>  Documentation/git-repo.adoc |  9 ++++++--
>  builtin/repo.c              | 45 +++++++++++++++++++++++++++----------
>  t/t1900-repo.sh             | 18 +++++++++++++++
>  3 files changed, 58 insertions(+), 14 deletions(-)

← back to recent threads