diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-03-02 12:44:08 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-03-02 12:44:08 -0800 |
commit | 7237f971819e4a65a77e4a551466937d7bfdc9e8 (patch) | |
tree | 32d69431d2adc7875574c62681a719e5f26e269f | |
parent | Merge branch 'jn/makedepend' (diff) | |
parent | hash-object: don't use mmap() for small files (diff) | |
download | tgif-7237f971819e4a65a77e4a551466937d7bfdc9e8.tar.xz |
Merge branch 'dp/read-not-mmap-small-loose-object'
* dp/read-not-mmap-small-loose-object:
hash-object: don't use mmap() for small files
-rw-r--r-- | sha1_file.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c index 657825e14e..0375159604 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2434,6 +2434,8 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size, return ret; } +#define SMALL_FILE_SIZE (32*1024) + int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path) { @@ -2448,6 +2450,14 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, else ret = -1; strbuf_release(&sbuf); + } else if (size <= SMALL_FILE_SIZE) { + char *buf = xmalloc(size); + if (size == read_in_full(fd, buf, size)) + ret = index_mem(sha1, buf, size, write_object, type, + path); + else + ret = error("short read %s", strerror(errno)); + free(buf); } else if (size) { void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); ret = index_mem(sha1, buf, size, write_object, type, path); |