aboutsummaryrefslogtreecommitdiff
path: root/builtin-apply.c
diff options
context:
space:
mode:
authorPierre Habouzit <madcoder@debian.org>2007-09-06 13:20:09 +0200
committerJunio C Hamano <gitster@pobox.com>2007-09-06 23:57:44 -0700
commitaf6eb82262e35687aa8f00d688e327cb845973fa (patch)
tree6220d0ed4ed1bd6838ce9aa5565de2d0a193f307 /builtin-apply.c
parentd52bc66152834dff3fb5f32a54f6ed57730f58c6 (diff)
downloadgit-af6eb82262e35687aa8f00d688e327cb845973fa.tar.gz
git-af6eb82262e35687aa8f00d688e327cb845973fa.tar.xz
Use strbuf API in apply, blame, commit-tree and diff
Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-apply.c')
-rw-r--r--builtin-apply.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/builtin-apply.c b/builtin-apply.c
index 976ec7704..90e328ef9 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -12,6 +12,7 @@
#include "blob.h"
#include "delta.h"
#include "builtin.h"
+#include "strbuf.h"
/*
* --check turns on checking that the working tree matches the
@@ -181,34 +182,21 @@ static void say_patch_name(FILE *output, const char *pre, struct patch *patch, c
static void *read_patch_file(int fd, unsigned long *sizep)
{
- unsigned long size = 0, alloc = CHUNKSIZE;
- void *buffer = xmalloc(alloc);
+ struct strbuf buf;
- for (;;) {
- ssize_t nr = alloc - size;
- if (nr < 1024) {
- alloc += CHUNKSIZE;
- buffer = xrealloc(buffer, alloc);
- nr = alloc - size;
- }
- nr = xread(fd, (char *) buffer + size, nr);
- if (!nr)
- break;
- if (nr < 0)
- die("git-apply: read returned %s", strerror(errno));
- size += nr;
- }
- *sizep = size;
+ strbuf_init(&buf);
+ if (strbuf_read(&buf, fd) < 0)
+ die("git-apply: read returned %s", strerror(errno));
+ *sizep = buf.len;
/*
* Make sure that we have some slop in the buffer
* so that we can do speculative "memcmp" etc, and
* see to it that it is NUL-filled.
*/
- if (alloc < size + SLOP)
- buffer = xrealloc(buffer, size + SLOP);
- memset((char *) buffer + size, 0, SLOP);
- return buffer;
+ strbuf_grow(&buf, SLOP);
+ memset(buf.buf + buf.len, 0, SLOP);
+ return strbuf_detach(&buf);
}
static unsigned long linelen(const char *buffer, unsigned long size)