Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2022-09-01 18:42:17 +0300
committerJunio C Hamano <gitster@pobox.com>2022-09-01 19:49:45 +0300
commitb6633a005384a8c120d34a8a79a5a5fe9d8719d7 (patch)
tree58520b4f0da6962b6566501a3e21c1ea47f44d6b /add-patch.c
parentad60dddad72dfb8367bd695028b5b8dc6c33661b (diff)
add -p: detect more mismatches between plain vs colored diffs
When parsing the colored version of a diff, the interactive `add` command really relies on the colored version having the same number of lines as the plain (uncolored) version. That is an invariant. We already have code to verify correctly when the colored diff has less lines than the plain diff. Modulo an off-by-one bug: If the last diff line has no matching colored one, the code pretends to succeed, still. To make matters worse, when we adjusted the test in 1e4ffc765db (t3701: adjust difffilter test, 2020-01-14), we did not catch this because `add -p` fails for a _different_ reason: it does not find any colored hunk header that contains a parseable line range. If we change the test case so that the line range _can_ be parsed, the bug is exposed. Let's address all of the above by - fixing the off-by-one, - adjusting the test case to allow `add -p` to parse the line range - making the test case more stringent by verifying that the expected error message is shown Also adjust a misleading code comment about the now-fixed code. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'add-patch.c')
-rw-r--r--add-patch.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/add-patch.c b/add-patch.c
index 509ca04456..34f3807ff3 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -592,7 +592,10 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
if (colored_eol)
colored_p = colored_eol + 1;
else if (p != pend)
- /* colored shorter than non-colored? */
+ /* non-colored has more lines? */
+ goto mismatched_output;
+ else if (colored_p == colored_pend)
+ /* last line has no matching colored one? */
goto mismatched_output;
else
colored_p = colored_pend;