MCPcopy Index your code
hub / github.com/git/git / read_loose_object

Function read_loose_object

object-file.c:1606–1671  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1604}
1605
1606int read_loose_object(struct repository *repo,
1607 const char *path,
1608 const struct object_id *expected_oid,
1609 struct object_id *real_oid,
1610 void **contents,
1611 struct object_info *oi)
1612{
1613 int ret = -1;
1614 int fd;
1615 void *map = NULL;
1616 unsigned long mapsize;
1617 git_zstream stream;
1618 char hdr[MAX_HEADER_LEN];
1619 size_t *size = oi->sizep;
1620
1621 fd = git_open(path);
1622 if (fd >= 0)
1623 map = map_fd(fd, path, &mapsize);
1624 if (!map) {
1625 error_errno(_("unable to mmap %s"), path);
1626 goto out;
1627 }
1628
1629 if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr)) != ULHR_OK) {
1630 error(_("unable to unpack header of %s"), path);
1631 goto out_inflate;
1632 }
1633
1634 if (parse_loose_header(hdr, oi) < 0) {
1635 error(_("unable to parse header of %s"), path);
1636 goto out_inflate;
1637 }
1638
1639 if (*oi->typep < 0) {
1640 error(_("unable to parse type from header '%s' of %s"),
1641 hdr, path);
1642 goto out_inflate;
1643 }
1644
1645 if (*oi->typep == OBJ_BLOB &&
1646 *size > repo_settings_get_big_file_threshold(repo)) {
1647 if (check_stream_oid(&stream, hdr, *size, path, expected_oid,
1648 repo->hash_algo) < 0)
1649 goto out_inflate;
1650 } else {
1651 *contents = unpack_loose_rest(&stream, hdr, *size, expected_oid);
1652 if (!*contents) {
1653 error(_("unable to unpack contents of %s"), path);
1654 goto out_inflate;
1655 }
1656 hash_object_file(repo->hash_algo,
1657 *contents, *size,
1658 *oi->typep, real_oid);
1659 if (!oideq(expected_oid, real_oid))
1660 goto out_inflate;
1661 }
1662
1663 ret = 0; /* everything checks out */

Callers 1

fsck_looseFunction · 0.85

Calls 11

map_fdFunction · 0.85
error_errnoFunction · 0.85
unpack_loose_headerFunction · 0.85
errorFunction · 0.85
parse_loose_headerFunction · 0.85
check_stream_oidFunction · 0.85
unpack_loose_restFunction · 0.85
hash_object_fileFunction · 0.85
oideqFunction · 0.85
git_inflate_endFunction · 0.85

Tested by

no test coverage detected