summaryrefslogtreecommitdiff
path: root/refs
diff options
context:
space:
mode:
authorKim Gybels <kgybels@infogroep.be>2018-01-24 11:14:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-01-24 20:55:26 (GMT)
commitba41a8b600871b68680ff33de08012f4887133a2 (patch)
tree2bebc8c302e63b07e8caae82cfc0dbf361e1f5da /refs
parent01caf20d57aea73e67337ba1d396dd80a76d9dc3 (diff)
downloadgit-ba41a8b600871b68680ff33de08012f4887133a2.zip
git-ba41a8b600871b68680ff33de08012f4887133a2.tar.gz
git-ba41a8b600871b68680ff33de08012f4887133a2.tar.bz2
packed_ref_cache: don't use mmap() for small files
Take a hint from commit ea68b0ce9f8 (hash-object: don't use mmap() for small files, 2010-02-21) and use read() instead of mmap() for small packed-refs files. Signed-off-by: Kim Gybels <kgybels@infogroep.be> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs')
-rw-r--r--refs/packed-backend.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index e30c233..ea7ad55 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -458,6 +458,8 @@ static void verify_buffer_safe(struct snapshot *snapshot)
last_line, eof - last_line);
}
+#define SMALL_FILE_SIZE (32*1024)
+
/*
* Depending on `mmap_strategy`, either mmap or read the contents of
* the `packed-refs` file into the snapshot. Return 1 if the file
@@ -495,7 +497,7 @@ static int load_contents(struct snapshot *snapshot)
if (!size) {
return 0;
- } else if (mmap_strategy == MMAP_NONE) {
+ } else if (mmap_strategy == MMAP_NONE || size <= SMALL_FILE_SIZE) {
snapshot->buf = xmalloc(size);
bytes_read = read_in_full(fd, snapshot->buf, size);
if (bytes_read < 0 || bytes_read != size)