parse-options: disallow negating OPTION_SET_INT 0
PATCH 1/1 parse-options: disallow negating OPTION_SET_INT 0
An option of type OPTION_SET_INT can be defined to set its variable to zero. It's negated variant will do the same, though, which is confusing. Several such options were fixed by disabling negation, changing the value to set or using a different option type:
991c552916 (ls-tree: fix --no-full-name, 2023-07-18)e12cb98e1e (branch: reject "--no-all" and "--no-remotes" early, 2023-07-18) 68cbb20e73 (show-branch: reject --[no-](topo|date)-order, 2023-07-19) 3821eb6c3d (reset: reject --no-(mixed|soft|hard|merge|keep) option, 2023-07-19) 36f76d2a25 (pack-objects: fix --no-quiet, 2023-07-21)3a5f308741 (pack-objects: fix --no-keep-true-parents, 2023-07-21) c95ae3ff9c (describe: fix --no-exact-match, 2023-07-21)d089a06421 (bundle: use OPT_PASSTHRU_ARGV, 2023-07-29)
Check for such options that allow negation in parse_options_check() and report them to find future cases quicker.
--- parse-options.c | 3 +++ 1 file changed, 3 insertions(+)
parse-options.c +3 -0
@@ -480,6 +480,9 @@ static void parse_options_check(const struct option *opts) opts->long_name))optbug (opts,"uses feature " "not supported for dashless options" ); +if (opts->type ==OPTION_SET_INT && !opts->defval && + opts->long_name && !(opts->flags &PARSE_OPT_NONEG )) +optbug (opts,"OPTION_SET_INT 0 should not be negatable" );switch (opts->type) {case OPTION_COUNTUP :case OPTION_BIT :
--
2.41.0
Quoted 14 lines · René Scharfe
An option of type
OPTION_SET_INTcan be defined to set its variable to zero. It's negated variant will do the same, though, which is confusing. Several such options were fixed by disabling negation, changing the value to set or using a different option type:
991c552916(ls-tree: fix --no-full-name, 2023-07-18)e12cb98e1e(branch: reject "--no-all" and "--no-remotes" early, 2023-07-18)68cbb20e73(show-branch: reject --[no-](topo|date)-order, 2023-07-19)3821eb6c3d(reset: reject --no-(mixed|soft|hard|merge|keep) option, 2023-07-19)36f76d2a25(pack-objects: fix --no-quiet, 2023-07-21)3a5f308741(pack-objects: fix --no-keep-true-parents, 2023-07-21)c95ae3ff9c(describe: fix --no-exact-match, 2023-07-21)d089a06421(bundle: useOPT_PASSTHRU_ARGV, 2023-07-29)
Quoted 2 lines
Check for such options that allow negation in
parse_options_check()and report them to find future cases quicker.
That does make quite a lot of sense, and parse_options_check() is the perfect place to do so.
Thanks.
Quoted 21 lines
Signed-off-by René Scharfe <[email protected]>--- parse-options.c | 3 +++ 1 file changed, 3 insertions(+)parse-options.c +3
-1@@ -480,6 +480,9 @@ static void parse_options_check(const struct option *opts) opts->long_name))optbug (opts,"uses feature " "not supported for dashless options" ); +if (opts->type ==OPTION_SET_INT && !opts->defval && + opts->long_name && !(opts->flags &PARSE_OPT_NONEG )) +optbug (opts,"OPTION_SET_INT 0 should not be negatable" );switch (opts->type) {case OPTION_COUNTUP :case OPTION_BIT : --2.41.0