MCPcopy Create free account
hub / github.com/git/git / allocate_snapshot_buffer

Function allocate_snapshot_buffer

refs/packed-backend.c:525–549  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

523#define SMALL_FILE_SIZE (32*1024)
524
525static int allocate_snapshot_buffer(struct snapshot *snapshot, int fd, struct stat *st)
526{
527 ssize_t bytes_read;
528 size_t size;
529
530 size = xsize_t(st->st_size);
531 if (!size)
532 return 0;
533
534 if (mmap_strategy == MMAP_NONE || size <= SMALL_FILE_SIZE) {
535 snapshot->buf = xmalloc(size);
536 bytes_read = read_in_full(fd, snapshot->buf, size);
537 if (bytes_read < 0 || bytes_read != size)
538 die_errno("couldn't read %s", snapshot->refs->path);
539 snapshot->mmapped = 0;
540 } else {
541 snapshot->buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
542 snapshot->mmapped = 1;
543 }
544
545 snapshot->start = snapshot->buf;
546 snapshot->eof = snapshot->buf + size;
547
548 return 1;
549}
550
551/*
552 * Depending on `mmap_strategy`, either mmap or read the contents of

Callers 2

load_contentsFunction · 0.85
packed_fsckFunction · 0.85

Calls 5

xsize_tFunction · 0.85
read_in_fullFunction · 0.85
die_errnoFunction · 0.85
xmmapFunction · 0.85
xmallocFunction · 0.50

Tested by

no test coverage detected