summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--refs/packed-backend.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index c2efe91..e30c233 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -461,7 +461,8 @@ static void verify_buffer_safe(struct snapshot *snapshot)
/*
* Depending on `mmap_strategy`, either mmap or read the contents of
* the `packed-refs` file into the snapshot. Return 1 if the file
- * existed and was read, or 0 if the file was absent. Die on errors.
+ * existed and was read, or 0 if the file was absent or empty. Die on
+ * errors.
*/
static int load_contents(struct snapshot *snapshot)
{
@@ -492,19 +493,17 @@ static int load_contents(struct snapshot *snapshot)
die_errno("couldn't stat %s", snapshot->refs->path);
size = xsize_t(st.st_size);
- switch (mmap_strategy) {
- case MMAP_NONE:
+ if (!size) {
+ return 0;
+ } else if (mmap_strategy == MMAP_NONE) {
snapshot->buf = xmalloc(size);
bytes_read = read_in_full(fd, snapshot->buf, size);
if (bytes_read < 0 || bytes_read != size)
die_errno("couldn't read %s", snapshot->refs->path);
snapshot->mmapped = 0;
- break;
- case MMAP_TEMPORARY:
- case MMAP_OK:
+ } else {
snapshot->buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
snapshot->mmapped = 1;
- break;
}
close(fd);