Skip to contentSkip to conversation

repo: add -z and objects.format

PATCH Superseded Lucas Seiki Oshiro 5 participants 37 messages Aug 20, 2025 – Sep 4, 2025 Documentation

lore
Share & tools
lore
#0 lore raw

cover repo: add -z and objects.format

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(-)
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw

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.

---
 Documentation/git-repo.adoc |  6 ++++--
 builtin/repo.c              | 17 ++++++++++++-----
 t/t1900-repo.sh             | 12 ++++++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)
Documentation/git-repo.adoc +4 -2
index 2870828d93..f2dc71193c 100644
@@ -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
 ---------
builtin/repo.c +12 -5
index 8c6e7f42ab..b2ec66e454 100644
@@ -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);
 
t/t1900-repo.sh +12 -0
index a69c715357..3df55dcc79 100755
@@ -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
Signature · 1 line
2.39.5 (Apple Git-154)
#2 lore raw

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

Quoted 21 lines · Lucas Seiki Oshiro

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.

---
 Documentation/git-repo.adoc |  6 ++++--
 builtin/repo.c              | 17 ++++++++++++-----
 t/t1900-repo.sh             | 12 ++++++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)
Documentation/git-repo.adoc +0 -0
index 2870828d93..f2dc71193c 100644

Documentation/git-repo.adoc git-repo - Retrieve information about the repository · line 12

Quoted 6 lines
Documentation/git-repo.adoc +1 -1
@@ -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?

Quoted 87 lines
Documentation/git-repo.adoc +3 -1
 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
 ---------
builtin/repo.c +12 -5
index 8c6e7f42ab..b2ec66e454 100644
@@ -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);
 
t/t1900-repo.sh +12 -1
index a69c715357..3df55dcc79 100755
@@ -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
--
Quoted 1 line

2.39.5 (Apple Git-154)

The rest looks good.

#3 lore raw

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

Quoted 5 lines · Karthik Nayak

Documentation/git-repo.adoc git-repo - Retrieve information about the repository · line 11

Quoted 3 lines
Documentation/git-repo.adoc +1 -1
-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)]

#4 lore raw

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

Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Karthik Nayak

Documentation/git-repo.adoc git-repo - Retrieve information about the repository · line 11

Quoted 3 lines
Documentation/git-repo.adoc +1 -1
-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?

Quoted 8 lines

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!

#5 lore raw

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

In reply to Lucas Seiki Oshiro
Quoted 6 lines · Lucas Seiki Oshiro

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.

Documentation/git-repo.adoc git-repo - Retrieve information about the repository · line 11

Quoted 10 lines
Documentation/git-repo.adoc +1 -1
index 2870828d93..f2dc71193c 100644
@@ -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.

Quoted 16 lines
builtin/repo.c +3 -1
index 8c6e7f42ab..b2ec66e454 100644
@@ -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")),

builtin/repo.c static int print_fields(int argc, const char **argv, · line 131

Quoted 10 lines
builtin/repo.c +2 -3
 		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".

builtin/repo.c static int print_fields(int argc, const char **argv, · line 141

Quoted 9 lines
builtin/repo.c +5 -0
+	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

#6 lore raw

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

Quoted 7 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!

#7 lore raw

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

Quoted 1 line · Lucas Seiki Oshiro

But I don't have any strong opinion about that. I'm open to suggestions.

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

#8 lore raw

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

Quoted 5 lines
Quoted 2 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...

#9 lore raw

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

Quoted 10 lines · Lucas Seiki Oshiro
Quoted 4 lines
Quoted 1 line

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...

#10 lore raw

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

In reply to Lucas Seiki Oshiro
Quoted 21 lines · On Wednesday, 20 August 2025 16:42:46 CEST Lucas Seiki Oshiro wrote:

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.

---
 Documentation/git-repo.adoc |  6 ++++--
 builtin/repo.c              | 17 ++++++++++++-----
 t/t1900-repo.sh             | 12 ++++++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)
Documentation/git-repo.adoc +0 -0
index 2870828d93..f2dc71193c 100644

Documentation/git-repo.adoc git-repo - Retrieve information about the repository · line 12

Quoted 6 lines
Documentation/git-repo.adoc +1 -1
@@ -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)]
#11 lore raw

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

Quoted 12 lines · Jean-Noël AVILA

Documentation/git-repo.adoc git-repo - Retrieve information about the repository · line 11

Quoted 3 lines
Documentation/git-repo.adoc +1 -1
-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:

