git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] repo: add new flag --keys to git-repo-info
@ 2025-12-07 19:02 Lucas Seiki Oshiro
  2025-12-07 22:14 ` Junio C Hamano
                   ` (5 more replies)
  0 siblings, 6 replies; 19+ messages in thread
From: Lucas Seiki Oshiro @ 2025-12-07 19:02 UTC (permalink / raw)
  To: git; +Cc: Lucas Seiki Oshiro

Currently, if the user wants to find what are the available keys,
they need to either check the documentation or to ask to all the
key-value pairs by using --all.

Add a new flag --keys for listing only the available keys without
listing the values.

Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---

Hi!

After the Junio's suggestion [1], this patch adds a new flag --keys to
git-repo-info. This new flag only prints the available keys, without
printing the corresponding values.

This patch is based on top of master bdc5341ff6 (The sixth batch,
2025-12-05) with lo/repo-struct-z merged.

[1] https://lore.kernel.org/git/xmqq8qg3do99.fsf@gitster.g/

 Documentation/git-repo.adoc |  4 ++++
 builtin/repo.c              | 17 +++++++++++++++++
 t/t1900-repo.sh             | 13 ++-----------
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index c4a78277df..f0f4d77db8 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -9,6 +9,7 @@ SYNOPSIS
 --------
 [synopsis]
 git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
+git repo info --keys
 git repo structure [--format=(table|keyvalue|nul) | -z]
 
 DESCRIPTION
@@ -44,6 +45,9 @@ supported:
 +
 `-z` is an alias for `--format=nul`.
 
+`info --keys`::
+List all the available keys, one per line.
+
 `structure [--format=(table|keyvalue|nul) | -z]`::
 	Retrieve statistics about the current repository structure. The
 	following kinds of information are reported:
diff --git a/builtin/repo.c b/builtin/repo.c
index 0dd41b1778..45e9d59d55 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -16,6 +16,7 @@
 
 static const char *const repo_usage[] = {
 	"git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
+	"git repo info --keys",
 	"git repo structure [--format=(table|keyvalue|nul) | -z]",
 	NULL
 };
@@ -146,6 +147,16 @@ static int print_all_fields(struct repository *repo,
 	return 0;
 }
 
+static int print_keys(void)
+{
+	for (size_t i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
+		const struct field *field = &repo_info_fields[i];
+		puts(field->key);
+	}
+
+	return 0;
+}
+
 static int parse_format_cb(const struct option *opt,
 			   const char *arg, int unset UNUSED)
 {
@@ -170,6 +181,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
 {
 	enum output_format format = FORMAT_KEYVALUE;
 	int all_keys = 0;
+	int show_keys = 0;
 	struct option options[] = {
 		OPT_CALLBACK_F(0, "format", &format, N_("format"),
 			       N_("output format"),
@@ -179,10 +191,15 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
 			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
 			       parse_format_cb),
 		OPT_BOOL(0, "all", &all_keys, N_("print all keys/values")),
+		OPT_BOOL(0, "keys", &show_keys, N_("show keys")),
 		OPT_END()
 	};
 
 	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+
+	if (show_keys)
+		return print_keys();
+
 	if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
 		die(_("unsupported output format"));
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 51d55f11a5..d6e84a78e5 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -4,15 +4,6 @@ test_description='test git repo-info'
 
 . ./test-lib.sh
 
-# git-repo-info keys. It must contain the same keys listed in the const
-# repo_info_fields, in lexicographical order.
-REPO_INFO_KEYS='
-	layout.bare
-	layout.shallow
-	object.format
-	references.format
-'
-
 # Test whether a key-value pair is correctly returned
 #
 # Usage: test_repo_info <label> <init command> <repo_name> <key> <expected value>
@@ -119,8 +110,8 @@ test_expect_success 'git repo info uses the last requested format' '
 	test_cmp expected actual
 '
 
-test_expect_success 'git repo info --all returns all key-value pairs' '
-	git repo info $REPO_INFO_KEYS >expect &&
+test_expect_success 'git repo info --all and git repo info $(git repo info --keys) output the same data' '
+	git repo info $(git repo info --keys) >expect &&
 	git repo info --all >actual &&
 	test_cmp expect actual
 '
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH] repo: add new flag --keys to git-repo-info
  2025-12-07 19:02 [PATCH] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
@ 2025-12-07 22:14 ` Junio C Hamano
  2025-12-08 16:33   ` Lucas Seiki Oshiro
  2025-12-08  7:13 ` Patrick Steinhardt
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 19+ messages in thread
From: Junio C Hamano @ 2025-12-07 22:14 UTC (permalink / raw)
  To: Lucas Seiki Oshiro; +Cc: git

Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:

> Currently, if the user wants to find what are the available keys,
> they need to either check the documentation or to ask to all the
> key-value pairs by using --all.
>
> Add a new flag --keys for listing only the available keys without
> listing the values.

We do not need to say "Currently," but other than that the above is
very well written.  Easy to grok and to the point.

>  [synopsis]
>  git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
> +git repo info --keys
>  git repo structure [--format=(table|keyvalue|nul) | -z]

So "git repo info --keys --all" or "git repo info --keys --format=..."
is not supported.  Does the implementation behave sensibly when given
such nonsense commands?  Let's see.

> @@ -170,6 +181,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
>  {
>  	enum output_format format = FORMAT_KEYVALUE;
>  	int all_keys = 0;
> +	int show_keys = 0;
>  	struct option options[] = {
>  		OPT_CALLBACK_F(0, "format", &format, N_("format"),
>  			       N_("output format"),
> @@ -179,10 +191,15 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
>  			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
>  			       parse_format_cb),
>  		OPT_BOOL(0, "all", &all_keys, N_("print all keys/values")),
> +		OPT_BOOL(0, "keys", &show_keys, N_("show keys")),
>  		OPT_END()
>  	};
>  
>  	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
> +
> +	if (show_keys)
> +		return print_keys();
> +
>  	if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
>  		die(_("unsupported output format"));

OK, so it is:

    "git repo info --all --keys" and "git repo info --keys layout.bare"
    both behave as if "git repo --keys" was given, ignoring
    everything else.

Shouldn't "--keys" be explicitly marked incompatible with "--all"
and remaining keys in argc/argv[]?

While there is no strong reason why anybody must use NUL-terminated
output format, simply because repo_info_fields[] contains no tokens
with strange byte values, but just as principle, shouldn't

    "git repo info --keys -z"

do what is naturally expected?

Perhaps

	if (format != ...)
		die(_("unsupported output format"));

	if (show_keys && (all_keys || argc))
		die(_("--keys cannot be used with a <key> or --all"));

	if (show_keys)
		return print_keys(output_format);

with a trivial update to print_keys() to support NUL-terminated
records, instead of puts()?

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] repo: add new flag --keys to git-repo-info
  2025-12-07 19:02 [PATCH] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
  2025-12-07 22:14 ` Junio C Hamano
@ 2025-12-08  7:13 ` Patrick Steinhardt
  2025-12-09 19:36 ` [PATCH v2 0/2] " Lucas Seiki Oshiro
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 19+ messages in thread
From: Patrick Steinhardt @ 2025-12-08  7:13 UTC (permalink / raw)
  To: Lucas Seiki Oshiro; +Cc: git

On Sun, Dec 07, 2025 at 04:02:10PM -0300, Lucas Seiki Oshiro wrote:
> Currently, if the user wants to find what are the available keys,
> they need to either check the documentation or to ask to all the

This sentence doesn't quite parse. I think you wanted to say "ask for
all" instead of "ask to all" here.

All the other points were already covered by Junio, so I won't comment
on these parts.

Thanks!

Patrick

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] repo: add new flag --keys to git-repo-info
  2025-12-07 22:14 ` Junio C Hamano
@ 2025-12-08 16:33   ` Lucas Seiki Oshiro
  0 siblings, 0 replies; 19+ messages in thread
