]> git.ipfire.org Git - thirdparty/git.git/commit
apply: revamp the parsing of incomplete lines
authorJunio C Hamano <gitster@pobox.com>
Wed, 12 Nov 2025 22:02:54 +0000 (14:02 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Nov 2025 22:04:04 +0000 (14:04 -0800)
commit3a4eb5ad2e9166255d5921196470710523f24ec4
tree8a74ba0cc4526f24ecf2ccecefa9b71c2bf82298
parent8d8e3c61874bbcf50d64aff34fb6c533458adf5e
apply: revamp the parsing of incomplete lines

A patch file represents the incomplete line at the end of the file
with two lines, one that is the usual "context" with " " as the
first letter, "added" with "+" as the first letter, or "removed"
with "-" as the first letter that shows the content of the line,
plus an extra "\ No newline at the end of file" line that comes
immediately after it.

Ever since the apply machinery was written, the "git apply"
machinery parses "\ No newline at the end of file" line
independently, without even knowing what line the incomplete-ness
applies to, simply because it does not even remember what the
previous line was.

This poses a problem if we want to check and warn on an incomplete
line.  Revamp the code that parses a fragment, to actually drop the
'\n' at the end of the incoming patch file that terminates a line,
so that check_whitespace() calls made from the code path actually
sees an incomplete as incomplete.

Note that the result of this parsing is not directly used by the
code path that applies the patch.  apply_one_fragment() function
already checks if each of the patch text it handles is followed by a
line that begins with a backslash to drop the newline at the end of
the current line it is looking at.  In a sense, this patch harmonizes
the behaviour of the parsing side to what is already done in the
application side.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
apply.c