]> git.ipfire.org Git - thirdparty/git.git/commit
builtin add -p: fix hunk splitting
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Tue, 11 Jan 2022 11:12:10 +0000 (11:12 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Jan 2022 18:29:53 +0000 (10:29 -0800)
commit7008ddc645cf8a6783d23b4ccdae0b74b096bd9e
tree2101f68fbb4cfdfea064946b0c98bf478a6c07fb
parentd16632f6942568019dec21447da1ecc58dba98e0
builtin add -p: fix hunk splitting

The C reimplementation of "add -p" fails to split the last hunk in a
file if hunk ends with an addition or deletion without any post context
line unless it is the last file to be processed.

To determine whether a hunk can be split a counter is incremented each
time a context line follows an insertion or deletion. If at the end of
the hunk the value of this counter is greater than one then the hunk
can be split into that number of smaller hunks. If the last hunk in a
file ends with an insertion or deletion then there is no following
context line and the counter will not be incremented. This case is
already handled at the end of the loop where counter is incremented if
the last hunk ended with an insertion or deletion. Unfortunately there
is no similar check between files (likely because the perl version
only ever parses one diff at a time). Fix this by checking if the last
hunk ended with an insertion or deletion when we see the diff header
of a new file and extend the existing regression test.

Reproted-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
add-patch.c
t/t3701-add-interactive.sh