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

Re: [PATCH 3/5] apply: whitespace errors in context lines if we have

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 27, 2024, 16:12 UTC
Message-ID
<xmqqplpuaqsr.fsf@gitster.g>
In-Reply-To
<xmqqv7zmd9a5.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 19 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Hmph.  0a80bc9f (apply: detect and mark whitespace errors in context
>> lines when fixing, 2015-01-16) deliberately added this check because
>> we will correct the whitespace breakages on these lines after
>> parsing the hunk with this function while applying.
> ...
> So, I am inclined to say that
>
>  * we propose to get rid of that "a single input may touch the same
>    path TWICE" feature at Git 3.0 boundary.
>
>  * we at the same time apply [3/5] (and possibly others, but I do
>    not think we want [1/5]).
>
> But until we can shed our pretense that the "single input may touch
> the same path TWICE" is seriously supported, I do not think applying
> this series as-is makes sense, as it directly contradicts with that
> (mis)feature.

So, here is another thought. Can we notice that we are dealing with such an irregular patch that we would never produce ourselves, but still have to support as a historical wart? And deal with context lines with whitespace breakages differently if that is the case.

I think that is doable. I won't address the entire set of fixes in your series, but a touched up version of your [3/5] may look like the attached at the end. This is on top of your whole series, not as a replacement for [3/5], made just for illustration purposes.

Show 5 quoted lines
>> It is iffy that this case arm for " " kicks in ONLY when applying in
>> the forward direction (which is not what you are changing).  When
>> applying a patch in reverse, " " is still an "unchanged" context
>> line, so we should be treating it the same way regardless of the
>> direction.

I didn't address this "why only in the forward direction?" iffyness in the illustration patch, by the way.

 apply.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git c/apply.c w/apply.c
index e6df8b6ab4..04bb094e57 100644
--- c/apply.c
+++ w/apply.c
@@ -38,6 +38,8 @@
 #include "wildmatch.h"
 #include "ws.h"
 
+static struct patch *in_fn_table(struct apply_state *state, const char *name);
+
 struct gitdiff_data {
 	struct strbuf *root;
 	int linenr;
@@ -1697,10 +1699,13 @@ static int parse_fragment(struct apply_state *state,
 	int len = linelen(line, size), offset;
 	unsigned long oldlines, newlines;
 	unsigned long leading, trailing;
+	int touching_same_path; 
 
 	offset = parse_fragment_header(line, len, fragment);
 	if (offset < 0)
 		return -1;
+
+	touching_same_path = !!in_fn_table(state, patch->old_name);
 	if (offset > 0 && patch->recount)
 		recount_diff(line + offset, size - offset, fragment);
 	oldlines = fragment->oldlines;
@@ -1734,7 +1739,8 @@ static int parse_fragment(struct apply_state *state,
 			check_old_for_crlf(patch, line, len);
 			if (!state->apply_in_reverse &&
 			    state->ws_error_action == correct_ws_error &&
-			    state->ws_ignore_action != ignore_ws_none)
+			    (touching_same_path ||
+			     state->ws_ignore_action != ignore_ws_none))
 				check_whitespace(state, line, len, patch->ws_rule);
 			break;
 		case '-':
Previous: Junio C HamanoNext: Junio C Hamano
Message 14 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.