Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> writes: > On Thu, Mar 3, 2022 at 1:58 PM Junio C Hamano <gitster@xxxxxxxxx> wrote: >> >> I wonder if something like this would have helped. > > That would certainly have helped, yes. > > But I think we can do better. > > How about just parsing the "--whitespace" option in 'git am' before > passing it through? > > Something like the attached patch seems to work for me. > > With this one, I simply get > > $ git am --whitespace 0001-Dummy.patch > error: unrecognized whitespace option '0001-Dummy.patch' > > when I make the mistake of not giving that whitespace argument. > > I'm not claiming this is extensively tested, but I did *some* testing > on it, and it's not a complicated patch. > > Linus Yup, reusing what apply.c already uses gives reviewers a solid assurance. It already is named appropriately for a global namespace, so the patch text, as far as I can see, looks good enough. > +static int parse_opt_whitespace(const struct option *opt, const char *arg, int unset) > +{ > + struct apply_state dummy = { }; It is rare to see a completely empty initializer in this codebase, I think. > + if (parse_whitespace_option(&dummy, arg)) > + return -1; > + > + return parse_opt_passthru_argv(opt, arg, unset); > +} Looks good. > static int git_am_config(const char *k, const char *v, void *cb) > { > int status; > @@ -2355,9 +2365,9 @@ int cmd_am(int argc, const char **argv, const char *prefix) > OPT_CALLBACK_F(0, "quoted-cr", &state.quoted_cr, N_("action"), > N_("pass it through git-mailinfo"), > PARSE_OPT_NONEG, am_option_parse_quoted_cr), > - OPT_PASSTHRU_ARGV(0, "whitespace", &state.git_apply_opts, N_("action"), > + OPT_CALLBACK(0, "whitespace", &state.git_apply_opts, N_("action"), > N_("pass it through git-apply"), > - 0), > + parse_opt_whitespace), > OPT_PASSTHRU_ARGV(0, "ignore-space-change", &state.git_apply_opts, NULL, > N_("pass it through git-apply"), > PARSE_OPT_NOARG),