summaryrefslogtreecommitdiff
path: root/apply.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-10-15 04:48:02 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-10-15 04:48:02 (GMT)
commitb6d712fa4e11e51e479b9e25090afff85e5d710a (patch)
treee087924cba548832c282a08eb20c973c8e1ea265 /apply.c
parent77458870a5b1ab4d7c8f2c4825e888571a32979b (diff)
parent2b6a9b13ca4a687aeb0cad5f32e49711b3e67aaa (diff)
downloadgit-b6d712fa4e11e51e479b9e25090afff85e5d710a.zip
git-b6d712fa4e11e51e479b9e25090afff85e5d710a.tar.gz
git-b6d712fa4e11e51e479b9e25090afff85e5d710a.tar.bz2
Merge branch 'tg/range-diff-output-update'
"git range-diff" failed to handle mode-only change, which has been corrected. * tg/range-diff-output-update: range-diff: don't segfault with mode-only changes
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/apply.c b/apply.c
index 57a61f2..f8a046a 100644
--- a/apply.c
+++ b/apply.c
@@ -1361,11 +1361,32 @@ int parse_git_diff_header(struct strbuf *root,
if (check_header_line(*linenr, patch))
return -1;
if (res > 0)
- return offset;
+ goto done;
break;
}
}
+done:
+ if (!patch->old_name && !patch->new_name) {
+ if (!patch->def_name) {
+ error(Q_("git diff header lacks filename information when removing "
+ "%d leading pathname component (line %d)",
+ "git diff header lacks filename information when removing "
+ "%d leading pathname components (line %d)",
+ parse_hdr_state.p_value),
+ parse_hdr_state.p_value, *linenr);
+ return -128;
+ }
+ patch->old_name = xstrdup(patch->def_name);
+ patch->new_name = xstrdup(patch->def_name);
+ }
+ if ((!patch->new_name && !patch->is_delete) ||
+ (!patch->old_name && !patch->is_new)) {
+ error(_("git diff header lacks filename information "
+ "(line %d)"), *linenr);
+ return -128;
+ }
+ patch->is_toplevel_relative = 1;
return offset;
}
@@ -1546,26 +1567,6 @@ static int find_header(struct apply_state *state,
return -128;
if (git_hdr_len <= len)
continue;
- if (!patch->old_name && !patch->new_name) {
- if (!patch->def_name) {
- error(Q_("git diff header lacks filename information when removing "
- "%d leading pathname component (line %d)",
- "git diff header lacks filename information when removing "
- "%d leading pathname components (line %d)",
- state->p_value),
- state->p_value, state->linenr);
- return -128;
- }
- patch->old_name = xstrdup(patch->def_name);
- patch->new_name = xstrdup(patch->def_name);
- }
- if ((!patch->new_name && !patch->is_delete) ||
- (!patch->old_name && !patch->is_new)) {
- error(_("git diff header lacks filename information "
- "(line %d)"), state->linenr);
- return -128;
- }
- patch->is_toplevel_relative = 1;
*hdrsize = git_hdr_len;
return offset;
}