builtin/apply: read_patch_file() return -1 instead of die()ing
To libify `git apply` functionality we have to signal errors to the caller instead of die()ing. Let's do that by returning -1 instead of die()ing in read_patch_file(). Helped-by: Stefan Beller <sbeller@google.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
3bee345d7b6c7d95e9585b224320689979a58f9e
1 file changed
+5
-3
builtin/apply.c
+5
-3
@@ -335,10 +335,10 @@ static void say_patch_name(FILE *output, const char *fmt, struct patch *patch)
335
336
#define SLOP (16)
337
338
-static void read_patch_file(struct strbuf *sb, int fd)
338
+static int read_patch_file(struct strbuf *sb, int fd)
339
{
340
if (strbuf_read(sb, fd, 0) < 0)
341
- die_errno("git apply: failed to read");
341
+ return error_errno("git apply: failed to read");
342
343
/*
344
* Make sure that we have some slop in the buffer
@@ -347,6 +347,7 @@ static void read_patch_file(struct strbuf *sb, int fd)
347
*/
348
strbuf_grow(sb, SLOP);
349
memset(sb->buf + sb->len, 0, SLOP);
350
+ return 0;
351
}
352
353
static unsigned long linelen(const char *buffer, unsigned long size)
@@ -4425,7 +4426,8 @@ static int apply_patch(struct apply_state *state,
4426
int res = 0;
4427
4428
state->patch_input_file = filename;
4428
- read_patch_file(&buf, fd);
4429
+ if (read_patch_file(&buf, fd) < 0)
4430
+ return -128;
4431
offset = 0;
4432
while (offset < buf.len) {
4433
struct patch *patch;