git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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: Tue, 18 Nov 2025 13:28:18 -0800	[thread overview]
Message-ID: <xmqq8qg3do99.fsf@gitster.g> (raw)
In-Reply-To: <DA3814BC-D6A5-4EF1-9A2B-9687D1B6C26A@gmail.com> (Lucas Seiki Oshiro's message of "Tue, 18 Nov 2025 17:16:09 -0300")

Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:

>>> + for (unsigned long i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
>>> 
>> 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.
>
> Yeah, I also thought it an unsigned long feels out of place, but I
> was only following ARRAY_SIZE. Actually, I was trying to avoid a
> warning. In this case we have very few `repo_info_field`s and any
> int type would work here...
>
> I'll replace it by size_t, then.
>
>>    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
>
> Perhaps if ARRAY_SIZE(repo_info_fields) is bigger than the maximum
> limit of the integer type, which would overflow and this for would
> loop forever. But, obviously this wouldn't happen here.

Yes.  We can tell, and a compiler should be able to figure out, that
inside the loop nothing other than increment by one per iteration is
done to "i", and the ARRAY_SIZE(repo_info_fields) is a compile-time
constant that comfortably fits in platform natural "int", so we
know, and a compiler should know, that there is nothing to complain
about if "int i" is used there.

But the quality of implementation of -Wsign-compare may not be good
enough to figure it out.

As ARRAY_SIZE() essentially is a size_t divided by another size_t,
use of size_t is the safest solution that does not require any
braincycle to pick.

>> 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.
>
> I can't see a use for it other than these tests. What about writing
> a helper inside t/helpers for that?

If you use "git repo info" only occasionally, wouldn't "git repo
info --keys", if supported, be a useful way to get a more focused
help than "git repo --help" where you have to scan the entire
document and try to find the list of keys that are supported from
there?

  reply	other threads:[~2025-11-18 21:28 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
2025-11-18 20:16       ` Lucas Seiki Oshiro
2025-11-18 21:28         ` Junio C Hamano [this message]
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=xmqq8qg3do99.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).