Skip to content

Commit 3bee345

Browse files
chriscoolgitster
authored andcommitted
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>
1 parent f07a9f7 commit 3bee345

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

builtin/apply.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,10 @@ static void say_patch_name(FILE *output, const char *fmt, struct patch *patch)
335335

336336
#define SLOP (16)
337337

338-
static void read_patch_file(struct strbuf *sb, int fd)
338+
static int read_patch_file(struct strbuf *sb, int fd)
339339
{
340340
if (strbuf_read(sb, fd, 0) < 0)
341-
die_errno("git apply: failed to read");
341+
return error_errno("git apply: failed to read");
342342

343343
/*
344344
* Make sure that we have some slop in the buffer
@@ -347,6 +347,7 @@ static void read_patch_file(struct strbuf *sb, int fd)
347347
*/
348348
strbuf_grow(sb, SLOP);
349349
memset(sb->buf + sb->len, 0, SLOP);
350+
return 0;
350351
}
351352

352353
static unsigned long linelen(const char *buffer, unsigned long size)
@@ -4425,7 +4426,8 @@ static int apply_patch(struct apply_state *state,
44254426
int res = 0;
44264427

44274428
state->patch_input_file = filename;
4428-
read_patch_file(&buf, fd);
4429+
if (read_patch_file(&buf, fd) < 0)
4430+
return -128;
44294431
offset = 0;
44304432
while (offset < buf.len) {
44314433
struct patch *patch;

0 commit comments

Comments
 (0)