Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-12-17 21:26:13 +0300
committerJunio C Hamano <gitster@pobox.com>2008-12-18 00:36:34 +0300
commitcf219d8c68ada1aa2855f4862f15753a32d09641 (patch)
treee74f4214cf23f10a46637d94ff81192e01f29dfd /diff.c
parentb760d3aa74585a96f0ccc4ce0374528a38be5177 (diff)
Make 'diff_populate_filespec()' use the new 'strbuf_readlink()'
This makes all tests pass on a system where 'lstat()' has been hacked to return bogus data in st_size for symlinks. Of course, the test coverage isn't complete, but it's a good baseline. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/diff.c b/diff.c
index afefe087bb..4b2029caa1 100644
--- a/diff.c
+++ b/diff.c
@@ -1773,19 +1773,17 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
s->size = xsize_t(st.st_size);
if (!s->size)
goto empty;
- if (size_only)
- return 0;
if (S_ISLNK(st.st_mode)) {
- int ret;
- s->data = xmalloc(s->size);
- s->should_free = 1;
- ret = readlink(s->path, s->data, s->size);
- if (ret < 0) {
- free(s->data);
+ struct strbuf sb = STRBUF_INIT;
+
+ if (strbuf_readlink(&sb, s->path, s->size))
goto err_empty;
- }
+ s->data = strbuf_detach(&sb, &s->size);
+ s->should_free = 1;
return 0;
}
+ if (size_only)
+ return 0;
fd = open(s->path, O_RDONLY);
if (fd < 0)
goto err_empty;