From: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
To: git@vger.kernel.org
Cc: ps@pks.im, karthik.188@gmail.com, gitster@pobox.com,
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Subject: [PATCH v2 0/2] repo: add --all to repo-info
Date: Mon, 20 Oct 2025 13:19:45 -0300 [thread overview]
Message-ID: <20251020181943.6314-1-lucasseikioshiro@gmail.com> (raw)
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("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);
@@ 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)
next reply other threads:[~2025-10-20 18:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-20 16:19 Lucas Seiki Oshiro [this message]
2025-10-20 16:19 ` [PATCH v2 1/2] repo: factor out field printing to dedicated function Lucas Seiki Oshiro
2025-10-20 16:19 ` [PATCH v2 2/2] repo: add --all to git-repo-info Lucas Seiki Oshiro
2025-10-21 5:44 ` Patrick Steinhardt
2025-10-21 13:44 ` Junio C Hamano
2025-10-24 21:15 ` Lucas Seiki Oshiro
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=20251020181943.6314-1-lucasseikioshiro@gmail.com \
--to=lucasseikioshiro@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--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).