builtin/apply: make parse_traditional_patch() return -1 on error
To libify `git apply` functionality we have to signal errors to the caller instead of die()ing. To do that in a compatible manner with the rest of the error handling in "builtin/apply.c", parse_traditional_patch() should return -1 instead of calling die(). 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
9724e6ff48506323ab897e2d9f8d27febd4d9bb0
1 file changed
+9
-6
builtin/apply.c
+9
-6
@@ -755,10 +755,10 @@ static int has_epoch_timestamp(const char *nameline)
755
* files, we can happily check the index for a match, but for creating a
756
* new file we should try to match whatever "patch" does. I have no idea.
757
*/
758
-static void parse_traditional_patch(struct apply_state *state,
759
- const char *first,
760
- const char *second,
761
- struct patch *patch)
758
+static int parse_traditional_patch(struct apply_state *state,
759
+ const char *first,
760
+ const char *second,
761
+ struct patch *patch)
762
{
763
char *name;
764
@@ -803,7 +803,9 @@ static void parse_traditional_patch(struct apply_state *state,
803
}
804
}
805
if (!name)
806
- die(_("unable to find filename in patch at line %d"), state->linenr);
806
+ return error(_("unable to find filename in patch at line %d"), state->linenr);
807
+
808
+ return 0;
809
}
810
811
static int gitdiff_hdrend(struct apply_state *state,
@@ -1467,7 +1469,8 @@ static int find_header(struct apply_state *state,
1469
continue;
1470
1471
/* Ok, we'll consider it a patch */
1470
- parse_traditional_patch(state, line, line+len, patch);
1472
+ if (parse_traditional_patch(state, line, line+len, patch))
1473
+ return -128;
1474
*hdrsize = len + nextlen;
1475
state->linenr += 2;
1476
return offset;