Skip to content
  • René Scharfe's avatar
    apply: update line lengths for --inaccurate-eof · 4855de12
    René Scharfe authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    Some diff implementations don't report missing newlines at the end of
    files.  Applying such a patch can cause a newline character to be
    added inadvertently.  The option --inaccurate-eof of git apply can be
    used to remove trailing newlines if needed.
    
    apply_one_fragment() cuts it off from the buffers for preimage and
    postimage.  Before it does, it builds an array with the lengths of each
    line for both.  Make sure to update the length of the last line in
    these line info structures as well to keep them consistent with their
    respective buffer.
    
    Without this fix the added test fails; git apply dies and reports:
    
       fatal: BUG: caller miscounted postlen: asked 1, orig = 1, used = 2
    
    That sanity check is only called if whitespace changes are ignored.
    
    Reported-by: default avatarMahmoud Al-Qudsi <mqudsi@neosmart.net>
    Signed-off-by: default avatarRene Scharfe <l.s.r@web.de>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    4855de12