Quoted 7 lines
   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!

#12 lore raw

PATCH 2/2 repo: add the field objects.format

In reply to Lucas Seiki Oshiro

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.

---
 Documentation/git-repo.adoc | 3 +++
 builtin/repo.c              | 7 +++++++
 t/t1900-repo.sh             | 6 ++++++
 3 files changed, 16 insertions(+)
Documentation/git-repo.adoc +3 -0
index f2dc71193c..b6ec423d12 100644
@@ -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:
 +
builtin/repo.c +7 -0
index b2ec66e454..71ddc5e8c6 100644
@@ -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 },
 };
 
t/t1900-repo.sh +6 -0
index 3df55dcc79..aca2ed23f9 100755
@@ -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
Signature · 1 line
2.39.5 (Apple Git-154)
#13 lore raw

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

builtin/repo.c static int get_references_format(struct repository *repo, struct strbuf *buf) · line 58

Quoted 9 lines · Lucas Seiki Oshiro
builtin/repo.c +1 -0
index b2ec66e454..71ddc5e8c6 100644
@@ -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

#14 lore raw

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

In reply to Lucas Seiki Oshiro
Quoted 3 lines · Lucas Seiki Oshiro

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".

Quoted 2 lines

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?

Quoted 7 lines
builtin/repo.c +1 -0
@@ -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 },
 };
#15 lore raw

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

Quoted 5 lines

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=...

Quoted 1 line

Perhaps drop "s" from "objects.format" before it becomes too late?

Ok!

Quoted 3 lines

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?

Quoted 1 line

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.

Quoted 3 lines

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!

#16 lore raw
In reply to Lucas Seiki Oshiro
Quoted 6 lines · Lucas Seiki Oshiro

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.

Quoted 8 lines

- 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]

#17 lore raw
Quoted 11 lines · Karthik Nayak
Quoted 9 lines · Lucas Seiki Oshiro

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]

Quoted 8 lines
Quoted 5 lines

- 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.

#18 lore raw
In reply to Lucas Seiki Oshiro
Quoted 9 lines · Lucas Seiki Oshiro

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]

Quoted 6 lines

- 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

#19 lore raw
Quoted 3 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.

#20 lore raw
Quoted 6 lines · Lucas Seiki Oshiro
Quoted 3 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

#21 lore raw
In reply to Lucas Seiki Oshiro
Quoted 5 lines · Lucas Seiki Oshiro
Quoted 2 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.

#22 lore raw
Quoted 4 lines

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.

#23 lore raw

v2 cover repo: add -z and objects.format

In reply to Lucas Seiki Oshiro

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(-)
Signature · 1 line
2.39.5 (Apple Git-154)
#24 lore raw

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.

---
 Documentation/git-repo.adoc |  6 ++++--
 builtin/repo.c              | 17 ++++++++++++-----
 t/t1900-repo.sh             | 12 ++++++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)
Documentation/git-repo.adoc +4 -2
index 2870828d93..8224a88bc8 100644
@@ -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
 ---------
builtin/repo.c +12 -5
index 8c6e7f42ab..5df33de42e 100644
@@ -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);
 
t/t1900-repo.sh +12 -0
index a69c715357..3df55dcc79 100755
@@ -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
Signature · 1 line
2.39.5 (Apple Git-154)
#25 lore raw

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

Quoted 3 lines · Lucas Seiki Oshiro

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.

Quoted 21 lines

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

builtin/repo.c +3 -1
index 8c6e7f42ab..5df33de42e 100644
@@ -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()
 	};

