aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-03-04 22:26:17 -0800
committerJunio C Hamano <gitster@pobox.com>2010-03-04 22:26:17 -0800
commit780fc9a0a6d13f667bb012621692107d244998a8 (patch)
tree7b7aed7be1531cbee13b914070694575fabee5f4
parent035aa7678b75bd6ec67f0b496603660fc685734f (diff)
parentea68b0ce9f8ce8da3e360aed3cbd6720159ffbee (diff)
downloadgit-780fc9a0a6d13f667bb012621692107d244998a8.tar.gz
git-780fc9a0a6d13f667bb012621692107d244998a8.tar.xz
Merge branch 'dp/read-not-mmap-small-loose-object' into maint
* dp/read-not-mmap-small-loose-object: hash-object: don't use mmap() for small files
-rw-r--r--sha1_file.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c
index c0214d794..006321e00 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2439,6 +2439,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)
{
@@ -2453,6 +2455,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);