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>
Christian Couder committed
Aug 8, 2016 at 23:03 UTC
70af7662d47ac9f450c248720a379a8db817163b
1 file changed
+9
-3
builtin/apply.c
+9
-3
@@ -812,7 +812,7 @@ static int gitdiff_hdrend(struct apply_state *state,
812
const char *line,
813
struct patch *patch)
814
{
815
- return -1;
815
+ return 1;
816
}
817
818
/*
@@ -1016,7 +1016,7 @@ static int gitdiff_unrecognized(struct apply_state *state,
1016
const char *line,
1017
struct patch *patch)
1018
{
1019
- return -1;
1019
+ return 1;
1020
}
1021
1022
/*
@@ -1248,9 +1248,13 @@ static int parse_git_header(struct apply_state *state,
1248
for (i = 0; i < ARRAY_SIZE(optable); i++) {
1249
const struct opentry *p = optable + i;
1250
int oplen = strlen(p->str);
1251
+ int res;
1252
if (len < oplen || memcmp(p->str, line, oplen))
1253
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)
1258
return offset;
1259
break;
1260
}
@@ -1430,6 +1434,8 @@ static int find_header(struct apply_state *state,
1434
*/
1435
if (!memcmp("diff --git ", line, 11)) {
1436
int git_hdr_len = parse_git_header(state, line, len, size, patch);
1437
+ if (git_hdr_len < 0)
1438
+ return -128;
1439
if (git_hdr_len <= len)
1440
continue;
1441
if (!patch->old_name && !patch->new_name) {