From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, "René Scharfe" <l.s.r@web.de>
Subject: Re: [PATCH 4/8] parse-options: mark unused "opt" parameter in callbacks
Date: Thu, 31 Aug 2023 09:33:22 -0700 [thread overview]
Message-ID: <xmqqil8vxjcd.fsf@gitster.g> (raw)
In-Reply-To: <20230831071820.GB3197751@coredump.intra.peff.net> (Jeff King's message of "Thu, 31 Aug 2023 03:18:20 -0400")
Jeff King <peff@peff.net> writes:
> diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
> index f62f13f2b5..95b3717dd1 100644
> --- a/builtin/checkout-index.c
> +++ b/builtin/checkout-index.c
> @@ -190,7 +190,7 @@ static const char * const builtin_checkout_index_usage[] = {
> NULL
> };
>
> -static int option_parse_stage(const struct option *opt,
> +static int option_parse_stage(const struct option *opt UNUSED,
> const char *arg, int unset)
> {
> BUG_ON_OPT_NEG(unset);
I suspect that the original is buggy; when given
$ git checkout-index --stage=all --stage=1 path
the first option turns --temp on, but the second one does not turn
it off. For now I think being bug-to-bug compatible and annotating
the opt as UNUSED is good, but as a follow-up, we could make the
caller:
(1) point &checkout_stage with opt->value;
(2) make to_tempfile to tristate <unspecified, false, true> by
initializing it to -1;
(3) adjust to_tempfile that is still <unspecified> after
parse_options() returns, according to the value in
checkout_stage.
and then this can follow the "opt->value points at the variable that
is affected" pattern.
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 8f93529505..cd2afe33e5 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -168,7 +168,8 @@ static int git_fetch_config(const char *k, const char *v,
> return git_default_config(k, v, ctx, cb);
> }
>
> -static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
> +static int parse_refmap_arg(const struct option *opt UNUSED,
> + const char *arg, int unset)
> {
> BUG_ON_OPT_NEG(unset);
Can't this just point opt->value at the global &refmap? Obviously
not a huge deal, as we could have taken the "annotate as UNUSED"
approach for all the functions in [3/8].
> diff --git a/builtin/gc.c b/builtin/gc.c
> index 369bd43fb2..b842349d86 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -1403,7 +1403,7 @@ static void initialize_task_config(int schedule)
> strbuf_release(&config_name);
> }
>
> -static int task_option_parse(const struct option *opt,
> +static int task_option_parse(const struct option *opt UNUSED,
> const char *arg, int unset)
> {
> int i, num_selected = 0;
The TASK__COUNT constant is very closely tied to the task[] array
and it is not worth passing the address of the array in opt->value.
The loss of clarity inside the callback funtion is a more serious
downside than the value on the caller side to document what array
is being modified. So I agree this is a good change.
> diff --git a/builtin/update-index.c b/builtin/update-index.c
> index aee3cb8cbd..59acae3336 100644
> --- a/builtin/update-index.c
> +++ b/builtin/update-index.c
> @@ -856,7 +856,7 @@ static int chmod_callback(const struct option *opt,
> return 0;
> }
>
> -static int resolve_undo_clear_callback(const struct option *opt,
> +static int resolve_undo_clear_callback(const struct option *opt UNUSED,
> const char *arg, int unset)
> {
> BUG_ON_OPT_NEG(unset);
> @@ -890,7 +890,7 @@ static int parse_new_style_cacheinfo(const char *arg,
> }
>
> static enum parse_opt_result cacheinfo_callback(
> - struct parse_opt_ctx_t *ctx, const struct option *opt,
> + struct parse_opt_ctx_t *ctx, const struct option *opt UNUSED,
> const char *arg, int unset)
> {
> struct object_id oid;
These two refuses to take "arg" and the callback mechanism is used
purely to trigger the side effect of the function, not as a part of
parsing something for its "value", so I agree that these UNUSED
annotations reflect the reality very well.
Thanks.
next prev parent reply other threads:[~2023-08-31 16:33 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-31 7:09 [PATCH 0/8] more unused parameters in parseopt callbacks Jeff King
2023-08-31 7:12 ` [PATCH 1/8] merge: make xopts a strvec Jeff King
2023-08-31 7:22 ` Jeff King
2023-08-31 11:18 ` Phillip Wood
2023-08-31 15:46 ` Junio C Hamano
2023-08-31 20:55 ` Taylor Blau
2023-08-31 7:14 ` [PATCH 2/8] merge: simplify parsing of "-n" option Jeff King
2023-08-31 15:56 ` Junio C Hamano
2023-08-31 7:17 ` [PATCH 3/8] parse-options: prefer opt->value to globals in callbacks Jeff King
2023-08-31 16:14 ` Junio C Hamano
2023-08-31 7:18 ` [PATCH 4/8] parse-options: mark unused "opt" parameter " Jeff King
2023-08-31 16:33 ` Junio C Hamano [this message]
2023-08-31 17:50 ` Jeff King
2023-08-31 20:48 ` Jeff King
2023-08-31 7:18 ` [PATCH 5/8] merge: do not pass unused opt->value parameter Jeff King
2023-08-31 16:53 ` Junio C Hamano
2023-08-31 7:19 ` [PATCH 6/8] parse-options: add more BUG_ON() annotations Jeff King
2023-08-31 16:58 ` Junio C Hamano
2023-08-31 7:19 ` [PATCH 7/8] interpret-trailers: mark unused "unset" parameters in option callbacks Jeff King
2023-08-31 17:04 ` Junio C Hamano
2023-08-31 17:56 ` Jeff King
2023-08-31 7:20 ` [PATCH 8/8] parse-options: mark unused parameters in noop callback Jeff King
2023-08-31 17:05 ` Junio C Hamano
2023-08-31 21:16 ` [PATCH v2 0/10] more unused parameters in parseopt callbacks Jeff King
2023-08-31 21:17 ` [PATCH v2 01/10] merge: make xopts a strvec Jeff King
2023-08-31 21:17 ` [PATCH v2 02/10] merge: simplify parsing of "-n" option Jeff King
2023-09-02 6:20 ` René Scharfe
2023-09-05 6:43 ` Jeff King
2023-08-31 21:17 ` [PATCH v2 03/10] format-patch: use OPT_STRING_LIST for to/cc options Jeff King
2023-08-31 21:20 ` [PATCH v2 04/10] checkout-index: delay automatic setting of to_tempfile Jeff King
2023-08-31 22:12 ` Junio C Hamano
2023-09-02 6:20 ` René Scharfe
2023-09-05 7:12 ` [PATCH v3 " Jeff King
2023-08-31 21:21 ` [PATCH v2 05/10] parse-options: prefer opt->value to globals in callbacks Jeff King
2023-09-02 7:34 ` René Scharfe
2023-09-05 6:52 ` Jeff King
2023-08-31 21:21 ` [PATCH v2 06/10] parse-options: mark unused "opt" parameter " Jeff King
2023-09-02 10:12 ` René Scharfe
2023-09-05 7:05 ` Jeff King
2023-09-19 7:42 ` René Scharfe
2023-08-31 21:21 ` [PATCH v2 07/10] merge: do not pass unused opt->value parameter Jeff King
2023-08-31 21:21 ` [PATCH v2 08/10] parse-options: add more BUG_ON() annotations Jeff King
2023-08-31 21:22 ` [PATCH v2 09/10] interpret-trailers: mark unused "unset" parameters in option callbacks Jeff King
2023-08-31 21:22 ` [PATCH v2 10/10] parse-options: mark unused parameters in noop callback Jeff King
2023-09-02 11:37 ` René Scharfe
2023-09-05 7:09 ` Jeff King
2023-09-07 20:20 ` René Scharfe
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=xmqqil8vxjcd.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
--cc=peff@peff.net \
/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.