From: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
To: git@vger.kernel.org
Cc: ps@pks.im, karthik.188@gmail.com,
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Subject: [PATCH] repo: add --all to git-repo-info
Date: Mon, 15 Sep 2025 19:36:17 -0300 [thread overview]
Message-ID: <20250915223618.13093-1-lucasseikioshiro@gmail.com> (raw)
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.
Helped-by: Karthik Nayak <karthik.188@gmail.com>
Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
Hi!
This patch is an epilogue of my GSoC, as it was requested to have some
way to retrieve all the values without needing to pass all the keys.
This is built on top of the current master, a483264b01 (The ninth
batch, 2025-09-15).
Documentation/git-repo.adoc | 6 ++--
builtin/repo.c | 62 ++++++++++++++++++++++++++++---------
t/t1900-repo.sh | 6 ++++
3 files changed, 56 insertions(+), 18 deletions(-)
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 209afd1b61..2caf093a9a 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,13 @@ 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 all keys.
+
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 bbb0966f2d..906d8a3e12 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
};
@@ -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("buf);
-
get_value(repo, &valbuf);
-
- switch (format) {
- case FORMAT_KEYVALUE:
- quote_c_style(valbuf.buf, "buf, 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, "buf);
}
strbuf_release(&valbuf);
@@ -119,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, "buf);
+ }
+
+ strbuf_release(&valbuf);
+ strbuf_release("buf);
+}
+
static int parse_format_cb(const struct option *opt,
const char *arg, int unset UNUSED)
{
@@ -140,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"),
@@ -148,11 +174,17 @@ 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 0;
+ }
+
return print_fields(argc, argv, repo, format);
}
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 2beba67889..b1391a47b6 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -110,4 +110,10 @@ 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 &&
+ git repo info --all >actual &&
+ test_cmp expect actual
+'
+
test_done
--
2.39.5 (Apple Git-154)
next reply other threads:[~2025-09-15 22:36 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-15 22:36 Lucas Seiki Oshiro [this message]
2025-09-15 23:58 ` [PATCH] repo: add --all to git-repo-info Junio C Hamano
2025-09-16 8:06 ` Patrick Steinhardt
2025-09-16 16:19 ` Junio C Hamano
2025-09-17 5:34 ` Patrick Steinhardt
2025-10-26 22:52 ` [PATCH v3 0/2] " Lucas Seiki Oshiro
2025-10-26 22:52 ` [PATCH v3 1/2] repo: factor out field printing to dedicated function Lucas Seiki Oshiro
2025-10-26 23:53 ` Eric Sunshine
2025-10-26 23:56 ` Eric Sunshine
2025-10-27 14:56 ` Junio C Hamano
2025-10-27 16:09 ` Eric Sunshine
2025-10-26 22:52 ` [PATCH v3 2/2] repo: add --all to git-repo-info Lucas Seiki Oshiro
2025-10-27 0:22 ` Eric Sunshine
2025-10-27 0:24 ` Eric Sunshine
2025-11-17 15:02 ` [PATCH v4 0/2] " Lucas Seiki Oshiro
2025-11-17 15:02 ` [PATCH v4 1/2] repo: factor out field printing to dedicated function Lucas Seiki Oshiro
2025-11-17 18:48 ` Junio C Hamano
2025-11-17 15:02 ` [PATCH v4 2/2] repo: add --all to git-repo-info Lucas Seiki Oshiro
2025-11-17 18:58 ` Junio C Hamano
2025-11-18 20:16 ` Lucas Seiki Oshiro
2025-11-18 21:28 ` Junio C Hamano
2025-11-20 22:50 ` Lucas Seiki Oshiro
2025-11-19 7:32 ` Eric Sunshine
2025-11-19 14:33 ` Junio C Hamano
2025-11-17 18:14 ` [PATCH v4 0/2] " Junio C Hamano
2025-11-18 20:37 ` [PATCH v5 " Lucas Seiki Oshiro
2025-11-18 20:37 ` [PATCH v5 1/2] repo: factor out field printing to dedicated function Lucas Seiki Oshiro
2025-11-18 20:37 ` [PATCH v5 2/2] repo: add --all to git-repo-info Lucas Seiki Oshiro
2025-11-18 21:34 ` [PATCH v5 0/2] " Junio C Hamano
2025-11-19 7:35 ` Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250915223618.13093-1-lucasseikioshiro@gmail.com \
--to=lucasseikioshiro@gmail.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).