* 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 or empty. Die on * errors. */
| 555 | * errors. |
| 556 | */ |
| 557 | static int load_contents(struct snapshot *snapshot) |
| 558 | { |
| 559 | struct stat st; |
| 560 | int ret; |
| 561 | int fd; |
| 562 | |
| 563 | fd = open(snapshot->refs->path, O_RDONLY); |
| 564 | if (fd < 0) { |
| 565 | if (errno == ENOENT) { |
| 566 | /* |
| 567 | * This is OK; it just means that no |
| 568 | * "packed-refs" file has been written yet, |
| 569 | * which is equivalent to it being empty, |
| 570 | * which is its state when initialized with |
| 571 | * zeros. |
| 572 | */ |
| 573 | return 0; |
| 574 | } else { |
| 575 | die_errno("couldn't read %s", snapshot->refs->path); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | stat_validity_update(&snapshot->validity, fd); |
| 580 | |
| 581 | if (fstat(fd, &st) < 0) |
| 582 | die_errno("couldn't stat %s", snapshot->refs->path); |
| 583 | |
| 584 | ret = allocate_snapshot_buffer(snapshot, fd, &st); |
| 585 | |
| 586 | close(fd); |
| 587 | return ret; |
| 588 | } |
| 589 | |
| 590 | static const char *find_reference_location_1(struct snapshot *snapshot, |
| 591 | const char *refname, int mustexist, |
no test coverage detected