range-diff: don't segfault with mode-only changes
In ef283b3699
("apply: make parse_git_diff_header public", 2019-07-11)
the 'parse_git_diff_header' function was made public and useable by
callers outside of apply.c.
However it was missed that its (then) only caller, 'find_header' did
some error handling, and completing 'struct patch' appropriately.
range-diff then started using this function, and tried to handle this
appropriately itself, but fell short in some cases. This in turn
would lead to range-diff segfaulting when there are mode-only changes
in a range.
Move the error handling and completing of the struct into the
'parse_git_diff_header' function, so other callers can take advantage
of it. This fixes the segfault in 'git range-diff'.
Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
499352c2ad
commit
2b6a9b13ca
@ -226,6 +226,46 @@ test_expect_success 'renamed file' '
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success 'file with mode only change' '
|
||||
git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
|
||||
sed s/Z/\ /g >expected <<-EOF &&
|
||||
1: fccce22 ! 1: 4d39cb3 s/4/A/
|
||||
@@ Metadata
|
||||
ZAuthor: Thomas Rast <trast@inf.ethz.ch>
|
||||
Z
|
||||
Z ## Commit message ##
|
||||
- s/4/A/
|
||||
+ s/4/A/ + add other-file
|
||||
Z
|
||||
Z ## file ##
|
||||
Z@@
|
||||
@@ file
|
||||
Z A
|
||||
Z 6
|
||||
Z 7
|
||||
+
|
||||
+ ## other-file (new) ##
|
||||
2: 147e64e ! 2: 26c107f s/11/B/
|
||||
@@ Metadata
|
||||
ZAuthor: Thomas Rast <trast@inf.ethz.ch>
|
||||
Z
|
||||
Z ## Commit message ##
|
||||
- s/11/B/
|
||||
+ s/11/B/ + mode change other-file
|
||||
Z
|
||||
Z ## file ##
|
||||
Z@@ file: A
|
||||
@@ file: A
|
||||
Z 12
|
||||
Z 13
|
||||
Z 14
|
||||
+
|
||||
+ ## other-file (mode change 100644 => 100755) ##
|
||||
3: a63e992 = 3: 4c1e0f5 s/12/B/
|
||||
EOF
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success 'file added and later removed' '
|
||||
git range-diff --no-color --submodule=log topic...added-removed >actual &&
|
||||
sed s/Z/\ /g >expected <<-EOF &&
|
||||
|
Reference in New Issue
Block a user