builtin/repo.c static int print_fields(int argc, const char **argv, · line 133

Quoted 10 lines
builtin/repo.c +2 -3
 
 	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.

builtin/repo.c static int print_fields(int argc, const char **argv, · line 133

Quoted 1 line
builtin/repo.c +1 -0
+	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.

builtin/repo.c static int print_fields(int argc, const char **argv, · line 140

Quoted 6 lines
builtin/repo.c +3 -0
+	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?

#26 lore raw

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

Quoted 6 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...

Quoted 7 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!

#27 lore raw

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

In reply to Lucas Seiki Oshiro

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.

---
 Documentation/git-repo.adoc | 3 +++
 builtin/repo.c              | 7 +++++++
 t/t1900-repo.sh             | 6 ++++++
 3 files changed, 16 insertions(+)
Documentation/git-repo.adoc +3 -0
index 8224a88bc8..2f9d696572 100644
@@ -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:
 +
builtin/repo.c +7 -0
index 5df33de42e..5c900d683e 100644
@@ -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 },
 };
 
t/t1900-repo.sh +6 -0
index 3df55dcc79..a83139f7ff 100755
@@ -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
Signature · 1 line
2.39.5 (Apple Git-154)
#28 lore raw

v3 cover repo: add -z and objects.format

In reply to Lucas Seiki Oshiro

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(-)
Signature · 1 line
2.39.5 (Apple Git-154)
#29 lore raw

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.

---
 Documentation/git-repo.adoc |  6 ++++--
 builtin/repo.c              | 37 +++++++++++++++++++++++++------------
 t/t1900-repo.sh             | 12 ++++++++++++
 3 files changed, 41 insertions(+), 14 deletions(-)
Documentation/git-repo.adoc +4 -2
index 2870828d93..6f5ee88215 100644
@@ -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
 ---------
builtin/repo.c +25 -12
index 8c6e7f42ab..13a34f68a5 100644
@@ -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);
 }
 
t/t1900-repo.sh +12 -0
index a69c715357..ddf788d5a2 100755
@@ -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
Signature · 1 line
2.39.5 (Apple Git-154)
#30 lore raw

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

Quoted 21 lines · Lucas Seiki Oshiro

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.

---
 Documentation/git-repo.adoc |  6 ++++--
 builtin/repo.c              | 37 +++++++++++++++++++++++++------------
 t/t1900-repo.sh             | 12 ++++++++++++
 3 files changed, 41 insertions(+), 14 deletions(-)
Documentation/git-repo.adoc +0 -0
index 2870828d93..6f5ee88215 100644

Documentation/git-repo.adoc git-repo - Retrieve information about the repository · line 11

Quoted 5 lines
Documentation/git-repo.adoc +1 -1
@@ -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.

#31 lore raw

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

Quoted 10 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!

Quoted 1 line

The updated option parsing looks much nicer. Thanks.

Thanks, Junio!

#32 lore raw

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

In reply to Lucas Seiki Oshiro

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.

---
 Documentation/git-repo.adoc | 3 +++
 builtin/repo.c              | 7 +++++++
 t/t1900-repo.sh             | 6 ++++++
 3 files changed, 16 insertions(+)
Documentation/git-repo.adoc +3 -0
index 6f5ee88215..209afd1b61 100644
@@ -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:
 +
builtin/repo.c +7 -0
index 13a34f68a5..9b519426fe 100644
@@ -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 },
 };
 
t/t1900-repo.sh +6 -0
index ddf788d5a2..2beba67889 100755
@@ -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
Signature · 1 line
2.39.5 (Apple Git-154)
#33 lore raw

v4 cover repo: add -z and objects.format

In reply to Lucas Seiki Oshiro

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(-)
Signature · 1 line
2.39.5 (Apple Git-154)
#34 lore raw

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.

---
 Documentation/git-repo.adoc |  6 ++++--
 builtin/repo.c              | 38 +++++++++++++++++++++++++------------
 t/t1900-repo.sh             | 12 ++++++++++++
 3 files changed, 42 insertions(+), 14 deletions(-)
Documentation/git-repo.adoc +4 -2
index 2870828d93..6f5ee88215 100644
@@ -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
 ---------
builtin/repo.c +26 -12
index 8c6e7f42ab..dc9a267469 100644
@@ -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);
 }
 
t/t1900-repo.sh +12 -0
index a69c715357..ddf788d5a2 100755
@@ -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
Signature · 1 line
2.39.5 (Apple Git-154)
#35 lore raw

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

In reply to Lucas Seiki Oshiro

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.

---
 Documentation/git-repo.adoc | 3 +++
 builtin/repo.c              | 7 +++++++
 t/t1900-repo.sh             | 6 ++++++
 3 files changed, 16 insertions(+)
Documentation/git-repo.adoc +3 -0
index 6f5ee88215..209afd1b61 100644
@@ -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:
 +
builtin/repo.c +7 -0
index dc9a267469..bbb0966f2d 100644
@@ -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 },
 };
 
t/t1900-repo.sh +6 -0
index ddf788d5a2..2beba67889 100755
@@ -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
Signature · 1 line
2.39.5 (Apple Git-154)
#36 lore raw
In reply to Lucas Seiki Oshiro
Quoted 4 lines · Lucas Seiki Oshiro

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'.

Quoted 33 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(-)