builtin/apply: make gitdiff_*() return 1 at end of header
[gitweb.git] / builtin / apply.c
index f99498b5cb07d5df15c4c0afb037fd435a0e42f5..eb918e583b989beb1030cc8be16f1bf601c6166d 100644 (file)
@@ -812,7 +812,7 @@ static int gitdiff_hdrend(struct apply_state *state,
                          const char *line,
                          struct patch *patch)
 {
-       return -1;
+       return 1;
 }
 
 /*
@@ -1016,7 +1016,7 @@ static int gitdiff_unrecognized(struct apply_state *state,
                                const char *line,
                                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++) {
                        const struct opentry *p = optable + i;
                        int oplen = strlen(p->str);
+                       int res;
                        if (len < oplen || memcmp(p->str, line, oplen))
                                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;
                        break;
                }
@@ -1430,6 +1434,8 @@ static int find_header(struct apply_state *state,
                 */
                if (!memcmp("diff --git ", line, 11)) {
                        int git_hdr_len = parse_git_header(state, line, len, size, patch);
+                       if (git_hdr_len < 0)
+                               return -128;
                        if (git_hdr_len <= len)
                                continue;
                        if (!patch->old_name && !patch->new_name) {