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

Broken WS_BLANK_AT_EOF highlighting with 0-length diff hunks

From
ACAlice Carlotti <alice.carlotti@arm.com>
Date
Oct 27, 2025, 13:20 UTC
Message-ID
<5447f4f0-68be-b554-9fde-579a8dac69ff@e124511.cambridge.arm.com>

Whitespace error highlighting is missing for blank lines at end of file when the final hunk contains either zero old lines or zero new lines. This most commonly occurs with new files (which happens to be when WS_BLANK_AT_EOF errors are most likely to be introduced), but can also occur with -U0.

The reason for this is that the initial line number in a hunk header is reduced by one for zero length ranges. In particular, an empty file uses 0,0 whereas a full nonempty file uses 1,N. This discrepancy is deliberate, and was agreed in https://lore.kernel.org/git/7vbqvictsc.fsf@assigned-by-dhcp.cox.net/.

We currently parse the hunk headers in diff.c:find_lno(). We could therefore fix the bug here by incrementing lno_in_{pre|post}image whenever the corresponding length is zero. Parsing the full ranges is complicated, but I notice that there is code to do this in apply.c:parse_range() - perhaps this code could be copied or reused? IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Message 1 of 1 in “Broken WS_BLANK_AT_EOF highlighting with 0-length diff hunks”
  1. Alice CarlottiOct 27, 2025

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.