mirror of
https://github.com/git/git.git
synced 2024-11-18 02:53:55 +01:00
builtin/apply: make gitdiff_*() return 1 at end of header
The gitdiff_*() functions that are called as p->fn() in parse_git_header() should return 1 instead of -1 in case of end of header or unrecognized input, as these are not real errors. It just instructs the parser to break out. This makes it possible for gitdiff_*() functions to return -1 in case of a real error. This will be done in a following patch. Helped-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
9724e6ff48
commit
70af7662d4
@ -812,7 +812,7 @@ static int gitdiff_hdrend(struct apply_state *state,
|
|||||||
const char *line,
|
const char *line,
|
||||||
struct patch *patch)
|
struct patch *patch)
|
||||||
{
|
{
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1016,7 +1016,7 @@ static int gitdiff_unrecognized(struct apply_state *state,
|
|||||||
const char *line,
|
const char *line,
|
||||||
struct patch *patch)
|
struct patch *patch)
|
||||||
{
|
{
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1248,9 +1248,13 @@ static int parse_git_header(struct apply_state *state,
|
|||||||
for (i = 0; i < ARRAY_SIZE(optable); i++) {
|
for (i = 0; i < ARRAY_SIZE(optable); i++) {
|
||||||
const struct opentry *p = optable + i;
|
const struct opentry *p = optable + i;
|
||||||
int oplen = strlen(p->str);
|
int oplen = strlen(p->str);
|
||||||
|
int res;
|
||||||
if (len < oplen || memcmp(p->str, line, oplen))
|
if (len < oplen || memcmp(p->str, line, oplen))
|
||||||
continue;
|
continue;
|
||||||
if (p->fn(state, line + oplen, patch) < 0)
|
res = p->fn(state, line + oplen, patch);
|
||||||
|
if (res < 0)
|
||||||
|
return -1;
|
||||||
|
if (res > 0)
|
||||||
return offset;
|
return offset;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1430,6 +1434,8 @@ static int find_header(struct apply_state *state,
|
|||||||
*/
|
*/
|
||||||
if (!memcmp("diff --git ", line, 11)) {
|
if (!memcmp("diff --git ", line, 11)) {
|
||||||
int git_hdr_len = parse_git_header(state, line, len, size, patch);
|
int git_hdr_len = parse_git_header(state, line, len, size, patch);
|
||||||
|
if (git_hdr_len < 0)
|
||||||
|
return -128;
|
||||||
if (git_hdr_len <= len)
|
if (git_hdr_len <= len)
|
||||||
continue;
|
continue;
|
||||||
if (!patch->old_name && !patch->new_name) {
|
if (!patch->old_name && !patch->new_name) {
|
||||||
|
Loading…
Reference in New Issue
Block a user