diff options
author | Christian Couder <christian.couder@gmail.com> | 2016-08-08 23:03:01 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-08-11 12:41:46 -0700 |
commit | 3bee345d7b6c7d95e9585b224320689979a58f9e (patch) | |
tree | ea7236e8826bb0259f8018c3469e88ac91467d27 /builtin/apply.c | |
parent | f07a9f7643c8b261b5d03d9c288c44916277f05e (diff) | |
download | git-3bee345d7b6c7d95e9585b224320689979a58f9e.tar.gz |
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>
Diffstat (limited to 'builtin/apply.c')
-rw-r--r-- | builtin/apply.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/builtin/apply.c b/builtin/apply.c index 435030a989..dd7afee09f 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -335,10 +335,10 @@ static void say_patch_name(FILE *output, const char *fmt, struct patch *patch) #define SLOP (16) -static void read_patch_file(struct strbuf *sb, int fd) +static int read_patch_file(struct strbuf *sb, int fd) { if (strbuf_read(sb, fd, 0) < 0) - die_errno("git apply: failed to read"); + return error_errno("git apply: failed to read"); /* * Make sure that we have some slop in the buffer @@ -347,6 +347,7 @@ static void read_patch_file(struct strbuf *sb, int fd) */ strbuf_grow(sb, SLOP); memset(sb->buf + sb->len, 0, SLOP); + return 0; } static unsigned long linelen(const char *buffer, unsigned long size) @@ -4425,7 +4426,8 @@ static int apply_patch(struct apply_state *state, int res = 0; state->patch_input_file = filename; - read_patch_file(&buf, fd); + if (read_patch_file(&buf, fd) < 0) + return -128; offset = 0; while (offset < buf.len) { struct patch *patch; |