threads / patch / 64357

v2, 2 partsrepo: add --all to repo-info

Subject: [PATCH v2 0/2] repo: add --all to repo-info

## tl;dr

6 messages between Oct 20, 2025 and Oct 24, 2025. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Lucas Seiki Oshiro· Oct 20, 2025, 16:19 UTC · lore
Hi!

The main change introduced in this v2 is that now `git repo info --all <some.key>` returns the values for all the available keys plus the value of `<some.key>` (which will be duplicated). If `<some.key>` is an invalid key, the command will proceed the same way that it would do without the `--all` flag.

PS: Sorry for sending this v2 after a month. I've been really busy last
weeks, but I still want to finish this :-)
Here's the rangediff against v1:
-:  ---------- > 1:  5f72f07589 repo: factor out field printing to dedicated function
1:  94c7b835f0 ! 2:  b8158bb7b8 repo: add --all to git-repo-info
    @@ Metadata
      ## Commit message ##
         repo: add --all to git-repo-info
     
    -    Add a new flag `--all` to git-repo-info for requesting all the available
    -    keys. By using this flag, the user can retrieve all the values instead
    -    of searching what are the desired keys for what they wants.
    +    Add a new flag `--all` to git-repo-info for requesting values for all
    +    the available keys. By using this flag, the user can retrieve all the
    +    values instead of searching what are the desired keys for what they
    +    wants.
     
         Helped-by: Karthik Nayak <karthik.188@gmail.com>
         Helped-by: Patrick Steinhardt <ps@pks.im>
    @@ Documentation/git-repo.adoc: git-repo - Retrieve information about the repositor
      --------
      [synopsis]
     -git repo info [--format=(keyvalue|nul)] [-z] [<key>...]
    -+git repo info [--format=(keyvalue|nul)] [-z] [--all] [<key>...]
    ++git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]
      
      DESCRIPTION
      -----------
    @@ Documentation/git-repo.adoc: THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHAN
      COMMANDS
      --------
     -`info [--format=(keyvalue|nul)] [-z] [<key>...]`::
    -+`info [--format=(keyvalue|nul)] [-z] [--all] [<key>...]`::
    ++`info [--format=(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).
      +
      The values are returned in the same order in which their respective keys were
     -requested.
    -+requested. The `--all` flag requests all keys.
    ++requested. The `--all` flag requests the values for all the available keys.
    ++Keys requested after `--all` will be duplicated.
      +
      The output format can be chosen through the flag `--format`. Two formats are
      supported:
    @@ builtin/repo.c
      
      static const char *const repo_usage[] = {
     -	"git repo info [--format=(keyvalue|nul)] [-z] [<key>...]",
    -+	"git repo info [--format=(keyvalue|nul)] [-z] [--all] [<key>...]",
    ++	"git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]",
      	NULL
      };
      
    -@@ builtin/repo.c: static get_value_fn *get_value_fn_for_key(const char *key)
    - 	return found ? found->get_value : NULL;
    - }
    - 
    -+static void print_field(enum output_format format, const char *key,
    -+			struct strbuf *valbuf, struct strbuf *quotbuf)
    -+{
    -+	strbuf_reset(quotbuf);
    -+
    -+	switch (format) {
    -+	case FORMAT_KEYVALUE:
    -+		quote_c_style(valbuf->buf, quotbuf, NULL, 0);
    -+		printf("%s=%s\n", key, quotbuf->buf);
    -+		break;
    -+	case FORMAT_NUL_TERMINATED:
    -+		printf("%s\n%s%c", key, valbuf->buf, '\0');
    -+		break;
    -+	default:
    -+		BUG("not a valid output format: %d", format);
    -+	}
    -+}
    -+
    - static int print_fields(int argc, const char **argv,
    - 			struct repository *repo,
    - 			enum output_format format)
    -@@ builtin/repo.c: static int print_fields(int argc, const char **argv,
    - 		}
    - 
    - 		strbuf_reset(&valbuf);
    --		strbuf_reset(&quotbuf);
    --
    - 		get_value(repo, &valbuf);
    --
    --		switch (format) {
    --		case FORMAT_KEYVALUE:
    --			quote_c_style(valbuf.buf, &quotbuf, NULL, 0);
    --			printf("%s=%s\n", key, quotbuf.buf);
    --			break;
    --		case FORMAT_NUL_TERMINATED:
    --			printf("%s\n%s%c", key, valbuf.buf, '\0');
    --			break;
    --		default:
    --			BUG("not a valid output format: %d", format);
    --		}
    -+		print_field(format, key, &valbuf, &quotbuf);
    - 	}
    - 
    - 	strbuf_release(&valbuf);
     @@ builtin/repo.c: static int print_fields(int argc, const char **argv,
      	return ret;
      }
    @@ builtin/repo.c: static int repo_info(int argc, const char **argv, const char *pr
      
      	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
      
    -+	if (all_keys) {
    ++	if (all_keys)
     +		print_all_fields(repo, format);
    -+		return 0;
    -+	}
     +
      	return print_fields(argc, argv, repo, format);
      }
      
     
      ## t/t1900-repo.sh ##
    +@@ t/t1900-repo.sh: 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>
     @@ t/t1900-repo.sh: test_expect_success 'git repo info uses the last requested format' '
      	test_cmp expected actual
      '
      
    -+test_expect_success 'git repo info --all returns all fields' '
    -+	git repo info layout.bare layout.shallow object.format references.format >expect &&
    ++test_expect_success 'git repo info --all returns all key-value pairs' '
    ++	git repo info $REPO_INFO_KEYS >expect &&
     +	git repo info --all >actual &&
     +	test_cmp expect actual
     +'
    ++
    ++test_expect_success 'git repo info --all <key> duplicates <key>' '
    ++	git repo info $REPO_INFO_KEYS object.format >expect &&
    ++	git repo info --all object.format >actual &&
    ++	test_cmp expect actual
    ++'
    ++
    ++test_expect_success 'git repo info --all <invalid key> warns about invalid key' '
    ++	git repo info $REPO_INFO_KEYS >expect &&
    ++	echo "error: key ${SQ}no.key${SQ} not found" >expect_err &&
    ++	test_must_fail git repo info --all no.key >actual 2>actual_err &&
    ++	test_cmp expect actual &&
    ++	test_cmp expect_err actual_err
    ++'
     +
      test_done
Lucas Seiki Oshiro (2):
  repo: factor out field printing to dedicated function
  repo: add --all to git-repo-info
 Documentation/git-repo.adoc |  7 +++--
 builtin/repo.c              | 60 +++++++++++++++++++++++++++----------
 t/t1900-repo.sh             | 29 ++++++++++++++++++
 3 files changed, 78 insertions(+), 18 deletions(-)
-- 
2.50.1 (Apple Git-155)
Lucas Seiki Oshiro· Oct 20, 2025, 16:19 UTC · re: Lucas Seiki Oshiro · lore

[PATCH v2 1/2] repo: factor out field printing to dedicated function

Move the field printing in git-repo-info to a new function called `print_field`, allowing it to be called by functions other than `print_fields`.

Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 builtin/repo.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
Show changes to builtin/repo.c +19 −14
diff --git a/builtin/repo.c b/builtin/repo.c
index bbb0966f2d..3b071e9a50 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -77,6 +77,24 @@ static get_value_fn *get_value_fn_for_key(const char *key)
 	return found ? found->get_value : NULL;
 }
 
+static void print_field(enum output_format format, const char *key,
+			struct strbuf *valbuf, struct strbuf *quotbuf)
+{
+	strbuf_reset(quotbuf);
+
+	switch (format) {
+	case FORMAT_KEYVALUE:
+		quote_c_style(valbuf->buf, quotbuf, NULL, 0);
+		printf("%s=%s\n", key, quotbuf->buf);
+		break;
+	case FORMAT_NUL_TERMINATED:
+		printf("%s\n%s%c", key, valbuf->buf, '\0');
+		break;
+	default:
+		BUG("not a valid output format: %d", format);
+	}
+}
+
 static int print_fields(int argc, const char **argv,
 			struct repository *repo,
 			enum output_format format)
@@ -97,21 +115,8 @@ static int print_fields(int argc, const char **argv,
 		}
 
 		strbuf_reset(&valbuf);
-		strbuf_reset(&quotbuf);
-
 		get_value(repo, &valbuf);
-
-		switch (format) {
-		case FORMAT_KEYVALUE:
-			quote_c_style(valbuf.buf, &quotbuf, NULL, 0);
-			printf("%s=%s\n", key, quotbuf.buf);
-			break;
-		case FORMAT_NUL_TERMINATED:
-			printf("%s\n%s%c", key, valbuf.buf, '\0');
-			break;
-		default:
-			BUG("not a valid output format: %d", format);
-		}
+		print_field(format, key, &valbuf, &quotbuf);
 	}
 
 	strbuf_release(&valbuf);
-- 
2.50.1 (Apple Git-155)
Lucas Seiki Oshiro· Oct 20, 2025, 16:19 UTC · re: Lucas Seiki Oshiro · lore

[PATCH v2 2/2] repo: add --all to git-repo-info

Add a new flag `--all` to git-repo-info for requesting values for all the available keys. By using this flag, the user can retrieve all the values instead of searching what are the desired keys for what they wants.

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

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

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 209afd1b61..1a9d0c50a9 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
 SYNOPSIS
 --------
 [synopsis]
-git repo info [--format=(keyvalue|nul)] [-z] [<key>...]
+git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]
 
 DESCRIPTION
 -----------
@@ -18,13 +18,14 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
 
 COMMANDS
 --------
-`info [--format=(keyvalue|nul)] [-z] [<key>...]`::
+`info [--format=(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).
 +
 The values are returned in the same order in which their respective keys were
-requested.
+requested. The `--all` flag requests the values for all the available keys.
+Keys requested after `--all` will be duplicated.
 +
 The output format can be chosen through the flag `--format`. Two formats are
 supported:
diff --git a/builtin/repo.c b/builtin/repo.c
index 3b071e9a50..1c54db5810 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -9,7 +9,7 @@
 #include "shallow.h"
 
 static const char *const repo_usage[] = {
-	"git repo info [--format=(keyvalue|nul)] [-z] [<key>...]",
+	"git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]",
 	NULL
 };
 
@@ -124,6 +124,26 @@ static int print_fields(int argc, const char **argv,
 	return ret;
 }
 
+static void print_all_fields(struct repository *repo,
+			     enum output_format format)
+{
+	struct strbuf valbuf = STRBUF_INIT;
+	struct strbuf quotbuf = STRBUF_INIT;
+
+	for (unsigned long i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
+		struct field field = repo_info_fields[i];
+		get_value_fn *get_value = field.get_value;
+		const char *key = field.key;
+
+		strbuf_reset(&valbuf);
+		get_value(repo, &valbuf);
+		print_field(format, key, &valbuf, &quotbuf);
+	}
+
+	strbuf_release(&valbuf);
+	strbuf_release(&quotbuf);
+}
+
 static int parse_format_cb(const struct option *opt,
 			   const char *arg, int unset UNUSED)
 {
@@ -145,6 +165,7 @@ static int repo_info(int argc, const char **argv, const char *prefix,
 		     struct repository *repo)
 {
 	enum output_format format = FORMAT_KEYVALUE;
+	int all_keys = 0;
 	struct option options[] = {
 		OPT_CALLBACK_F(0, "format", &format, N_("format"),
 			       N_("output format"),
@@ -153,11 +174,15 @@ static int repo_info(int argc, const char **argv, const char *prefix,
 			       N_("synonym for --format=nul"),
 			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
 			       parse_format_cb),
+		OPT_BOOL(0, "all", &all_keys, N_("return all keys")),
 		OPT_END()
 	};
 
 	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
 
+	if (all_keys)
+		print_all_fields(repo, format);
+
 	return print_fields(argc, argv, repo, format);
 }
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 2beba67889..28635d0f92 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -4,6 +4,15 @@ 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>
@@ -110,4 +119,24 @@ 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 &&
+	git repo info --all >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'git repo info --all <key> duplicates <key>' '
+	git repo info $REPO_INFO_KEYS object.format >expect &&
+	git repo info --all object.format >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'git repo info --all <invalid key> warns about invalid key' '
+	git repo info $REPO_INFO_KEYS >expect &&
+	echo "error: key ${SQ}no.key${SQ} not found" >expect_err &&
+	test_must_fail git repo info --all no.key >actual 2>actual_err &&
+	test_cmp expect actual &&
+	test_cmp expect_err actual_err
+'
+
 test_done
-- 
2.50.1 (Apple Git-155)
Patrick Steinhardt· Oct 21, 2025, 05:44 UTC · re: Lucas Seiki Oshiro · lore

Re: [PATCH v2 2/2] repo: add --all to git-repo-info

On Mon, Oct 20, 2025 at 01:19:47PM -0300, Lucas Seiki Oshiro wrote:
Show 30 quoted lines
> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> index 209afd1b61..1a9d0c50a9 100644
> --- a/Documentation/git-repo.adoc
> +++ b/Documentation/git-repo.adoc
> @@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
>  SYNOPSIS
>  --------
>  [synopsis]
> -git repo info [--format=(keyvalue|nul)] [-z] [<key>...]
> +git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]
>  
>  DESCRIPTION
>  -----------
> @@ -18,13 +18,14 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
>  
>  COMMANDS
>  --------
> -`info [--format=(keyvalue|nul)] [-z] [<key>...]`::
> +`info [--format=(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).
>  +
>  The values are returned in the same order in which their respective keys were
> -requested.
> +requested. The `--all` flag requests the values for all the available keys.
> +Keys requested after `--all` will be duplicated.
>  +
>  The output format can be chosen through the flag `--format`. Two formats are
>  supported:

The synopsis now disagrees with the new behaviour, as it looks as if you can pick either "--all" or a set of keys. But we now support both at the same time.

I know Junio mentioned this as one of the ways this may operate, and said that accepting both is the "most logical". I personally don't quite agree, and think that having it be either or is a bit saner. After all, what is the use case for listing specific keys twice? I cannot really see why one would ever want that. So I think we should accept either `--all` or keys, and die if they are used in combination.

If Junio continues to prefer the version you have here then so be it. But in that case you'll have to fix the synopsis to reflect that.

Show 27 quoted lines
> diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
> index 2beba67889..28635d0f92 100755
> --- a/t/t1900-repo.sh
> +++ b/t/t1900-repo.sh
> @@ -110,4 +119,24 @@ 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 &&
> +	git repo info --all >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'git repo info --all <key> duplicates <key>' '
> +	git repo info $REPO_INFO_KEYS object.format >expect &&
> +	git repo info --all object.format >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'git repo info --all <invalid key> warns about invalid key' '
> +	git repo info $REPO_INFO_KEYS >expect &&
> +	echo "error: key ${SQ}no.key${SQ} not found" >expect_err &&
> +	test_must_fail git repo info --all no.key >actual 2>actual_err &&
> +	test_cmp expect actual &&
> +	test_cmp expect_err actual_err
> +'

Yeah, these don't quite convince me that using them in combination is sensible :) In fact, there is one more argument against this here: in the current form, the order in which we print the key-value pairs depends on the order in which they are specified on the command line. So far so good.

But with `--all` that's not the case anymore, as we unconditionally print all pairs before the individual keys. So `git repo info --all <key>` produces the same output as `git repo info <key> --all`. Now we're in a mode where only _parts_ of the output depends on the order of our command line arguments, which is inconsistent.

So... yeah, I think accepting either or is the more sensible approach. There is no use case for printing keys twice, and if we do then we have some weird inconsistencies in the ordering.

Thanks!
Patrick
Junio C Hamano· Oct 21, 2025, 13:44 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v2 2/2] repo: add --all to git-repo-info

Patrick Steinhardt <ps@pks.im> writes:
Show 12 quoted lines
>> +`info [--format=(keyvalue|nul)] [-z] [--all | <key>...]`::
> ...
> The synopsis now disagrees with the new behaviour, as it looks as if you
> can pick either "--all" or a set of keys. But we now support both at the
> same time.
>
> I know Junio mentioned this as one of the ways this may operate, and
> said that accepting both is the "most logical". I personally don't quite
> agree, and think that having it be either or is a bit saner. After all,
> what is the use case for listing specific keys twice? I cannot really
> see why one would ever want that. So I think we should accept either
> `--all` or keys, and die if they are used in combination.

Yup, unless we declare that the order of output is unspecified when "--all" is used (regardless of the presense of explicitly given keys), it would become awkweard to define the output behaviour. So I am OK to make the command behave as specified in the synopsis section.

Thanks.

← back to recent threads