format-rev: place BUG calls first in callback

I added these parse-options `BUG` statements based on existing examples;
one `BUG` check per flag. Now, of course the code as-is will not call
this callback with `unset` set to `0`, or with an argument
string. Rather, these preconditions defend against `opts[]` getting
changed *without* changing this callback.

And I copied the existing examples that I found down to
the placement. And the placement doesn’t matter here; we just
unconditionally set two variables. Failing on `BUG` before or after
that makes no difference to the user. Still, it is better style to
test function preconditions as early as possible. So let’s move them
to the start.

Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
seen
Kristoffer Haugsbakk 2026-08-18 11:57:31 +02:00 committed by Junio C Hamano
parent 7dd020f883
commit 0ac2a41b18
1 changed files with 2 additions and 2 deletions

View File

@ -782,10 +782,10 @@ static int format_nul_cb(const struct option *option,
int unset)
{
struct format_nul_data *data = option->value;
data->nul_input = 1;
data->nul_output = 1;
BUG_ON_OPT_NEG(unset);
BUG_ON_OPT_ARG(arg);
data->nul_input = 1;
data->nul_output = 1;
return 0;
}