aboutsummaryrefslogtreecommitdiff
path: root/diff.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 /diff.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 'diff.c')
-rw-r--r--diff.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/diff.c b/diff.c
index 0d30d0526..c054b234b 100644
--- a/diff.c
+++ b/diff.c
@@ -9,6 +9,7 @@
#include "xdiff-interface.h"
#include "color.h"
#include "attr.h"
+#include "strbuf.h"
#ifdef NO_FAST_WORKING_DIRECTORY
#define FAST_WORKING_DIRECTORY 0
@@ -1545,26 +1546,16 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
static int populate_from_stdin(struct diff_filespec *s)
{
-#define INCREMENT 1024
- char *buf;
- unsigned long size;
- ssize_t got;
-
- size = 0;
- buf = NULL;
- while (1) {
- buf = xrealloc(buf, size + INCREMENT);
- got = xread(0, buf + size, INCREMENT);
- if (!got)
- break; /* EOF */
- if (got < 0)
- return error("error while reading from stdin %s",
+ struct strbuf buf;
+
+ strbuf_init(&buf);
+ if (strbuf_read(&buf, 0) < 0)
+ return error("error while reading from stdin %s",
strerror(errno));
- size += got;
- }
+
s->should_munmap = 0;
- s->data = buf;
- s->size = size;
+ s->size = buf.len;
+ s->data = strbuf_detach(&buf);
s->should_free = 1;
return 0;
}