From: Lucas Seiki Oshiro @ 2025-12-08 16:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Patrick Steinhardt


> We do not need to say "Currently," but other than that the above is
> very well written.  Easy to grok and to the point.

Thanks!

> Shouldn't "--keys" be explicitly marked incompatible with "--all"
> and remaining keys in argc/argv[]?

Yes, I'll work on that.

> While there is no strong reason why anybody must use NUL-terminated
> output format, simply because repo_info_fields[] contains no tokens
> with strange byte values, but just as principle, shouldn't
> 
>    "git repo info --keys -z"
> 
> do what is naturally expected?

Hmmm... Perhaps it's too much for this simple flag. `-z` is tied to
--format here, and if we want to support -z we'll also need to 
support --format.

What about adding a "default" format for --format? This way, it
would translate to:

- keyvalue, when using info without --keys
- table, when using structure
- using puts, when using info with --keys

Another solution, of course, would be aborting when --format, -z or
--all are used with --keys.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v2 0/2] repo: add new flag --keys to git-repo-info
  2025-12-07 19:02 [PATCH] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
  2025-12-07 22:14 ` Junio C Hamano
  2025-12-08  7:13 ` Patrick Steinhardt
@ 2025-12-09 19:36 ` Lucas Seiki Oshiro
  2025-12-09 19:36   ` [PATCH v2 1/2] repo: add a default output format to enum output_format Lucas Seiki Oshiro
                     ` (2 more replies)
  2026-01-09 20:31 ` [PATCH v3 0/2] repo: add --format=default and --keys Lucas Seiki Oshiro
                   ` (2 subsequent siblings)
  5 siblings, 3 replies; 19+ messages in thread
From: Lucas Seiki Oshiro @ 2025-12-09 19:36 UTC (permalink / raw)
  To: git; +Cc: ps, Lucas Seiki Oshiro

Hi!

This patch series adds a new flag --keys to git-repo-info. This new flag
only prints the available keys, without printing the corresponding
values.

The main change in this version is the compatibility with the flags -z
and --format, allowing the keys to be printed following the
null-terminated format.

This patch is based on top of master bdc5341ff6 (The sixth batch, 
2025-12-05) with lo/repo-struct-z merged.

Lucas Seiki Oshiro (2):
  repo: add a default output format to enum output_format
  repo: add new flag --keys to git-repo-info

 Documentation/git-repo.adoc | 11 ++++++++++
 builtin/repo.c              | 41 ++++++++++++++++++++++++++++++++++++-
 t/t1900-repo.sh             | 33 +++++++++++++++++++----------
 3 files changed, 73 insertions(+), 12 deletions(-)

Range-diff against v1:
-:  ---------- > 1:  9eb2549806 repo: add a default output format to enum output_format
1:  1b9b7dceb7 ! 2:  c5b7ba8824 repo: add new flag --keys to git-repo-info
    @@ Metadata
      ## Commit message ##
         repo: add new flag --keys to git-repo-info
     
    -    Currently, if the user wants to find what are the available keys,
    -    they need to either check the documentation or to ask to all the
    -    key-value pairs by using --all.
    +    If the user wants to find what are the available keys, they need to
    +    either check the documentation or to ask for all the key-value pairs
    +    by using --all.
     
         Add a new flag --keys for listing only the available keys without
         listing the values.
    @@ Documentation/git-repo.adoc: SYNOPSIS
      --------
      [synopsis]
      git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
    -+git repo info --keys
    ++git repo info --keys [--format=(default|nul) | -z]
      git repo structure [--format=(table|keyvalue|nul) | -z]
      
      DESCRIPTION
    @@ Documentation/git-repo.adoc: supported:
      +
      `-z` is an alias for `--format=nul`.
      
    -+`info --keys`::
    -+List all the available keys, one per line.
    ++`info --keys [--format=(default|nul) | -z]`::
    ++	List all the available keys, one per line. The output format can be chosen
    ++	through the flag `--format`. The following formats are supported:
    +++
    ++`default`:::
    ++	output the keys one per line.
    ++
    ++`nul`:::
    ++	similar to `default`, but using a NUL character after each value.
     +
      `structure [--format=(table|keyvalue|nul) | -z]`::
      	Retrieve statistics about the current repository structure. The
    @@ builtin/repo.c
      
      static const char *const repo_usage[] = {
      	"git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
    -+	"git repo info --keys",
    ++	"git repo info --keys [--format=(default|nul) | -z]",
      	"git repo structure [--format=(table|keyvalue|nul) | -z]",
      	NULL
      };
    @@ builtin/repo.c: static int print_all_fields(struct repository *repo,
      	return 0;
      }
      
    -+static int print_keys(void)
    ++static int print_keys(enum output_format format)
     +{
    ++	char sep;
    ++
    ++	switch (format) {
    ++	case FORMAT_DEFAULT:
    ++		sep = '\n';
    ++		break;
    ++	case FORMAT_NUL_TERMINATED:
    ++		sep = '\0';
    ++		break;
    ++	default:
    ++		die(_("--keys can only be used with --format=default or --format=nul"));
    ++	}
    ++
     +	for (size_t i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
     +		const struct field *field = &repo_info_fields[i];
    -+		puts(field->key);
    ++		printf("%s%c", field->key, sep);
     +	}
     +
     +	return 0;
    @@ builtin/repo.c: static int print_all_fields(struct repository *repo,
      {
     @@ builtin/repo.c: static int cmd_repo_info(int argc, const char **argv, const char *prefix,
      {
    - 	enum output_format format = FORMAT_KEYVALUE;
    + 	enum output_format format = FORMAT_DEFAULT;
      	int all_keys = 0;
     +	int show_keys = 0;
      	struct option options[] = {
    @@ builtin/repo.c: static int cmd_repo_info(int argc, const char **argv, const char
      	};
      
      	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
    + 
    ++	if (show_keys && (all_keys || argc))
    ++		die(_("--keys cannot be used with a <key> or --all"));
     +
     +	if (show_keys)
    -+		return print_keys();
    ++		return print_keys(format);
     +
    - 	if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
    - 		die(_("unsupported output format"));
    + 	if (format == FORMAT_DEFAULT)
    + 		format = FORMAT_KEYVALUE;
      
     
      ## t/t1900-repo.sh ##
    @@ t/t1900-repo.sh: test_expect_success 'git repo info uses the last requested form
      	git repo info --all >actual &&
      	test_cmp expect actual
      '
    +@@ t/t1900-repo.sh: test_expect_success 'git repo info --all <key> aborts' '
    + 	test_cmp expect actual
    + '
    + 
    ++test_expect_success 'git repo info --keys --format=nul uses nul-terminated output' '
    ++	git repo info --keys --format=default >default &&
    ++	lf_to_nul <default > expect &&
    ++	git repo info --keys --format=nul >actual &&
    ++	test_cmp expect actual
    ++'
    ++
    ++test_expect_success 'git repo info --keys aborts when using --format other than default or nul' '
    ++	echo "fatal: --keys can only be used with --format=default or --format=nul" >expect &&
    ++	test_must_fail git repo info --keys --format=keyvalue 2>actual &&
    ++	test_cmp expect actual
    ++'
    ++
    ++test_expect_success 'git repo info --keys aborts when requesting keys' '
    ++	echo "fatal: --keys cannot be used with a <key> or --all" >expect &&
    ++	test_must_fail git repo info --keys --all 2>actual_all &&
    ++	test_must_fail git repo info --keys some.key 2>actual_key &&
    ++	test_cmp expect actual_all &&
    ++	test_cmp expect actual_key
    ++'
    + test_done
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v2 1/2] repo: add a default output format to enum output_format
  2025-12-09 19:36 ` [PATCH v2 0/2] " Lucas Seiki Oshiro
