From: Junio C Hamano <gitster@pobox.com>
To: "D. Ben Knoble" <ben.knoble+github@gmail.com>
Cc: git@vger.kernel.org, "René Scharfe" <l.s.r@web.de>,
"Andrzej Hunt" <ajrhunt@google.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH 2/4] parse-options: name flags passed to usage_with_options_internal
Date: Mon, 28 Jul 2025 11:19:51 -0700 [thread overview]
Message-ID: <xmqqseiguqig.fsf@gitster.g> (raw)
In-Reply-To: <xmqqjz3sxro3.fsf@gitster.g> (Junio C. Hamano's message of "Mon, 28 Jul 2025 08:26:36 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> For example, it ought to be sufficient, for the purpose of improved
> readability, to instead doing this
>
>> static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t *,
>> const char * const *,
>> const struct option *,
>> - int, int);
>> + enum usage_style,
>> + enum usage_output);
>
> just do
>
> int full_usage,
> int usage_to_stderr);
>
> here. Dropping the parameter names in the function prototype is
> allowed, and we encourage to do so in our codebase but _only_ when
> the meaning of each parameter is obvious from their type. The first
> 3 parameters we see above are of distinct types and except for the
> second one being the usage string given to the users, they should be
> obvious. But the last two unnamed integers are not obvious and they
> should have been spelled out---otherwise a developer who is adding
> a new callsite cannot work from the prototype alone and has to go to
> the implementation to figure out what to pass.
>
> Adding two enums for this is a bit overkill, but is OK here locally.
And with that lessor impact change, you could still add a smaller
change to help callers (you do not need any change to the callee,
which uses biased parameter names for these two), if you wanted to
(though as I said this is internal implementation detail of the
parse_options API, so you do not have to). For example, you could
do
#define USAGE_FULL 1
#define USAGE_TO_STDERR 1
without anything else and do
>> @@ -1088,7 +1099,7 @@ enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
>> }
>>
>> if (internal_help && !strcmp(arg + 2, "help-all"))
>> - return usage_with_options_internal(ctx, usagestr, options, 1, 0);
>> + return usage_with_options_internal(ctx, usagestr, options, style_full, to_out);
return usage_with_options_internal(ctx, usagestr, options,
USAGE_FULL, 0);
which may make it easier to follow. The point is that you be more
verbose only when you do a non-standard thing.
And without enum, of course you do not need any change like below.
> One way to reduce this churn is to do
>
> int err = (to_where == to_stderr);
> int full = (help_style == style_full);
>
> at the very beginning of the function. Then you do not have to
> change the body of the function harder to read at all.
next prev parent reply other threads:[~2025-07-28 18:19 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-26 16:53 [PATCH 0/4] permit -h/--help-all in more scenarios D. Ben Knoble
2025-07-26 16:53 ` [PATCH 1/4] t1517: fixup for ua/t1517-short-help-tests D. Ben Knoble
2025-07-26 21:57 ` Usman Akinyemi
2025-07-28 15:35 ` Junio C Hamano
2025-07-26 16:53 ` [PATCH 2/4] parse-options: name flags passed to usage_with_options_internal D. Ben Knoble
2025-07-28 15:26 ` Junio C Hamano
2025-07-28 18:19 ` Junio C Hamano [this message]
2025-07-30 22:05 ` D. Ben Knoble
2025-07-26 16:53 ` [PATCH 3/4] builtin: also setup gently for --help-all D. Ben Knoble
2025-07-28 15:33 ` Junio C Hamano
2025-07-30 22:00 ` D. Ben Knoble
2025-07-26 16:53 ` [PATCH 4/4] builtins: show help on "-h"/"--help-all" with more than 2 arguments left D. Ben Knoble
2025-07-27 0:28 ` Junio C Hamano
2025-07-30 21:55 ` D. Ben Knoble
2025-08-02 9:23 ` Jeff King
2025-08-02 16:10 ` D. Ben Knoble
2025-08-02 16:28 ` Jeff King
2025-08-02 17:05 ` D. Ben Knoble
2025-08-03 1:26 ` [PATCH v2 0/3] permit -h/--help-all in more scenarios D. Ben Knoble
2025-08-03 16:10 ` [PATCH v3 " D. Ben Knoble
2025-08-04 4:53 ` Junio C Hamano
2025-08-05 1:28 ` D. Ben Knoble
2025-08-03 16:10 ` [PATCH v3 1/3] t1517: fixup for ua/t1517-short-help-tests D. Ben Knoble
2025-08-03 16:41 ` Junio C Hamano
2025-08-03 16:43 ` D. Ben Knoble
2025-08-03 16:10 ` [PATCH v3 2/3] parse-options: refactor flags for usage_with_options_internal D. Ben Knoble
2025-08-03 16:10 ` [PATCH v3 3/3] builtin: also setup gently for --help-all D. Ben Knoble
2025-08-03 1:26 ` [PATCH v2 1/3] t1517: fixup for ua/t1517-short-help-tests D. Ben Knoble
2025-08-03 1:26 ` [PATCH v2 2/3] parse-options: refactor flags for usage_with_options_internal D. Ben Knoble
2025-08-03 1:26 ` [PATCH v2 3/3] builtin: also setup gently for --help-all D. Ben Knoble
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=xmqqseiguqig.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=ajrhunt@google.com \
--cc=avarab@gmail.com \
--cc=ben.knoble+github@gmail.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.