git-2.22.0/refs/packed-backend.c
/*
 * 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.
 */
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.
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 .
static int load_contents(struct snapshot *snapshot)
{
	int fd;
	struct stat st;
	size_t size;
	ssize_t bytes_read;
	fd = open(snapshot->refs->path, O_RDONLY);
	if (fd < 0) {
		if (errno == ENOENT) {
			return 0;
		} else {
			die_errno("couldn't read %s", snapshot->refs->path);
		}
	}
	stat_validity_update(&snapshot->validity, fd);
	if (fstat(fd, &st) < 0)
		die_errno("couldn't stat %s", snapshot->refs->path);
	size = xsize_t(st.st_size);
	if (!size) {
		close(fd);
		return 0;
	} 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)
			die_errno("couldn't read %s", snapshot->refs->path);
		snapshot->mmapped = 0;
	} else {
		snapshot->buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
		snapshot->mmapped = 1;
	}
	close(fd);
	snapshot->start = snapshot->buf;
	snapshot->eof = snapshot->buf + size;
	return 1;
}
static int load_contents ( struct snapshot * snapshot ) { int fd ; struct stat st ; size_t size ; ssize_t bytes_read ; fd = open ( snapshot -> refs -> path , O_RDONLY ) ; if ( fd < 0 ) { if ( errno == ENOENT ) { return 0 ; } else { die_errno ( " " , snapshot -> refs -> path ) ; } } stat_validity_update ( & snapshot -> validity , fd ) ; if ( fstat ( fd , & st ) < 0 ) die_errno ( " " , snapshot -> refs -> path ) ; size = xsize_t ( st . st_size ) ; if ( ! size ) { close ( fd ) ; return 0 ; } 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 ) die_errno ( " " , snapshot -> refs -> path ) ; snapshot -> mmapped = 0 ; } else { snapshot -> buf = xmmap ( NULL , size , PROT_READ , MAP_PRIVATE , fd , 0 ) ; snapshot -> mmapped = 1 ; } close ( fd ) ; snapshot -> start = snapshot -> buf ; snapshot -> eof = snapshot -> buf + size ; return 1 ; }
Depending on `mmap_strategy`, either mmap or read the contents of
 the `packed-refs` file into the snapshot.
Depending on ` mmap_strategy ` either mmap or read the contents of the ` packed - refs ` file into the snapshot .
/*
			 * This is OK; it just means that no
			 * "packed-refs" file has been written yet,
			 * which is equivalent to it being empty,
			 * which is its state when initialized with
			 * zeros.
			 */