]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reflog: assert PARSE_OPT_NONEG in parse-options callbacks
authorJeff King <peff@peff.net>
Fri, 19 Aug 2022 08:55:02 +0000 (04:55 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 Aug 2022 21:14:55 +0000 (14:14 -0700)
In the spirit of 517fe807d6 (assert NOARG/NONEG behavior of
parse-options callbacks, 2018-11-05), this asserts that our callbacks
were invoked using the right flags (since otherwise they'd segfault on
the NULL arg). Both cases are already correct here, so this is mostly
about annotating the functions, and appeasing -Wunused-parameters.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/reflog.c

index 4dd297dce86e5212087ee1202d5b9dd1f754f9d1..81239568478d39ccb4b79a52d85a9ace66fd5cb7 100644 (file)
@@ -193,6 +193,8 @@ static int expire_unreachable_callback(const struct option *opt,
 {
        struct cmd_reflog_expire_cb *cmd = opt->value;
 
+       BUG_ON_OPT_NEG(unset);
+
        if (parse_expiry_date(arg, &cmd->expire_unreachable))
                die(_("invalid timestamp '%s' given to '--%s'"),
                    arg, opt->long_name);
@@ -207,6 +209,8 @@ static int expire_total_callback(const struct option *opt,
 {
        struct cmd_reflog_expire_cb *cmd = opt->value;
 
+       BUG_ON_OPT_NEG(unset);
+
        if (parse_expiry_date(arg, &cmd->expire_total))
                die(_("invalid timestamp '%s' given to '--%s'"),
                    arg, opt->long_name);