Re: [PATCH 3/6] parse-options: factor out register_abbrev() and struct parsed_option
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 24, 2024, 23:13 UTC
- Message-ID
- <xmqqttlxjw1u.fsf@gitster.g>
- In-Reply-To
- <20240224212953.44026-4-l.s.r@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 10 quoted lines
> static enum parse_opt_result parse_long_opt(
> struct parse_opt_ctx_t *p, const char *arg,
> const struct option *options)
> {
> const char *arg_end = strchrnul(arg, '=');
> - const struct option *abbrev_option = NULL, *ambiguous_option = NULL;
> - enum opt_parsed abbrev_flags = OPT_LONG, ambiguous_flags = OPT_LONG;
> - int allow_abbrev = !(p->flags & PARSE_OPT_KEEP_UNKNOWN_OPT);
> + struct parsed_option abbrev = { .option = NULL, .flags = OPT_LONG };
> + struct parsed_option ambiguous = { .option = NULL, .flags = OPT_LONG };There is this "allow_abbrev" thing ...
Show 16 quoted lines
> ...
> if (!skip_prefix(arg + 3, long_name, &rest)) {
> /* abbreviated and negated? */
> - if (allow_abbrev &&
> - !strncmp(long_name, arg + 3,
> + if (!strncmp(long_name, arg + 3,
> arg_end - arg - 3))
> - goto is_abbreviated;
> - else
> - continue;
> + register_abbrev(p, options,
> + flags ^ opt_flags,
> + &abbrev, &ambiguous);
> + continue;
> }
> }... whose use goes away completely from the loop. We still call register_abbrev(), but the helper function becomes no-op when p->flags had KEEP_UNKNOWN_OPT bit set, so everything cancels out.
OK.