apply.c:update_pre_post_images(): the preimage can be truncated
commit5de7166d46d25fed3b8a181c3842cf4350ecdea4
authorJunio C Hamano <gitster@pobox.com>
Fri, 12 Oct 2012 22:53:46 +0000 (12 15:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Oct 2012 23:06:49 +0000 (12 16:06 -0700)
treee8a5471da611530d03a189b8f2000d6139c0af4b
parentbafc478f1618534fcb85bedc0fa224bd2d462441
apply.c:update_pre_post_images(): the preimage can be truncated

5166714 (apply: Allow blank context lines to match beyond EOF,
2010-03-06) and then later 0c3ef98 (apply: Allow blank *trailing*
context lines to match beyond EOF, 2010-04-08) taught "git apply"
to trim new blank lines at the end in the patch text when matching
the contents being patched and the preimage recorded in the patch,
under --whitespace=fix mode.

When a preimage is modified to match the current contents in
preparation for such a "fixed" patch application, the context lines
in the postimage must be updated to match (otherwise, it would
reintroduce whitespace breakages), and update_pre_post_images()
function is responsible for doing this.  However, this function was
not updated to take into account a case where the removal of
trailing blank lines reduces the number of lines in the preimage,
and triggered an assertion error.

The logic to fix the postimage by copying the corrected context
lines from the preimage was not prepared to handle this case,
either, but it was protected by the assert() and only got exposed
when the assertion is corrected.

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