git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Silly 'git am' UI issue

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 4, 2022, 03:51 UTC
Message-ID
<xmqq1qzi4bpk.fsf@gitster.g>
In-Reply-To
<CAHk-=wjQP8PwYZMYUhKu3s9wMhE2yDqdAO_OKagqXuvPrHRyAQ@mail.gmail.com>
Linus Torvalds <torvalds@linux-foundation.org> writes:
Show 24 quoted lines
> On Thu, Mar 3, 2022 at 1:58 PM Junio C Hamano <gitster@pobox.com> 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.

Show 5 quoted lines
> +	if (parse_whitespace_option(&dummy, arg))
> +		return -1;
> +
> +	return parse_opt_passthru_argv(opt, arg, unset);
> +}
Looks good.
Show 15 quoted lines
>  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),
Previous: Linus TorvaldsNext: Ævar Arnfjörð Bjarmason
Message 4 of 7 in “Silly 'git am' UI issue”
  1. Linus TorvaldsMar 3, 2022
  2. Junio C HamanoMar 3, 2022
  3. Linus TorvaldsMar 4, 2022
  4. Junio C HamanoMar 4, 2022
  5. Ævar Arnfjörð BjarmasonMar 4, 2022
  6. Ævar Arnfjörð BjarmasonMar 4, 2022
  7. Linus TorvaldsMar 4, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.