diff options
author | Christian Couder <christian.couder@gmail.com> | 2016-08-08 23:03:03 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-08-11 12:41:46 -0700 |
commit | b654b34c1cf877709febb602991f46e7ba0d947d (patch) | |
tree | 90367b55dae0dfcf095b7d6f42790a4a96264869 /builtin/apply.c | |
parent | builtin/apply: make find_header() return -128 instead of die()ing (diff) | |
download | tgif-b654b34c1cf877709febb602991f46e7ba0d947d.tar.xz |
builtin/apply: make parse_chunk() return a negative integer on error
To libify `git apply` functionality we have to signal errors to the
caller instead of die()ing or exit()ing.
To do that in a compatible manner with the rest of the error handling
in builtin/apply.c, parse_chunk() should return a negative integer
instead of calling die() or exit().
As parse_chunk() is called only by apply_patch() which already
returns either -1 or -128 when an error happened, let's make it also
return -1 or -128.
This makes it compatible with what find_header() and parse_binary()
already return.
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/apply.c')
-rw-r--r-- | builtin/apply.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/builtin/apply.c b/builtin/apply.c index 434ba0c542..c07d142be8 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -1996,22 +1996,22 @@ static int use_patch(struct apply_state *state, struct patch *p) return !state->has_include; } - /* * Read the patch text in "buffer" that extends for "size" bytes; stop * reading after seeing a single patch (i.e. changes to a single file). * Create fragments (i.e. patch hunks) and hang them to the given patch. - * Return the number of bytes consumed, so that the caller can call us - * again for the next patch. + * + * Returns: + * -1 if no header was found or parse_binary() failed, + * -128 on another error, + * the number of bytes consumed otherwise, + * so that the caller can call us again for the next patch. */ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long size, struct patch *patch) { int hdrsize, patchsize; int offset = find_header(state, buffer, size, &hdrsize, patch); - if (offset == -128) - exit(128); - if (offset < 0) return offset; @@ -2071,8 +2071,10 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si * empty to us here. */ if ((state->apply || state->check) && - (!patch->is_binary && !metadata_changes(patch))) - die(_("patch with only garbage at line %d"), state->linenr); + (!patch->is_binary && !metadata_changes(patch))) { + error(_("patch with only garbage at line %d"), state->linenr); + return -128; + } } return offset + hdrsize + patchsize; @@ -4455,6 +4457,10 @@ static int apply_patch(struct apply_state *state, nr = parse_chunk(state, buf.buf + offset, buf.len - offset, patch); if (nr < 0) { free_patch(patch); + if (nr == -128) { + res = -128; + goto end; + } break; } if (state->apply_in_reverse) |