parse-options.c: use optbug() instead of BUG() "opts" check

Change the assertions added in bf3ff338a25 (parse-options: stop abusing 'callback' for lowlevel callbacks, 2019-01-27) to use optbug() instead of BUG(). At this point we're looping over individual options, so if we encounter any issues we'd like to report the offending option. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jun 2, 2022 at 14:25 UTC 5b2f5d92ca5afc118d3fb798c1f25863a5011a01
1 file changed +9 -8
parse-options.c
+9 -8
@@ -474,20 +474,21 @@ static void parse_options_check(const struct option *opts)
474 break;
475 case OPTION_CALLBACK:
476 if (!opts->callback && !opts->ll_callback)
477 - BUG("OPTION_CALLBACK needs one callback");
478 - if (opts->callback && opts->ll_callback)
479 - BUG("OPTION_CALLBACK can't have two callbacks");
477 + optbug(opts, "OPTION_CALLBACK needs one callback");
478 + else if (opts->callback && opts->ll_callback)
479 + optbug(opts, "OPTION_CALLBACK can't have two callbacks");
480 break;
481 case OPTION_LOWLEVEL_CALLBACK:
482 if (!opts->ll_callback)
483 - BUG("OPTION_LOWLEVEL_CALLBACK needs a callback");
483 + optbug(opts, "OPTION_LOWLEVEL_CALLBACK needs a callback");
484 if (opts->callback)
485 - BUG("OPTION_LOWLEVEL_CALLBACK needs no high level callback");
485 + optbug(opts, "OPTION_LOWLEVEL_CALLBACK needs no high level callback");
486 break;
487 case OPTION_ALIAS:
488 - BUG("OPT_ALIAS() should not remain at this point. "
489 - "Are you using parse_options_step() directly?\n"
490 - "That case is not supported yet.");
488 + optbug(opts, "OPT_ALIAS() should not remain at this point. "
489 + "Are you using parse_options_step() directly?\n"
490 + "That case is not supported yet.");
491 + break;
492 default:
493 ; /* ok. (usually accepts an argument) */
494 }