freebsd-skq/usr.bin/patch
Warner Losh c7cddf955f Remove heuristic for dealing with trailing newlines being truncated by mailers.
Every version of patch since the first one posted to mod.sources in 1985 have
included a heuristic for coping with the state of email messaging at the
time. This heuristic would add up to 4 blank lines to a patch if it thought it
needed it. The trouble is, though this causes at least one bug.

The bug in my case is that if you have a context diff whose last hunk only
deletes 3 or fewer lines, then if you try to reverse apply it with -R, it will
fail. The reason for this is the heuristic builds an internal representation
that includes those blank lines. However, it should really replicate the lines
from the pattern lines line it would any other time, not assume they are blank
lines. Removing this heuristic will prevent patch from misapplying the lines
removed after applying a 'fuzz' factor to the previous blank line in the file. I
believe this will only affect 'new-style' 4.3BSD context diffs and not the
older-style 4.2BSD diffs and plain, non-context diffs. It won't affect any of
the newer formats, since they don't use the 'omitted' construct in the same way.

Since this heuristic was put into patch at a time when email / etc ate trailing
white space on a regular basis, and since it's clear that this heuristic is the
wrong thing to do at least some of the time, it's better to remove it
entirely. It's not been needed for maybe 20 years since patch files are not
usually corrupted. If there are a small number of patch files that would benefit
from this corruption fixing, those already-currupt patches can be fixed by the
addition of blank lines. I'd wager that no one will ever come to me with an
example of a once-working patch file that breaks with this change. However, I
have 2 patches from the first 195 patches to 2.11BSD that are affected by this
bug, suggesting that the relative frequency of the issue has changed
signficantly since the original heuristic was put into place.

Reviewed by: phk@
Differential Revision: https://reviews.freebsd.org/D26081
2020-08-16 23:55:23 +00:00
..
tests patch(1): give /dev/null patches special treatment 2019-11-04 03:07:01 +00:00
backupfile.c
backupfile.h
common.h patch(1): Exit successfully if we're fed a 0-length patch 2019-03-01 01:20:21 +00:00
inp.c patch(1): Don't check for NUL bytes in Plan A 2018-01-11 15:01:48 +00:00
inp.h
Makefile patch(1): add some basic tests 2019-09-05 03:16:14 +00:00
Makefile.depend
mkpath.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
patch.1 patch(1): give /dev/null patches special treatment 2019-11-04 03:07:01 +00:00
patch.c patch(1): give /dev/null patches special treatment 2019-11-04 03:07:01 +00:00
pathnames.h
pch.c Remove heuristic for dealing with trailing newlines being truncated by mailers. 2020-08-16 23:55:23 +00:00
pch.h patch(1): give /dev/null patches special treatment 2019-11-04 03:07:01 +00:00
util.c patch(1): give /dev/null patches special treatment 2019-11-04 03:07:01 +00:00
util.h