Skip to content

Commit 9724e6f

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

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

builtin/apply.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,10 @@ static int has_epoch_timestamp(const char *nameline)
755755
* files, we can happily check the index for a match, but for creating a
756756
* new file we should try to match whatever "patch" does. I have no idea.
757757
*/
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)
762762
{
763763
char *name;
764764

@@ -803,7 +803,9 @@ static void parse_traditional_patch(struct apply_state *state,
803803
}
804804
}
805805
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;
807809
}
808810

809811
static int gitdiff_hdrend(struct apply_state *state,
@@ -1467,7 +1469,8 @@ static int find_header(struct apply_state *state,
14671469
continue;
14681470

14691471
/* 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;
14711474
*hdrsize = len + nextlen;
14721475
state->linenr += 2;
14731476
return offset;

0 commit comments

Comments
 (0)