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>

Kim Gybels committed Jan 24, 2018 at 12:14 UTC ba41a8b600871b68680ff33de08012f4887133a2
1 file changed +3 -1
refs/packed-backend.c
+3 -1
@@ -458,6 +458,8 @@ static void verify_buffer_safe(struct snapshot *snapshot)
458 last_line, eof - last_line);
459 }
460
461 +#define SMALL_FILE_SIZE (32*1024)
462 +
463 /*
464 * Depending on `mmap_strategy`, either mmap or read the contents of
465 * the `packed-refs` file into the snapshot. Return 1 if the file
@@ -495,7 +497,7 @@ static int load_contents(struct snapshot *snapshot)
497
498 if (!size) {
499 return 0;
498 - } else if (mmap_strategy == MMAP_NONE) {
500 + } else if (mmap_strategy == MMAP_NONE || size <= SMALL_FILE_SIZE) {
501 snapshot->buf = xmalloc(size);
502 bytes_read = read_in_full(fd, snapshot->buf, size);
503 if (bytes_read < 0 || bytes_read != size)