]> git.ipfire.org Git - thirdparty/git.git/commitdiff
parse-options.c: use optbug() instead of BUG() "opts" check
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Thu, 2 Jun 2022 12:25:35 +0000 (14:25 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Jun 2022 19:51:35 +0000 (12:51 -0700)
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>
parse-options.c

index 78b46ae96989043d58d59f8fcb1d20d96bdce27c..edf55d3ef5d7428b68e793d6d684c0299710c628 100644 (file)
@@ -474,20 +474,21 @@ static void parse_options_check(const struct option *opts)
                        break;
                case OPTION_CALLBACK:
                        if (!opts->callback && !opts->ll_callback)
-                               BUG("OPTION_CALLBACK needs one callback");
-                       if (opts->callback && opts->ll_callback)
-                               BUG("OPTION_CALLBACK can't have two callbacks");
+                               optbug(opts, "OPTION_CALLBACK needs one callback");
+                       else if (opts->callback && opts->ll_callback)
+                               optbug(opts, "OPTION_CALLBACK can't have two callbacks");
                        break;
                case OPTION_LOWLEVEL_CALLBACK:
                        if (!opts->ll_callback)
-                               BUG("OPTION_LOWLEVEL_CALLBACK needs a callback");
+                               optbug(opts, "OPTION_LOWLEVEL_CALLBACK needs a callback");
                        if (opts->callback)
-                               BUG("OPTION_LOWLEVEL_CALLBACK needs no high level callback");
+                               optbug(opts, "OPTION_LOWLEVEL_CALLBACK needs no high level callback");
                        break;
                case OPTION_ALIAS:
-                       BUG("OPT_ALIAS() should not remain at this point. "
-                           "Are you using parse_options_step() directly?\n"
-                           "That case is not supported yet.");
+                       optbug(opts, "OPT_ALIAS() should not remain at this point. "
+                              "Are you using parse_options_step() directly?\n"
+                              "That case is not supported yet.");
+                       break;
                default:
                        ; /* ok. (usually accepts an argument) */
                }