Skip to content

Commit 70af766

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9724e6f commit 70af766

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

builtin/apply.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ static int gitdiff_hdrend(struct apply_state *state,
812812
const char *line,
813813
struct patch *patch)
814814
{
815-
return -1;
815+
return 1;
816816
}
817817

818818
/*
@@ -1016,7 +1016,7 @@ static int gitdiff_unrecognized(struct apply_state *state,
10161016
const char *line,
10171017
struct patch *patch)
10181018
{
1019-
return -1;
1019+
return 1;
10201020
}
10211021

10221022
/*
@@ -1248,9 +1248,13 @@ static int parse_git_header(struct apply_state *state,
12481248
for (i = 0; i < ARRAY_SIZE(optable); i++) {
12491249
const struct opentry *p = optable + i;
12501250
int oplen = strlen(p->str);
1251+
int res;
12511252
if (len < oplen || memcmp(p->str, line, oplen))
12521253
continue;
1253-
if (p->fn(state, line + oplen, patch) < 0)
1254+
res = p->fn(state, line + oplen, patch);
1255+
if (res < 0)
1256+
return -1;
1257+
if (res > 0)
12541258
return offset;
12551259
break;
12561260
}
@@ -1430,6 +1434,8 @@ static int find_header(struct apply_state *state,
14301434
*/
14311435
if (!memcmp("diff --git ", line, 11)) {
14321436
int git_hdr_len = parse_git_header(state, line, len, size, patch);
1437+
if (git_hdr_len < 0)
1438+
return -128;
14331439
if (git_hdr_len <= len)
14341440
continue;
14351441
if (!patch->old_name && !patch->new_name) {

0 commit comments

Comments
 (0)