Skip to content

Commit d775365

Browse files
peffgitster
authored andcommitted
interpret-trailers: mark unused "unset" parameters in option callbacks
There are a few parse-option callbacks that do not look at their "unset" parameters, but also do not set PARSE_OPT_NONEG. At first glance this seems like a bug, as we'd ignore "--no-if-exists", etc. But they do work fine, because when "unset" is true, then "arg" is NULL. And all three functions pass "arg" on to helper functions which do the right thing with the NULL. Note that this shortcut would not be correct if any callback used PARSE_OPT_NOARG (in which case "arg" would be NULL but "unset" would be false). But none of these do. So the code is fine as-is. But we'll want to mark the unused "unset" parameters to quiet -Wunused-parameter. I've also added a comment to make this rather subtle situation more explicit. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent abf2952 commit d775365

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

builtin/interpret-trailers.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,23 @@ static enum trailer_if_exists if_exists;
2424
static enum trailer_if_missing if_missing;
2525

2626
static int option_parse_where(const struct option *opt,
27-
const char *arg, int unset)
27+
const char *arg, int unset UNUSED)
2828
{
29+
/* unset implies NULL arg, which is handled in our helper */
2930
return trailer_set_where(opt->value, arg);
3031
}
3132

3233
static int option_parse_if_exists(const struct option *opt,
33-
const char *arg, int unset)
34+
const char *arg, int unset UNUSED)
3435
{
36+
/* unset implies NULL arg, which is handled in our helper */
3537
return trailer_set_if_exists(opt->value, arg);
3638
}
3739

3840
static int option_parse_if_missing(const struct option *opt,
39-
const char *arg, int unset)
41+
const char *arg, int unset UNUSED)
4042
{
43+
/* unset implies NULL arg, which is handled in our helper */
4144
return trailer_set_if_missing(opt->value, arg);
4245
}
4346

0 commit comments

Comments
 (0)