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

Re: [PATCH] Fix 'No newline...' annotation in rewrite diffs.

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 2, 2012, 21:52 UTC
Message-ID
<7vipd1c66f.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20120802213346.GA575@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 9 quoted lines
> On Thu, Aug 02, 2012 at 10:11:02PM +0100, Adam Butcher wrote:
>
>> From 01730a741cc5fd7d0a5d8bd0d3df80d12c81fe48 Mon Sep 17 00:00:00 2001
>> From: Adam Butcher <dev.lists@jessamine.co.uk>
>> Date: Wed, 1 Aug 2012 22:25:09 +0100
>> Subject: [PATCH] Fix 'No newline...' annotation in rewrite diffs.
>
> You can drop these lines from the email body; they are redundant with
> what's in your actual header.
s/can/should/ actually, for readability.
Show 29 quoted lines
>> When operating in --break-rewrites (-B) mode on a file with no newline
>> terminator (and assuming --break-rewrites determines that the diff
>> _is_ a rewrite), git diff previously concatenated the indicator comment
>> '\ No newline at end of file' directly to the terminating line rather
>> than on a line of its own.  The resulting diff is broken; claiming
>> that the last line actually contains the indicator text.  Without -B
>> there is no problem with the same files.
>> 
>> This patch fixes the former case by inserting a newline into the
>> output prior to emitting the indicator comment.
>
> Makes sense.
>
>> Potential issue: Currently this emits an ASCII 10 newline character
>> only.  I'm not sure whether this will be okay on all platforms; it
>> seems to work fine on Windows and GNU at least.
>
> This should not be a problem. Git always outputs newlines; it is stdio
> who might munge it into CRLF if need be (and your patch uses putc, so we
> should be fine).
>
>> A couple of tests have been added to the rewrite suite to confirm that
>> the indicator comment is generated on its own line in both plain diff
>> and rewrite mode.  The latter test fails if the functional part of
>> this patch (i.e. diff.c) is reverted.
>
> Yay, tests.
>
>> ---
Sign-off needed.
Show 44 quoted lines
>>  diff.c                  |  1 +
>>  t/t4022-diff-rewrite.sh | 27 +++++++++++++++++++++++++++
>>  2 files changed, 28 insertions(+)
>> 
>> diff --git a/diff.c b/diff.c
>> index 95706a5..77d4e84 100644
>> --- a/diff.c
>> +++ b/diff.c
>> @@ -574,6 +574,7 @@ static void emit_rewrite_lines(struct
>> emit_callback *ecb,
>
> Your patch is line-wrapped and cannot be applied as-is (try turning off
> "flowed text" in your MUA).
>
>>  	if (!endp) {
>>  		const char *plain = diff_get_color(ecb->color_diff,
>>  						   DIFF_PLAIN);
>> +		putc('\n', ecb->opt->file);
>>  		emit_line_0(ecb->opt, plain, reset, '\\',
>>  			    nneof, strlen(nneof));
>>  	}
>
> Looks correct. I was curious how the regular (non-rewrite) code path did
> this, and it just sticks the "\n" as part of the nneof string. However,
> we would not want that here, because each line should have its own
> color markers.
>
>> +# create a file containing numbers with no newline at
>> +# the end and modify it such that the starting 10 lines
>> +# are unchanged, the next 101 are rewritten and the last
>> +# line differs only in that in is terminated by a newline.
>> +seq 1 10 > seq
>> +seq 100 +1 200 >> seq
>> +printf 201 >> seq
>> +(git add seq; git commit seq -m seq) >/dev/null
>> +seq 1 10 > seq
>> +seq 300 -1 200 >> seq
>
> Seq is (unfortunately) not portable. I usually use a perl snippet
> instead, like:
>
>   perl -le 'print for (1..10)'
>
> Though I think we are adjusting that to use $PERL_PATH these days.

t/perf/perf-lib.sh and t/t5551-http-fetch.sh seem to use "seq"; perhaps we should replace them, then.

Previous: Jeff KingNext: Jeff King
Message 3 of 34 in “Fix 'No newline...' annotation in rewrite diffs.”
  1. Fix 'No newline...' annotation in rewrite diffs.Adam Butcher, Aug 2, 2012
  2. Jeff KingAug 2, 2012
  3. Junio C HamanoAug 2, 2012
  4. Jeff KingAug 2, 2012
  5. Michał KiedrowiczAug 3, 2012
  6. Jeff KingAug 3, 2012
  7. Junio C HamanoAug 3, 2012
  8. Jeff KingAug 3, 2012
  9. tests: Introduce test_seqMichał Kiedrowicz, Aug 3, 2012
  10. Jeff KingAug 3, 2012
  11. Junio C HamanoAug 3, 2012
  12. Jeff KingAug 3, 2012
  13. Michał KiedrowiczAug 3, 2012
  14. Johannes SixtAug 4, 2012
  15. Junio C HamanoAug 4, 2012
  16. Michał KiedrowiczAug 6, 2012
  17. Jeff KingAug 6, 2012
  18. tests: Introduce test_seqMichał Kiedrowicz, Aug 3, 2012
  19. Junio C HamanoAug 3, 2012
  20. Jeff KingAug 3, 2012
  21. Junio C HamanoAug 3, 2012
  22. Michał KiedrowiczAug 4, 2012
  23. Adam ButcherAug 4, 2012
  24. tests: Introduce test_seqMichał Kiedrowicz, Aug 3, 2012
  25. Jeff KingAug 3, 2012
  26. Michał KiedrowiczAug 3, 2012
  27. tests: Introduce test_seqMichał Kiedrowicz, Aug 3, 2012
  28. Jeff KingAug 3, 2012
  29. Adam ButcherAug 2, 2012
  30. Junio C HamanoAug 2, 2012
  31. Adam ButcherAug 2, 2012
  32. Adam ButcherAug 4, 2012
  33. Junio C HamanoAug 5, 2012
  34. Fix '\ No newline...' annotation in rewrite diffsAdam Butcher, Aug 5, 2012

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.