[PATCH] repo: add new flag --keys to git-repo-info
- From
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
- Date
- Dec 7, 2025, 19:02 UTC
- Message-ID
- <20251207190532.67107-1-lucasseikioshiro@gmail.com>
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)