]> git.ipfire.org Git - thirdparty/git.git/commit - builtin/commit.c
commit: avoid writing to global in option callback
authorJeff King <peff@peff.net>
Thu, 6 Oct 2022 13:11:31 +0000 (09:11 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 6 Oct 2022 16:58:06 +0000 (09:58 -0700)
commit116761ba9cdee81e0d7b4671f14f9bd256f2cb36
tree01a76dd96c88ce4d1c5b2571f287d82d8dbcc5b2
parent7faba18a9a82b32aeacc5dd5f525764a80640a95
commit: avoid writing to global in option callback

The callback function for --trailer writes directly to the global
trailer_args and ignores opt->value completely. This is OK, since that's
where we expect to find the value. But it does mean the option
declaration isn't as clear. E.g., we have:

    OPT_BOOL(0, "reset-author", &renew_authorship, ...),
    OPT_CALLBACK_F(0, "trailer", NULL, ..., opt_pass_trailer)

In the first one we can see where the result will be stored, but in the
second, we get only NULL, and you have to go read the callback.

Let's pass &trailer_args, and use it in the callback. As a bonus, this
silences a -Wunused-parameter warning.

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