git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Alice Carlotti <alice.carlotti@arm.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: Broken WS_BLANK_AT_EOF highlighting with 0-length diff hunks
Date: Mon, 27 Oct 2025 13:20:03 +0000	[thread overview]
Message-ID: <5447f4f0-68be-b554-9fde-579a8dac69ff@e124511.cambridge.arm.com> (raw)

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.


                 reply	other threads:[~2025-10-27 13:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5447f4f0-68be-b554-9fde-579a8dac69ff@e124511.cambridge.arm.com \
    --to=alice.carlotti@arm.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).