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

[PATCH 1/5] apply: introduce `ignore_ws_default`

From
Rubén Justo <rjusto@gmail.com>
Date
Aug 25, 2024, 10:17 UTC
Message-ID
<5e35f260-056c-4af3-95d9-70d6f117bff9@gmail.com>
In-Reply-To
<6dd964c2-9dee-4257-8f1a-5bc31a73722e@gmail.com>

When we see `--whitespace=fix` we don't consider a possible option: `--no-ignore-whitespace`.

The expected result in the following example is a failure when applying the patch, however:

    $ printf "a \nb\nc\n" >file
    $ git add file
    $ cat >patch <<END
    --- a/file
    +++ b/file
    @@ -1,3 +1,2 @@
     a
    -b
     c
    END
    $ git apply --no-ignore-whitespace --whitespace=fix patch
    $ xxd file
    00000000: 610a 630a                                a.c.
This unexpected result will be addressed in an upcoming commit.

As a preparation, we need to detect when the user has explicitly said `--no-ignore-whitespace`.

Let's add a new value: `ignore_ws_default`, and use it to initialize `ws_ignore_action` in `init_apply_state()`. This will allow us to distinguish whether the user has explicitly set any value for `ws_ignore_action` via `--[no-]ignore-whitespace` or via `apply.ignoreWhitespace`.

Currently, we only have one explicit consideration for `ignore_ws_change`, and no, implicit or explicit, considerations for `ignore_ws_none`. Therefore, no modification to the existing logic is required in this step.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
---
 apply.c | 2 +-
 apply.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/apply.c b/apply.c
index 6e1060a952..63e58086f1 100644
--- a/apply.c
+++ b/apply.c
@@ -115,7 +115,7 @@ int init_apply_state(struct apply_state *state,
 	state->p_context = UINT_MAX;
 	state->squelch_whitespace_errors = 5;
 	state->ws_error_action = warn_on_ws_error;
-	state->ws_ignore_action = ignore_ws_none;
+	state->ws_ignore_action = ignore_ws_default;
 	state->linenr = 1;
 	string_list_init_nodup(&state->fn_table);
 	string_list_init_nodup(&state->limit_by_name);
diff --git a/apply.h b/apply.h
index cd25d24cc4..201f953a64 100644
--- a/apply.h
+++ b/apply.h
@@ -16,6 +16,7 @@ enum apply_ws_error_action {
 };
 
 enum apply_ws_ignore {
+	ignore_ws_default,
 	ignore_ws_none,
 	ignore_ws_change
 };
-- 
2.46.0.353.g385c909849
Previous: Rubén JustoNext: Junio C Hamano
Message 2 of 18 in “`--whitespace=fix` with `--no-ignore-whitespace`”
  1. 0/5 `--whitespace=fix` with `--no-ignore-whitespace`Rubén Justo, Aug 25, 2024
  2. 1/5 apply: introduce `ignore_ws_default`Rubén Justo, Aug 25, 2024
  3. Junio C HamanoAug 27, 2024
  4. 2/5 apply: honor `ignore_ws_none` with `correct_ws_error`Rubén Justo, Aug 25, 2024
  5. Junio C HamanoAug 27, 2024
  6. Rubén JustoAug 29, 2024
  7. Junio C HamanoAug 29, 2024
  8. Rubén JustoSep 3, 2024
  9. Junio C HamanoSep 4, 2024
  10. Rubén JustoSep 4, 2024
  11. 3/5 apply: whitespace errors in context lines if we haveRubén Justo, Aug 25, 2024
  12. Junio C HamanoAug 27, 2024
  13. Junio C HamanoAug 27, 2024
  14. Junio C HamanoAug 27, 2024
  15. Junio C HamanoAug 27, 2024
  16. 4/5 apply: error message in `record_ws_error()`Rubén Justo, Aug 25, 2024
  17. Junio C HamanoAug 27, 2024
  18. 5/5 t4124: move test preparation into the test contextRubén Justo, Aug 25, 2024

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.