]> git.ipfire.org Git - thirdparty/git.git/commit
add-patch: handle splitting hunks with diff.suppressBlankEmpty
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Sat, 20 Jul 2024 16:01:59 +0000 (16:01 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 Jul 2024 23:29:14 +0000 (16:29 -0700)
commit39bdd84eaf646aa73a3709b0eb8be3f47378708f
treec08b998aceb46bf881b76ed23525f262a1b4801d
parent337b4d400023d22207bcc3c29e9ebab31bf96fc2
add-patch: handle splitting hunks with diff.suppressBlankEmpty

When "add -p" parses diffs, it looks for context lines starting with a
single space. But when diff.suppressBlankEmpty is in effect, an empty
context line will omit the space, giving us a true empty line. This
confuses the parser, which is unable to split based on such a line.

It's tempting to say that we should just make sure that we generate a
diff without that option.  However, although we do not parse hunks that
the user has manually edited with parse_diff() we do allow the user
to split such hunks. As POSIX calls the decision of whether to print the
space here "implementation-defined" we need to handle edited hunks where
empty context lines omit the space.

So let's handle both cases: a context line either starts with a space or
consists of a totally empty line by normalizing the first character to a
space when we parse them. Normalizing the first character rather than
changing the code to check for a space or newline will hopefully future
proof against introducing similar bugs if the code is changed.

Reported-by: Ilya Tumaykin <itumaykin@gmail.com>
Helped-by: Jeff King <peff@peff.net>
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