From: Junio C Hamano <gitster@pobox.com>
To: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Cc: git@vger.kernel.org, sunshine@sunshineco.com, ps@pks.im,
karthik.188@gmail.com
Subject: Re: [PATCH v4 2/2] repo: add --all to git-repo-info
Date: Mon, 17 Nov 2025 10:58:34 -0800 [thread overview]
Message-ID: <xmqqh5usiizp.fsf@gitster.g> (raw)
In-Reply-To: <20251117151844.14802-3-lucasseikioshiro@gmail.com> (Lucas Seiki Oshiro's message of "Mon, 17 Nov 2025 12:02:52 -0300")
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
> +static void print_all_fields(struct repository *repo,
> + enum output_format format)
> +{
> + struct strbuf valbuf = STRBUF_INIT;
> +
> + for (unsigned long i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
> + const struct field *field = &repo_info_fields[i];
> +
> + strbuf_reset(&valbuf);
> + field->get_value(repo, &valbuf);
> + print_field(format, field->key, valbuf.buf);
> + }
> + strbuf_release(&valbuf);
> +}
I am not sure if "unsigned long i" is the type you want here. I do
not mind, and actually I prefer, a simple platform natural "int i"
for something simple like this [*], but I know other people prefer to
use "size_t" to work with ARRAY_SIZE() these days.
Side note: The reason they insist using size_t here is that
"-Wsign-compare" makes the compiler complain. But I would
say that it only shows what a misguided feature
-Wsign-compare warning is, especially given that the
compiler perfectly well knows how big repo_info_fields[]
array is and the iteration cannot do any harm if done with a
signed integer smaller than size_t
Anyway.
We grab each field, ask it for its value, and then print it. What a
straight-forward flow that is pleasant to read! ;-).
Compared to that, printing of individual keys given by the end-user
is much uglier, but it is not a fault of this two-patch series, so
my comment here is only as #leftoverbits for later clean-up.
The print_fields() function does this (modulo error checking for
missing key):
for (int i = 0; i < argc; i++) {
get_value_fn *get_value;
const char *key = argv[i];
get_value = get_value_fn_for_key(key);
get_value(repo, &valbuf);
We should get rid of the get_value_fn_for_key() helper, and instead
add and use repo_info_field(const char *key) helepr. That way, the
logic become exactly the same as the "get all" case. The body of
the loop would read (modulo error checking for missing key):
const struct field *field = repo_info_field(argv[i]);
field->get_value(repo, &valbuf);
whcih is much nicer, when the repo_info_fields[] gains more
attributes other than a callback function, we do not want to keep
adding get_this_attr_for_key() functions.
Side note: By the way, it should be named repo_info_field[].
Name arrays singular so that you can name its 0th element by
saying dog[0], not dogs[0]. "dog[1] and dog[2] are friends"
not "dogs[1] and dogs[2] are friends". An exception is when
most of the time you use the array as a single unit as a
collection, passing it around in the call chain, and you
rarely address each individual element (other than outside
the implementation of the API). I am OK to see such an
array that is mostly used as a collection named plural (but
of course, singular names are always fine). Adding this to
CodingGuidelines is perhaps a #leftoverbits material.
> @@ -167,6 +185,14 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
> if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
> die(_("unsupported output format"));
>
> + if (all_keys) {
> + if (argc)
> + die(_("--all and <key> cannot be used together"));
> +
> + print_all_fields(repo, format);
> + return 0;
> + }
> return print_fields(argc, argv, repo, format);
This would work, but the symmetry between a list of keys vs the
"--all" option is lost.
I'd rather see something like the following after a #leftoverbits
clean-up commit:
if (all_keys && argc)
die(_("--all and <key> cannot be used together"));
if (all_keys)
return print_all_fields(repo, format);
else
return print_fields(argc, argv, repo, format);
> diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
> index 2beba67889..51d55f11a5 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
> +'
Again, this would work for now, but maybe "git repo info --keys"
that emits these would be easier to manage. This can be left to
#leftoverbits of course.
But then we have seem to have seen too many #leftoverbits material,
you might want to handle some or all of them in this series in a
reroll? I am starting to become undecided.
With "repo info --keys", the user could even do
git repo info $(git repo info --keys)
if they wanted to.
No, I am not suggesting to discard the "--all" option; only pointing
out that conceptually, "--all" can be explained in terms of
"--keys".
next prev parent reply other threads:[~2025-11-17 18:58 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-15 22:36 [PATCH] repo: add --all to git-repo-info Lucas Seiki Oshiro
2025-09-15 23:58 ` 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 [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqh5usiizp.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=lucasseikioshiro@gmail.com \
--cc=ps@pks.im \
--cc=sunshine@sunshineco.com \
/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.
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 NNTP newsgroup(s).