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

Re: Silly 'git am' UI issue

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Mar 4, 2022, 00:42 UTC
Message-ID
<CAHk-=wjQP8PwYZMYUhKu3s9wMhE2yDqdAO_OKagqXuvPrHRyAQ@mail.gmail.com>
In-Reply-To
<xmqqlexq8zqo.fsf@gitster.g>
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
 apply.c      |  2 +-
 apply.h      |  2 ++
 builtin/am.c | 14 ++++++++++++--
 3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/apply.c b/apply.c
index 0912307bd9..28e6fe0cfa 100644
--- a/apply.c
+++ b/apply.c
@@ -36,7 +36,7 @@ static void git_apply_config(void)
 	git_config(git_xmerge_config, NULL);
 }
 
-static int parse_whitespace_option(struct apply_state *state, const char *option)
+int parse_whitespace_option(struct apply_state *state, const char *option)
 {
 	if (!option) {
 		state->ws_error_action = warn_on_ws_error;
diff --git a/apply.h b/apply.h
index 4052da50c0..c931786a2a 100644
--- a/apply.h
+++ b/apply.h
@@ -173,6 +173,8 @@ int parse_git_diff_header(struct strbuf *root,
 			  unsigned int size,
 			  struct patch *patch);
 
+int parse_whitespace_option(struct apply_state *state, const char *option);
+
 /*
  * Some aspects of the apply behavior are controlled by the following
  * bits in the "options" parameter passed to apply_all_patches().
diff --git a/builtin/am.c b/builtin/am.c
index 0f4111bafa..542c6c5cab 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -2298,6 +2298,16 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar
 	return 0;
 }
 
+static int parse_opt_whitespace(const struct option *opt, const char *arg, int unset)
+{
+	struct apply_state dummy = { };
+
+	if (parse_whitespace_option(&dummy, arg))
+		return -1;
+
+	return parse_opt_passthru_argv(opt, arg, unset);
+}
+
 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: Junio C HamanoNext: Junio C Hamano
Message 3 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.