@ 2025-12-09 19:36   ` Lucas Seiki Oshiro
  2026-01-05 14:18     ` Patrick Steinhardt
  2025-12-09 19:36   ` [PATCH v2 2/2] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
  2026-01-05 13:57   ` [PATCH v2 0/2] " Lucas Seiki Oshiro
  2 siblings, 1 reply; 19+ messages in thread
From: Lucas Seiki Oshiro @ 2025-12-09 19:36 UTC (permalink / raw)
  To: git; +Cc: ps, Lucas Seiki Oshiro

Add a `FORMAT_DEFAULT` value to `enum output_format`. Change the initial
value of `format` to `FORMAT_DEFAULT` in cmd_repo_info, indicating that
the initial value hasn't been changed. Also map the string "default" to
this new value in `parse_format_cb`, allowing future patches to add
support to --format=default.

Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 builtin/repo.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/builtin/repo.c b/builtin/repo.c
index 0dd41b1778..1cd12e7eea 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -23,6 +23,7 @@ static const char *const repo_usage[] = {
 typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
 
 enum output_format {
+	FORMAT_DEFAULT,
 	FORMAT_TABLE,
 	FORMAT_KEYVALUE,
 	FORMAT_NUL_TERMINATED,
@@ -159,6 +160,8 @@ static int parse_format_cb(const struct option *opt,
 		*format = FORMAT_KEYVALUE;
 	else if (!strcmp(arg, "table"))
 		*format = FORMAT_TABLE;
+	else if (!strcmp(arg, "default"))
+		*format = FORMAT_DEFAULT;
 	else
 		die(_("invalid format '%s'"), arg);
 
@@ -168,7 +171,7 @@ static int parse_format_cb(const struct option *opt,
 static int cmd_repo_info(int argc, const char **argv, const char *prefix,
 			 struct repository *repo)
 {
-	enum output_format format = FORMAT_KEYVALUE;
+	enum output_format format = FORMAT_DEFAULT;
 	int all_keys = 0;
 	struct option options[] = {
 		OPT_CALLBACK_F(0, "format", &format, N_("format"),
@@ -183,6 +186,10 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
 	};
 
 	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+
+	if (format == FORMAT_DEFAULT)
+		format = FORMAT_KEYVALUE;
+
 	if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
 		die(_("unsupported output format"));
 
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 2/2] repo: add new flag --keys to git-repo-info
  2025-12-09 19:36 ` [PATCH v2 0/2] " Lucas Seiki Oshiro
  2025-12-09 19:36   ` [PATCH v2 1/2] repo: add a default output format to enum output_format Lucas Seiki Oshiro
@ 2025-12-09 19:36   ` Lucas Seiki Oshiro
  2026-01-05 14:18     ` Patrick Steinhardt
  2026-01-05 13:57   ` [PATCH v2 0/2] " Lucas Seiki Oshiro
  2 siblings, 1 reply; 19+ messages in thread
From: Lucas Seiki Oshiro @ 2025-12-09 19:36 UTC (permalink / raw)
  To: git; +Cc: ps, Lucas Seiki Oshiro

If the user wants to find what are the available keys, they need to
either check the documentation or to ask for all the key-value pairs
by using --all.

Add a new flag --keys for listing only the available keys without
listing the values.

Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 Documentation/git-repo.adoc | 11 +++++++++++
 builtin/repo.c              | 32 ++++++++++++++++++++++++++++++++
 t/t1900-repo.sh             | 33 ++++++++++++++++++++++-----------
 3 files changed, 65 insertions(+), 11 deletions(-)

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index c4a78277df..fd0683631c 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -9,6 +9,7 @@ SYNOPSIS
 --------
 [synopsis]
 git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
+git repo info --keys [--format=(default|nul) | -z]
 git repo structure [--format=(table|keyvalue|nul) | -z]
 
 DESCRIPTION
@@ -44,6 +45,16 @@ supported:
 +
 `-z` is an alias for `--format=nul`.
 
+`info --keys [--format=(default|nul) | -z]`::
+	List all the available keys, one per line. The output format can be chosen
+	through the flag `--format`. The following formats are supported:
++
+`default`:::
+	output the keys one per line.
+
+`nul`:::
+	similar to `default`, but using a NUL character after each value.
+
 `structure [--format=(table|keyvalue|nul) | -z]`::
 	Retrieve statistics about the current repository structure. The
 	following kinds of information are reported:
diff --git a/builtin/repo.c b/builtin/repo.c
index 1cd12e7eea..48341f9245 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -16,6 +16,7 @@
 
 static const char *const repo_usage[] = {
 	"git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
+	"git repo info --keys [--format=(default|nul) | -z]",
 	"git repo structure [--format=(table|keyvalue|nul) | -z]",
 	NULL
 };
@@ -147,6 +148,29 @@ static int print_all_fields(struct repository *repo,
 	return 0;
 }
 
+static int print_keys(enum output_format format)
+{
+	char sep;
+
+	switch (format) {
+	case FORMAT_DEFAULT:
+		sep = '\n';
+		break;
+	case FORMAT_NUL_TERMINATED:
+		sep = '\0';
+		break;
+	default:
+		die(_("--keys can only be used with --format=default or --format=nul"));
+	}
+
+	for (size_t i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
+		const struct field *field = &repo_info_fields[i];
+		printf("%s%c", field->key, sep);
+	}
+
+	return 0;
+}
+
 static int parse_format_cb(const struct option *opt,
 			   const char *arg, int unset UNUSED)
 {
@@ -173,6 +197,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
 {
 	enum output_format format = FORMAT_DEFAULT;
 	int all_keys = 0;
+	int show_keys = 0;
 	struct option options[] = {
 		OPT_CALLBACK_F(0, "format", &format, N_("format"),
 			       N_("output format"),
@@ -182,11 +207,18 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
 			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
 			       parse_format_cb),
 		OPT_BOOL(0, "all", &all_keys, N_("print all keys/values")),
+		OPT_BOOL(0, "keys", &show_keys, N_("show keys")),
 		OPT_END()
 	};
 
 	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
 
+	if (show_keys && (all_keys || argc))
+		die(_("--keys cannot be used with a <key> or --all"));
+
+	if (show_keys)
+		return print_keys(format);
+
 	if (format == FORMAT_DEFAULT)
 		format = FORMAT_KEYVALUE;
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 51d55f11a5..e8802413a6 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -4,15 +4,6 @@ test_description='test git repo-info'
 
 . ./test-lib.sh
 
-# git-repo-info keys. It must contain the same keys listed in the const
-# repo_info_fields, in lexicographical order.
-REPO_INFO_KEYS='
-	layout.bare
-	layout.shallow
-	object.format
-	references.format
-'
-
 # Test whether a key-value pair is correctly returned
 #
 # Usage: test_repo_info <label> <init command> <repo_name> <key> <expected value>
@@ -119,8 +110,8 @@ test_expect_success 'git repo info uses the last requested format' '
 	test_cmp expected actual
 '
 
-test_expect_success 'git repo info --all returns all key-value pairs' '
-	git repo info $REPO_INFO_KEYS >expect &&
+test_expect_success 'git repo info --all and git repo info $(git repo info --keys) output the same data' '
+	git repo info $(git repo info --keys) >expect &&
 	git repo info --all >actual &&
 	test_cmp expect actual
 '
@@ -131,4 +122,24 @@ test_expect_success 'git repo info --all <key> aborts' '
 	test_cmp expect actual
 '
 
+test_expect_success 'git repo info --keys --format=nul uses nul-terminated output' '
+	git repo info --keys --format=default >default &&
+	lf_to_nul <default > expect &&
+	git repo info --keys --format=nul >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'git repo info --keys aborts when using --format other than default or nul' '
+	echo "fatal: --keys can only be used with --format=default or --format=nul" >expect &&
+	test_must_fail git repo info --keys --format=keyvalue 2>actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'git repo info --keys aborts when requesting keys' '
+	echo "fatal: --keys cannot be used with a <key> or --all" >expect &&
+	test_must_fail git repo info --keys --all 2>actual_all &&
+	test_must_fail git repo info --keys some.key 2>actual_key &&
+	test_cmp expect actual_all &&
+	test_cmp expect actual_key
+'
 test_done
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 0/2] repo: add new flag --keys to git-repo-info
  2025-12-09 19:36 ` [PATCH v2 0/2] " Lucas Seiki Oshiro
  2025-12-09 19:36   ` [PATCH v2 1/2] repo: add a default output format to enum output_format Lucas Seiki Oshiro
  2025-12-09 19:36   ` [PATCH v2 2/2] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
@ 2026-01-05 13:57   ` Lucas Seiki Oshiro
  2026-01-05 14:19     ` Patrick Steinhardt
  2 siblings, 1 reply; 19+ messages in thread
From: Lucas Seiki Oshiro @ 2026-01-05 13:57 UTC (permalink / raw)
  To: git; +Cc: ps, Junio C Hamano

Hello, everyone, and happy new year!

Sorry to bother you with this, but do you have any comments about this
patch?

Thanks!

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 2/2] repo: add new flag --keys to git-repo-info
  2025-12-09 19:36   ` [PATCH v2 2/2] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
@ 2026-01-05 14:18     ` Patrick Steinhardt
  0 siblings, 0 replies; 19+ messages in thread
From: Patrick Steinhardt @ 2026-01-05 14:18 UTC (permalink / raw)
  To: Lucas Seiki Oshiro; +Cc: git

On Tue, Dec 09, 2025 at 04:36:03PM -0300, Lucas Seiki Oshiro wrote:
> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> index c4a78277df..fd0683631c 100644
> --- a/Documentation/git-repo.adoc
> +++ b/Documentation/git-repo.adoc
> @@ -9,6 +9,7 @@ SYNOPSIS
>  --------
>  [synopsis]
>  git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
> +git repo info --keys [--format=(default|nul) | -z]
>  git repo structure [--format=(table|keyvalue|nul) | -z]
>  
>  DESCRIPTION

The synopsis should have been updated in the preceding commit to mention
"default" for `git repo info`.

> @@ -131,4 +122,24 @@ test_expect_success 'git repo info --all <key> aborts' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'git repo info --keys --format=nul uses nul-terminated output' '
> +	git repo info --keys --format=default >default &&
> +	lf_to_nul <default > expect &&

Style nit: there shouldn't be a space between "> expect".

Patrick

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 1/2] repo: add a default output format to enum output_format
  2025-12-09 19:36   ` [PATCH v2 1/2] repo: add a default output format to enum output_format Lucas Seiki Oshiro
@ 2026-01-05 14:18     ` Patrick Steinhardt
  2026-01-07 21:28       ` Lucas Seiki Oshiro
  0 siblings, 1 reply; 19+ messages in thread
From: Patrick Steinhardt @ 2026-01-05 14:18 UTC (permalink / raw)
  To: Lucas Seiki Oshiro; +Cc: git

On Tue, Dec 09, 2025 at 04:36:02PM -0300, Lucas Seiki Oshiro wrote:
> Add a `FORMAT_DEFAULT` value to `enum output_format`. Change the initial
> value of `format` to `FORMAT_DEFAULT` in cmd_repo_info, indicating that
> the initial value hasn't been changed. Also map the string "default" to
> this new value in `parse_format_cb`, allowing future patches to add
> support to --format=default.

This is missing a test. It would for example be nice to verify that
"--format=nul --format=default" does the expected thing.

Also, I didn't see `git repo structure` being updated. Should we do that
so that both subcommands know to handle the "default" format?

Patrick

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 0/2] repo: add new flag --keys to git-repo-info
  2026-01-05 13:57   ` [PATCH v2 0/2] " Lucas Seiki Oshiro
@ 2026-01-05 14:19     ` Patrick Steinhardt
  0 siblings, 0 replies; 19+ messages in thread
From: Patrick Steinhardt @ 2026-01-05 14:19 UTC (permalink / raw)
  To: Lucas Seiki Oshiro; +Cc: git, Junio C Hamano

Hi Lucas,

On Mon, Jan 05, 2026 at 10:57:23AM -0300, Lucas Seiki Oshiro wrote:
> Hello, everyone, and happy new year!
> 
> Sorry to bother you with this, but do you have any comments about this
> patch?

no need to be sorry, I lost track of this series and didn't have it on
my radar anymore. I've left some comments now, thanks!

Patrick

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 1/2] repo: add a default output format to enum output_format
  2026-01-05 14:18     ` Patrick Steinhardt
@ 2026-01-07 21:28       ` Lucas Seiki Oshiro
  2026-01-08  6:13         ` Patrick Steinhardt
  0 siblings, 1 reply; 19+ messages in thread
From: Lucas Seiki Oshiro @ 2026-01-07 21:28 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: git


> This is missing a test.

Indeed, I'll add a test for `--format=default`.

> It would for example be nice to verify that
> "--format=nul --format=default" does the expected thing.

Would it be necessary? We already have a test asserting that the
last "--format" wins:

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
'

> Also, I didn't see `git repo structure` being updated. Should we do that
> so that both subcommands know to handle the "default" format?

Sure! I'll do that!

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 1/2] repo: add a default output format to enum output_format
  2026-01-07 21:28       ` Lucas Seiki Oshiro
@ 2026-01-08  6:13         ` Patrick Steinhardt
  0 siblings, 0 replies; 19+ messages in thread
From: Patrick Steinhardt @ 2026-01-08  6:13 UTC (permalink / raw)
  To: Lucas Seiki Oshiro; +Cc: git

On Wed, Jan 07, 2026 at 06:28:59PM -0300, Lucas Seiki Oshiro wrote:
> 
> > This is missing a test.
> 
> Indeed, I'll add a test for `--format=default`.
> 
> > It would for example be nice to verify that
> > "--format=nul --format=default" does the expected thing.
> 
> Would it be necessary? We already have a test asserting that the
> last "--format" wins:
> 
> 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
> '

Yup, but we don't have any test that verifies we do the right thing when
the user asks for the default format. So it's mostly an additional check
that the default format can be requested as expected, which would in the
normal case be a no-op as, well, it's the default. So if you specify a
different format before we verify that it can reset to the default.

Patrick

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v3 0/2] repo: add --format=default and --keys
  2025-12-07 19:02 [PATCH] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
                   ` (2 preceding siblings ...)
  2025-12-09 19:36 ` [PATCH v2 0/2] " Lucas Seiki Oshiro
@ 2026-01-09 20:31 ` Lucas Seiki Oshiro
  2026-01-10  6:48   ` Junio C Hamano
  2026-01-09 20:31 ` [PATCH v3 1/2] repo: add a default output format to enum output_format Lucas Seiki Oshiro
  2026-01-09 20:31 ` [PATCH v3 2/2] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
  5 siblings, 1 reply; 19+ messages in thread
From: Lucas Seiki Oshiro @ 2026-01-09 20:31 UTC (permalink / raw)
  To: git; +Cc: ps, gitster, jltobler, Lucas Seiki Oshiro

Hi!

The main change in this version is that git-repo-structure now supports
`--format=default`. This way, both git-repo-info and git-repo-structure
now can be used with `--format=default`, which resets the output format
to the default one (`keyvalue` in repo-info, `table` in repo-structure).

I'm also cc'ing Justin to see if he agrees with this change to
git-repo-structure.

Lucas Seiki Oshiro (2):
  repo: add a default output format to enum output_format
  repo: add new flag --keys to git-repo-info

 Documentation/git-repo.adoc | 30 ++++++++++++++++------
 builtin/repo.c              | 50 ++++++++++++++++++++++++++++++++++---
 t/t1900-repo.sh             | 46 ++++++++++++++++++++++++++--------
 t/t1901-repo-structure.sh   | 22 ++++++++++++++++
 4 files changed, 126 insertions(+), 22 deletions(-)

Range-diff against v2:
1:  9eb2549806 ! 1:  97f8eee687 repo: add a default output format to enum output_format
    @@ Metadata
      ## Commit message ##
         repo: add a default output format to enum output_format
     
    -    Add a `FORMAT_DEFAULT` value to `enum output_format`. Change the initial
    -    value of `format` to `FORMAT_DEFAULT` in cmd_repo_info, indicating that
    -    the initial value hasn't been changed. Also map the string "default" to
    -    this new value in `parse_format_cb`, allowing future patches to add
    -    support to --format=default.
    +    Add "default" as an option for --format in both git-repo-info and
    +    git-repo-structure. Using `--format=default` makes those commands use
    +    their default output format.
     
         Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
     
    + ## Documentation/git-repo.adoc ##
    +@@ Documentation/git-repo.adoc: git-repo - Retrieve information about the repository
    + SYNOPSIS
    + --------
    + [synopsis]
    +-git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
    +-git repo structure [--format=(table|keyvalue|nul) | -z]
    ++git repo info [--format=(default|keyvalue|nul) | -z] [--all | <key>...]
    ++git repo structure [--format=(default|table|keyvalue|nul) | -z]
    + 
    + DESCRIPTION
    + -----------
    +@@ Documentation/git-repo.adoc: THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
    + 
    + COMMANDS
    + --------
    +-`info [--format=(keyvalue|nul) | -z] [--all | <key>...]`::
    ++`info [--format=(default|keyvalue|nul) | -z] [--all | <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).
    +@@ Documentation/git-repo.adoc: requested. The `--all` flag requests the values for all the available keys.
    + The output format can be chosen through the flag `--format`. Two formats are
    + supported:
    + +
    ++`default`:::
    ++	synonym for `keyvalue`.
    ++
    + `keyvalue`:::
    + 	output key-value pairs one per line using the `=` character as
    + 	the delimiter between the key and the value. Values containing "unusual"
    + 	characters are quoted as explained for the configuration variable
    +-	`core.quotePath` (see linkgit:git-config[1]). This is the default.
    ++	`core.quotePath` (see linkgit:git-config[1]).
    + 
    + `nul`:::
    + 	similar to `keyvalue`, but using a newline character as the delimiter
    +@@ Documentation/git-repo.adoc: supported:
    + +
    + `-z` is an alias for `--format=nul`.
    + 
    +-`structure [--format=(table|keyvalue|nul) | -z]`::
    ++`structure [--format=(default|table|keyvalue|nul) | -z]`::
    + 	Retrieve statistics about the current repository structure. The
    + 	following kinds of information are reported:
    + +
    +@@ Documentation/git-repo.adoc: supported:
    + The output format can be chosen through the flag `--format`. Three formats are
    + supported:
    + +
    ++`default`:::
    ++	synonym for `table`.
    ++
    + `table`:::
    + 	Outputs repository stats in a human-friendly table. This format may
    +-	change and is not intended for machine parsing. This is the default
    +-	format.
    ++	change and is not intended for machine parsing.
    + 
    + `keyvalue`:::
    + 	Each line of output contains a key-value pair for a repository stat.
    +
      ## builtin/repo.c ##
    -@@ builtin/repo.c: static const char *const repo_usage[] = {
    +@@
    + #include "utf8.h"
    + 
    + static const char *const repo_usage[] = {
    +-	"git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
    +-	"git repo structure [--format=(table|keyvalue|nul) | -z]",
    ++	"git repo info [--format=(default|keyvalue|nul) | -z] [--all | <key>...]",
    ++	"git repo structure [--format=(default|table|keyvalue|nul) | -z]",
    + 	NULL
    + };
    + 
      typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
      
      enum output_format {
    @@ builtin/repo.c: static int cmd_repo_info(int argc, const char **argv, const char
      	if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
      		die(_("unsupported output format"));
      
    +@@ builtin/repo.c: static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
    + 	struct stats_table table = {
    + 		.rows = STRING_LIST_INIT_DUP,
    + 	};
    +-	enum output_format format = FORMAT_TABLE;
    ++	enum output_format format = FORMAT_DEFAULT;
    + 	struct repo_structure stats = { 0 };
    + 	struct rev_info revs;
    + 	int show_progress = -1;
    +@@ builtin/repo.c: static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
    + 	if (argc)
    + 		usage(_("too many arguments"));
    + 
    ++	if (format == FORMAT_DEFAULT)
    ++		format = FORMAT_TABLE;
    ++
    + 	repo_init_revisions(repo, &revs, prefix);
    + 
    + 	if (show_progress < 0)
    +
    + ## t/t1900-repo.sh ##
    +@@ t/t1900-repo.sh: test_expect_success 'git repo info --all <key> aborts' '
    + 	test_cmp expect actual
    + '
    + 
    ++test_expect_success '--format=default is a synonym for --format=keyvalue' '
    ++	git repo info --all --format=keyvalue >expect &&
    ++	git repo info --all --format=default >actual &&
    ++	test_cmp expect actual
    ++'
    ++
    ++test_expect_success '--format=default resets the format' '
    ++	git repo info --all >expect &&
    ++	git repo info --all --format=nul --format=default >actual &&
    ++	test_cmp expect actual
    ++'
    ++
    + test_done
    +
    + ## t/t1901-repo-structure.sh ##
    +@@ t/t1901-repo-structure.sh: test_expect_success 'progress meter option' '
    + 	)
    + '
    + 
    ++test_expect_success '--format=default is a synonym for --format=table' '
    ++	test_when_finished "rm -rf repo" &&
    ++	git init repo &&
    ++	(
    ++		cd repo &&
    ++		git repo structure --format=table >expect &&
    ++		git repo structure --format=default >actual &&
    ++		test_cmp expect actual
    ++	)
    ++'
    ++
    ++test_expect_success '--format=default resets the format' '
    ++	test_when_finished "rm -rf repo" &&
    ++	git init repo &&
    ++	(
    ++		cd repo &&
    ++		git repo structure >expect &&
    ++		git repo structure --format=nul --format=default >actual &&
    ++		test_cmp expect actual
    ++	)
    ++'
    ++
    + test_done
2:  c5b7ba8824 ! 2:  0c7d3bca32 repo: add new flag --keys to git-repo-info
    @@ Documentation/git-repo.adoc
     @@ Documentation/git-repo.adoc: SYNOPSIS
      --------
      [synopsis]
    - git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
    + git repo info [--format=(default|keyvalue|nul) | -z] [--all | <key>...]
     +git repo info --keys [--format=(default|nul) | -z]
    - git repo structure [--format=(table|keyvalue|nul) | -z]
    + git repo structure [--format=(default|table|keyvalue|nul) | -z]
      
      DESCRIPTION
     @@ Documentation/git-repo.adoc: supported:
    @@ Documentation/git-repo.adoc: supported:
     +`nul`:::
     +	similar to `default`, but using a NUL character after each value.
     +
    - `structure [--format=(table|keyvalue|nul) | -z]`::
    + `structure [--format=(default|table|keyvalue|nul) | -z]`::
      	Retrieve statistics about the current repository structure. The
      	following kinds of information are reported:
     
    @@ builtin/repo.c
     @@
      
      static const char *const repo_usage[] = {
    - 	"git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
    + 	"git repo info [--format=(default|keyvalue|nul) | -z] [--all | <key>...]",
     +	"git repo info --keys [--format=(default|nul) | -z]",
    - 	"git repo structure [--format=(table|keyvalue|nul) | -z]",
    + 	"git repo structure [--format=(default|table|keyvalue|nul) | -z]",
      	NULL
      };
     @@ builtin/repo.c: static int print_all_fields(struct repository *repo,
    @@ t/t1900-repo.sh: test_expect_success 'git repo info uses the last requested form
      	git repo info --all >actual &&
      	test_cmp expect actual
      '
    -@@ t/t1900-repo.sh: test_expect_success 'git repo info --all <key> aborts' '
    +@@ t/t1900-repo.sh: test_expect_success '--format=default resets the format' '
      	test_cmp expect actual
      '
      
     +test_expect_success 'git repo info --keys --format=nul uses nul-terminated output' '
     +	git repo info --keys --format=default >default &&
    -+	lf_to_nul <default > expect &&
    ++	lf_to_nul <default >expect &&
     +	git repo info --keys --format=nul >actual &&
     +	test_cmp expect actual
     +'
    @@ t/t1900-repo.sh: test_expect_success 'git repo info --all <key> aborts' '
     +	test_cmp expect actual_all &&
     +	test_cmp expect actual_key
     +'
    ++
      test_done
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v3 1/2] repo: add a default output format to enum output_format
  2025-12-07 19:02 [PATCH] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
                   ` (3 preceding siblings ...)
  2026-01-09 20:31 ` [PATCH v3 0/2] repo: add --format=default and --keys Lucas Seiki Oshiro
@ 2026-01-09 20:31 ` Lucas Seiki Oshiro
  2026-01-09 20:31 ` [PATCH v3 2/2] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
  5 siblings, 0 replies; 19+ messages in thread
From: Lucas Seiki Oshiro @ 2026-01-09 20:31 UTC (permalink / raw)
  To: git; +Cc: ps, gitster, jltobler, Lucas Seiki Oshiro

Add "default" as an option for --format in both git-repo-info and
git-repo-structure. Using `--format=default` makes those commands use
their default output format.

Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 Documentation/git-repo.adoc | 19 ++++++++++++-------
 builtin/repo.c              | 18 ++++++++++++++----
 t/t1900-repo.sh             | 12 ++++++++++++
 t/t1901-repo-structure.sh   | 22 ++++++++++++++++++++++
 4 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 7d70270dfa..fa0e6600af 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -8,8 +8,8 @@ git-repo - Retrieve information about the repository
 SYNOPSIS
 --------
 [synopsis]
-git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
-git repo structure [--format=(table|keyvalue|nul) | -z]
+git repo info [--format=(default|keyvalue|nul) | -z] [--all | <key>...]
+git repo structure [--format=(default|table|keyvalue|nul) | -z]
 
 DESCRIPTION
 -----------
@@ -19,7 +19,7 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
 
 COMMANDS
 --------
-`info [--format=(keyvalue|nul) | -z] [--all | <key>...]`::
+`info [--format=(default|keyvalue|nul) | -z] [--all | <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).
@@ -30,11 +30,14 @@ requested. The `--all` flag requests the values for all the available keys.
 The output format can be chosen through the flag `--format`. Two formats are
 supported:
 +
+`default`:::
+	synonym for `keyvalue`.
+
 `keyvalue`:::
 	output key-value pairs one per line using the `=` character as
 	the delimiter between the key and the value. Values containing "unusual"
 	characters are quoted as explained for the configuration variable
-	`core.quotePath` (see linkgit:git-config[1]). This is the default.
+	`core.quotePath` (see linkgit:git-config[1]).
 
 `nul`:::
 	similar to `keyvalue`, but using a newline character as the delimiter
@@ -44,7 +47,7 @@ supported:
 +
 `-z` is an alias for `--format=nul`.
 
-`structure [--format=(table|keyvalue|nul) | -z]`::
+`structure [--format=(default|table|keyvalue|nul) | -z]`::
 	Retrieve statistics about the current repository structure. The
 	following kinds of information are reported:
 +
@@ -56,10 +59,12 @@ supported:
 The output format can be chosen through the flag `--format`. Three formats are
 supported:
 +
+`default`:::
+	synonym for `table`.
+
 `table`:::
 	Outputs repository stats in a human-friendly table. This format may
-	change and is not intended for machine parsing. This is the default
-	format.
+	change and is not intended for machine parsing.
 
 `keyvalue`:::
 	Each line of output contains a key-value pair for a repository stat.
diff --git a/builtin/repo.c b/builtin/repo.c
index 0ea045abc1..306d3fa2df 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -17,14 +17,15 @@
 #include "utf8.h"
 
 static const char *const repo_usage[] = {
-	"git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
-	"git repo structure [--format=(table|keyvalue|nul) | -z]",
+	"git repo info [--format=(default|keyvalue|nul) | -z] [--all | <key>...]",
+	"git repo structure [--format=(default|table|keyvalue|nul) | -z]",
 	NULL
 };
 
 typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
 
 enum output_format {
+	FORMAT_DEFAULT,
 	FORMAT_TABLE,
 	FORMAT_KEYVALUE,
 	FORMAT_NUL_TERMINATED,
@@ -161,6 +162,8 @@ static int parse_format_cb(const struct option *opt,
 		*format = FORMAT_KEYVALUE;
 	else if (!strcmp(arg, "table"))
 		*format = FORMAT_TABLE;
+	else if (!strcmp(arg, "default"))
+		*format = FORMAT_DEFAULT;
 	else
 		die(_("invalid format '%s'"), arg);
 
@@ -170,7 +173,7 @@ static int parse_format_cb(const struct option *opt,
 static int cmd_repo_info(int argc, const char **argv, const char *prefix,
 			 struct repository *repo)
 {
-	enum output_format format = FORMAT_KEYVALUE;
+	enum output_format format = FORMAT_DEFAULT;
 	int all_keys = 0;
 	struct option options[] = {
 		OPT_CALLBACK_F(0, "format", &format, N_("format"),
@@ -185,6 +188,10 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
 	};
 
 	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+
+	if (format == FORMAT_DEFAULT)
+		format = FORMAT_KEYVALUE;
+
 	if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
 		die(_("unsupported output format"));
 
@@ -638,7 +645,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
 	struct stats_table table = {
 		.rows = STRING_LIST_INIT_DUP,
 	};
-	enum output_format format = FORMAT_TABLE;
+	enum output_format format = FORMAT_DEFAULT;
 	struct repo_structure stats = { 0 };
 	struct rev_info revs;
 	int show_progress = -1;
@@ -658,6 +665,9 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
 	if (argc)
 		usage(_("too many arguments"));
 
+	if (format == FORMAT_DEFAULT)
+		format = FORMAT_TABLE;
+
 	repo_init_revisions(repo, &revs, prefix);
 
 	if (show_progress < 0)
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 51d55f11a5..e6670f0f58 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -131,4 +131,16 @@ test_expect_success 'git repo info --all <key> aborts' '
 	test_cmp expect actual
 '
 
+test_expect_success '--format=default is a synonym for --format=keyvalue' '
+	git repo info --all --format=keyvalue >expect &&
+	git repo info --all --format=default >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success '--format=default resets the format' '
+	git repo info --all >expect &&
+	git repo info --all --format=nul --format=default >actual &&
+	test_cmp expect actual
+'
+
 test_done
diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh
index 17ff164b05..9c5054c8db 100755
--- a/t/t1901-repo-structure.sh
+++ b/t/t1901-repo-structure.sh
@@ -181,4 +181,26 @@ test_expect_success 'progress meter option' '
 	)
 '
 
+test_expect_success '--format=default is a synonym for --format=table' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		git repo structure --format=table >expect &&
+		git repo structure --format=default >actual &&
+		test_cmp expect actual
+	)
+'
+
+test_expect_success '--format=default resets the format' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		git repo structure >expect &&
+		git repo structure --format=nul --format=default >actual &&
+		test_cmp expect actual
+	)
+'
+
 test_done
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 2/2] repo: add new flag --keys to git-repo-info
  2025-12-07 19:02 [PATCH] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
                   ` (4 preceding siblings ...)
  2026-01-09 20:31 ` [PATCH v3 1/2] repo: add a default output format to enum output_format Lucas Seiki Oshiro
@ 2026-01-09 20:31 ` Lucas Seiki Oshiro
  2026-01-10 12:04   ` Jean-Noël AVILA
  5 siblings, 1 reply; 19+ messages in thread
From: Lucas Seiki Oshiro @ 2026-01-09 20:31 UTC (permalink / raw)
  To: git; +Cc: ps, gitster, jltobler, Lucas Seiki Oshiro

If the user wants to find what are the available keys, they need to
either check the documentation or to ask for all the key-value pairs
by using --all.

Add a new flag --keys for listing only the available keys without
listing the values.

Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 Documentation/git-repo.adoc | 11 +++++++++++
 builtin/repo.c              | 32 ++++++++++++++++++++++++++++++++
 t/t1900-repo.sh             | 34 +++++++++++++++++++++++-----------
 3 files changed, 66 insertions(+), 11 deletions(-)

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index fa0e6600af..4471816cc8 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -9,6 +9,7 @@ SYNOPSIS
 --------
 [synopsis]
 git repo info [--format=(default|keyvalue|nul) | -z] [--all | <key>...]
+git repo info --keys [--format=(default|nul) | -z]
 git repo structure [--format=(default|table|keyvalue|nul) | -z]
 
 DESCRIPTION
@@ -47,6 +48,16 @@ supported:
 +
 `-z` is an alias for `--format=nul`.
 
+`info --keys [--format=(default|nul) | -z]`::
+	List all the available keys, one per line. The output format can be chosen
+	through the flag `--format`. The following formats are supported:
++
+`default`:::
+	output the keys one per line.
+
+`nul`:::
+	similar to `default`, but using a NUL character after each value.
+
 `structure [--format=(default|table|keyvalue|nul) | -z]`::
 	Retrieve statistics about the current repository structure. The
 	following kinds of information are reported:
diff --git a/builtin/repo.c b/builtin/repo.c
index 306d3fa2df..bc10b2da0b 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -18,6 +18,7 @@
 
 static const char *const repo_usage[] = {
 	"git repo info [--format=(default|keyvalue|nul) | -z] [--all | <key>...]",
+	"git repo info --keys [--format=(default|nul) | -z]",
 	"git repo structure [--format=(default|table|keyvalue|nul) | -z]",
 	NULL
 };
@@ -149,6 +150,29 @@ static int print_all_fields(struct repository *repo,
 	return 0;
 }
 
+static int print_keys(enum output_format format)
+{
+	char sep;
+
+	switch (format) {
+	case FORMAT_DEFAULT:
+		sep = '\n';
+		break;
+	case FORMAT_NUL_TERMINATED:
+		sep = '\0';
+		break;
+	default:
+		die(_("--keys can only be used with --format=default or --format=nul"));
+	}
+
+	for (size_t i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
+		const struct field *field = &repo_info_fields[i];
+		printf("%s%c", field->key, sep);
+	}
+
+	return 0;
+}
+
 static int parse_format_cb(const struct option *opt,
 			   const char *arg, int unset UNUSED)
 {
@@ -175,6 +199,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
 {
 	enum output_format format = FORMAT_DEFAULT;
 	int all_keys = 0;
+	int show_keys = 0;
 	struct option options[] = {
 		OPT_CALLBACK_F(0, "format", &format, N_("format"),
 			       N_("output format"),
@@ -184,11 +209,18 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
 			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
 			       parse_format_cb),
 		OPT_BOOL(0, "all", &all_keys, N_("print all keys/values")),
+		OPT_BOOL(0, "keys", &show_keys, N_("show keys")),
 		OPT_END()
 	};
 
 	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
 
+	if (show_keys && (all_keys || argc))
+		die(_("--keys cannot be used with a <key> or --all"));
+
+	if (show_keys)
+		return print_keys(format);
+
 	if (format == FORMAT_DEFAULT)
 		format = FORMAT_KEYVALUE;
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index e6670f0f58..14533b95a0 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -4,15 +4,6 @@ test_description='test git repo-info'
 
 . ./test-lib.sh
 
-# git-repo-info keys. It must contain the same keys listed in the const
-# repo_info_fields, in lexicographical order.
-REPO_INFO_KEYS='
-	layout.bare
-	layout.shallow
-	object.format
-	references.format
-'
-
 # Test whether a key-value pair is correctly returned
 #
 # Usage: test_repo_info <label> <init command> <repo_name> <key> <expected value>
@@ -119,8 +110,8 @@ test_expect_success 'git repo info uses the last requested format' '
 	test_cmp expected actual
 '
 
-test_expect_success 'git repo info --all returns all key-value pairs' '
-	git repo info $REPO_INFO_KEYS >expect &&
+test_expect_success 'git repo info --all and git repo info $(git repo info --keys) output the same data' '
+	git repo info $(git repo info --keys) >expect &&
 	git repo info --all >actual &&
 	test_cmp expect actual
 '
@@ -143,4 +134,25 @@ test_expect_success '--format=default resets the format' '
 	test_cmp expect actual
 '
 
+test_expect_success 'git repo info --keys --format=nul uses nul-terminated output' '
+	git repo info --keys --format=default >default &&
+	lf_to_nul <default >expect &&
+	git repo info --keys --format=nul >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'git repo info --keys aborts when using --format other than default or nul' '
+	echo "fatal: --keys can only be used with --format=default or --format=nul" >expect &&
+	test_must_fail git repo info --keys --format=keyvalue 2>actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'git repo info --keys aborts when requesting keys' '
+	echo "fatal: --keys cannot be used with a <key> or --all" >expect &&
+	test_must_fail git repo info --keys --all 2>actual_all &&
+	test_must_fail git repo info --keys some.key 2>actual_key &&
+	test_cmp expect actual_all &&
+	test_cmp expect actual_key
+'
+
 test_done
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 0/2] repo: add --format=default and --keys
  2026-01-09 20:31 ` [PATCH v3 0/2] repo: add --format=default and --keys Lucas Seiki Oshiro
@ 2026-01-10  6:48   ` Junio C Hamano
  2026-01-10  7:02     ` Junio C Hamano
  0 siblings, 1 reply; 19+ messages in thread
From: Junio C Hamano @ 2026-01-10  6:48 UTC (permalink / raw)
  To: Lucas Seiki Oshiro; +Cc: git, ps, jltobler

Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:

> Hi!
>
> The main change in this version is that git-repo-structure now supports
> `--format=default`. This way, both git-repo-info and git-repo-structure
> now can be used with `--format=default`, which resets the output format
> to the default one (`keyvalue` in repo-info, `table` in repo-structure).
>
> I'm also cc'ing Justin to see if he agrees with this change to
> git-repo-structure.
>
> Lucas Seiki Oshiro (2):
>   repo: add a default output format to enum output_format
>   repo: add new flag --keys to git-repo-info

How does the bottommost commit relate to what has been queued on
lo/repo-info-keys topic as ac3e74d2 (repo: add new flag --keys to
git-repo-info, 2025-12-09)?


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 0/2] repo: add --format=default and --keys
  2026-01-10  6:48   ` Junio C Hamano
@ 2026-01-10  7:02     ` Junio C Hamano
  0 siblings, 0 replies; 19+ messages in thread
From: Junio C Hamano @ 2026-01-10  7:02 UTC (permalink / raw)
  To: Lucas Seiki Oshiro; +Cc: git, ps, jltobler

Junio C Hamano <gitster@pobox.com> writes:

>> Lucas Seiki Oshiro (2):
>>   repo: add a default output format to enum output_format
>>   repo: add new flag --keys to git-repo-info
>
> How does the bottommost commit relate to what has been queued on
> lo/repo-info-keys topic as ac3e74d2 (repo: add new flag --keys to
> git-repo-info, 2025-12-09)?

Ah, nevermind.  These two are designed to replace the two patches on
lo/repo-info-keys topic, so I'll discard the old ones and replace.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 2/2] repo: add new flag --keys to git-repo-info
  2026-01-09 20:31 ` [PATCH v3 2/2] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
@ 2026-01-10 12:04   ` Jean-Noël AVILA
  0 siblings, 0 replies; 19+ messages in thread
From: Jean-Noël AVILA @ 2026-01-10 12:04 UTC (permalink / raw)
  To: git, Lucas Seiki Oshiro; +Cc: ps, gitster, jltobler, Lucas Seiki Oshiro

On Friday, 9 January 2026 21:31:53 CET Lucas Seiki Oshiro wrote:
> If the user wants to find what are the available keys, they need to
> either check the documentation or to ask for all the key-value pairs
> by using --all.
> 
> Add a new flag --keys for listing only the available keys without
> listing the values.
> 
> Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
> ---
>  Documentation/git-repo.adoc | 11 +++++++++++
>  builtin/repo.c              | 32 ++++++++++++++++++++++++++++++++
>  t/t1900-repo.sh             | 34 +++++++++++++++++++++++-----------
>  3 files changed, 66 insertions(+), 11 deletions(-)
> 
> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> index fa0e6600af..4471816cc8 100644
> --- a/Documentation/git-repo.adoc
> +++ b/Documentation/git-repo.adoc
> @@ -9,6 +9,7 @@ SYNOPSIS
>  --------
>  [synopsis]
>  git repo info [--format=(default|keyvalue|nul) | -z] [--all | <key>...]
> +git repo info --keys [--format=(default|nul) | -z]
>  git repo structure [--format=(default|table|keyvalue|nul) | -z]
> 
>  DESCRIPTION
> @@ -47,6 +48,16 @@ supported:
>  +
>  `-z` is an alias for `--format=nul`.
> 
> +`info --keys [--format=(default|nul) | -z]`::
> +	List all the available keys, one per line. The output format can be 
chosen
> +	through the flag `--format`. The following formats are supported:
> ++
> +`default`:::
> +	output the keys one per line.
> +
> +`nul`:::
> +	similar to `default`, but using a NUL character after each value.

We use the placeholder format for character names: _NUL_





^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2026-01-10 12:05 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-07 19:02 [PATCH] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
2025-12-07 22:14 ` Junio C Hamano
2025-12-08 16:33   ` Lucas Seiki Oshiro
2025-12-08  7:13 ` Patrick Steinhardt
2025-12-09 19:36 ` [PATCH v2 0/2] " Lucas Seiki Oshiro
2025-12-09 19:36   ` [PATCH v2 1/2] repo: add a default output format to enum output_format Lucas Seiki Oshiro
2026-01-05 14:18     ` Patrick Steinhardt
2026-01-07 21:28       ` Lucas Seiki Oshiro
2026-01-08  6:13         ` Patrick Steinhardt
2025-12-09 19:36   ` [PATCH v2 2/2] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
2026-01-05 14:18     ` Patrick Steinhardt
2026-01-05 13:57   ` [PATCH v2 0/2] " Lucas Seiki Oshiro
2026-01-05 14:19     ` Patrick Steinhardt
2026-01-09 20:31 ` [PATCH v3 0/2] repo: add --format=default and --keys Lucas Seiki Oshiro
2026-01-10  6:48   ` Junio C Hamano
2026-01-10  7:02     ` Junio C Hamano
2026-01-09 20:31 ` [PATCH v3 1/2] repo: add a default output format to enum output_format Lucas Seiki Oshiro
2026-01-09 20:31 ` [PATCH v3 2/2] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
2026-01-10 12:04   ` Jean-Noël AVILA

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).