Skip to content

Commit 28a9247

Browse files
rscharfegitster
authored andcommitted
parse-options: rearrange long_name matching code
Move the code for handling a full match of long_name first and get rid of negations. Reduce the indent of the code for matching abbreviations and remove unnecessary curly braces. Combine the checks for whether negation is allowed and whether arg is "n", "no" or "no-" because they belong together and avoid a continue statement. The result is shorter, more readable code. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b1ce2b6 commit 28a9247

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

parse-options.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -413,30 +413,23 @@ static enum parse_opt_result parse_long_opt(
413413
if (((flags ^ opt_flags) & OPT_UNSET) && !allow_unset)
414414
continue;
415415

416-
if (!skip_prefix(arg_start, long_name, &rest))
417-
rest = NULL;
418-
if (!rest) {
419-
/* abbreviated? */
420-
if (!strncmp(long_name, arg_start, arg_end - arg_start)) {
421-
register_abbrev(p, options, flags ^ opt_flags,
422-
&abbrev, &ambiguous);
423-
}
424-
/* negation allowed? */
425-
if (options->flags & PARSE_OPT_NONEG)
416+
if (skip_prefix(arg_start, long_name, &rest)) {
417+
if (*rest == '=')
418+
p->opt = rest + 1;
419+
else if (*rest)
426420
continue;
427-
/* negated and abbreviated very much? */
428-
if (starts_with("no-", arg)) {
429-
register_abbrev(p, options, OPT_UNSET ^ opt_flags,
430-
&abbrev, &ambiguous);
431-
}
432-
continue;
421+
return get_value(p, options, flags ^ opt_flags);
433422
}
434-
if (*rest) {
435-
if (*rest != '=')
436-
continue;
437-
p->opt = rest + 1;
438-
}
439-
return get_value(p, options, flags ^ opt_flags);
423+
424+
/* abbreviated? */
425+
if (!strncmp(long_name, arg_start, arg_end - arg_start))
426+
register_abbrev(p, options, flags ^ opt_flags,
427+
&abbrev, &ambiguous);
428+
429+
/* negated and abbreviated very much? */
430+
if (allow_unset && starts_with("no-", arg))
431+
register_abbrev(p, options, OPT_UNSET ^ opt_flags,
432+
&abbrev, &ambiguous);
440433
}
441434

442435
if (disallow_abbreviated_options && (ambiguous.option || abbrev.option))

0 commit comments

Comments
 (0)