Skip to content

Commit 457f962

Browse files
rscharfegitster
authored andcommitted
parse-options: simplify positivation handling
We accept the positive version of options whose long name starts with "no-" and are defined without the flag PARSE_OPT_NONEG. E.g. git clone has an explicitly defined --no-checkout option and also implicitly accepts --checkout to override it. parse_long_opt() handles that by restarting the option matching with the positive version when it finds that only the current option definition starts with "no-", but not the user-supplied argument. This code is located almost at the end of the matching logic. Avoid the need for a restart by moving the code up. We don't have to check the positive arg against the negative long_name at all -- the "no-" prefix of the latter makes a match impossible. Skip it and toggle OPT_UNSET right away to simplify the control flow. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5825268 commit 457f962

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

parse-options.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,11 @@ static enum parse_opt_result parse_long_opt(
369369
if (!long_name)
370370
continue;
371371

372-
again:
372+
if (!starts_with(arg, "no-") &&
373+
!(options->flags & PARSE_OPT_NONEG) &&
374+
skip_prefix(long_name, "no-", &long_name))
375+
opt_flags |= OPT_UNSET;
376+
373377
if (!skip_prefix(arg, long_name, &rest))
374378
rest = NULL;
375379
if (!rest) {
@@ -403,13 +407,8 @@ static enum parse_opt_result parse_long_opt(
403407
goto is_abbreviated;
404408
}
405409
/* negated? */
406-
if (!starts_with(arg, "no-")) {
407-
if (skip_prefix(long_name, "no-", &long_name)) {
408-
opt_flags |= OPT_UNSET;
409-
goto again;
410-
}
410+
if (!starts_with(arg, "no-"))
411411
continue;
412-
}
413412
flags |= OPT_UNSET;
414413
if (!skip_prefix(arg + 3, long_name, &rest)) {
415414
/* abbreviated and negated? */

0 commit comments

Comments
 (0)