[PATCH v6 2/6] repo: support category requests in repo info
- From
- Eslam reda ragheb via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Mar 2, 2026, 05:15 UTC
- Message-ID
- <2369608976c6126bcf40c59974389a84394aab68.1772428548.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2208.v6.git.git.1772428548.gitgitgadget@gmail.com>
From: Eslam reda ragheb <eslam.reda.div@gmail.com>
Teach repo info to accept category names (for example, layout) and expand them to matching key.* entries in request order.
Explicit keys keep their existing behavior; unknown keys or categories still report clear errors.
Signed-off-by: Eslam reda ragheb <eslam.reda.div@gmail.com> --- builtin/repo.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-)
diff --git a/builtin/repo.c b/builtin/repo.c index e687d833b4..f614298199 100644 --- a/builtin/repo.c +++ b/builtin/repo.c @@ -96,6 +96,33 @@ 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, + const char *value); + +static int print_category_fields(const char *category, + struct repo_info *info, + enum output_format format, + struct strbuf *valbuf) +{ + int found = 0; + size_t category_len = strlen(category); + + for (size_t i = 0; i < ARRAY_SIZE(repo_info_fields); i++) { + const struct field *field = &repo_info_fields[i]; + + if (!starts_with(field->key, category) || + field->key[category_len] != '.') + continue; + + strbuf_reset(valbuf); + field->get_value(info, valbuf); + print_field(format, field->key, valbuf->buf); + found = 1; + } + + return found; +} + static void print_field(enum output_format format, const char *key, const char *value) { @@ -126,14 +153,15 @@ static int print_fields(int argc, const char **argv, get_value = get_value_fn_for_key(key); - if (!get_value) { - ret = error(_("key '%s' not found"), key); + if (get_value) { + strbuf_reset(&valbuf); + get_value(info, &valbuf); + print_field(format, key, valbuf.buf); continue; } - strbuf_reset(&valbuf); - get_value(info, &valbuf); - print_field(format, key, valbuf.buf); + if (!print_category_fields(key, info, format, &valbuf)) + ret = error(_("key '%s' not found"), key); } strbuf_release(&valbuf);
-- gitgitgadget