Branch Coverage

deps/libgit2/src/libgit2/pack.c
Criterion Covered Total %
branch 181 490 36.9


line true false branch
57 0 2 if (!e)
70 2 0 if (e != NULL) {
80 8 0 if (cache->entries) {
81 2 8 git_offmap_foreach_value(cache->entries, entry, {
92 0 9 if (git_offmap_new(&cache->entries) < 0)
97 0 9 if (git_mutex_init(&cache->lock)) {
113 0 5 if (git_mutex_lock(&cache->lock) < 0)
116 0 5 if ((entry = git_offmap_get(cache->entries, offset)) != NULL) {
131 0 0 git_offmap_foreach(cache->entries, offset, entry, {
0 0 git_offmap_foreach(cache->entries, offset, entry, {
0 0 git_offmap_foreach(cache->entries, offset, entry, {
149 0 2 if (base->len > GIT_PACK_CACHE_SIZE_LIMIT)
153 2 0 if (entry) {
154 0 2 if (git_mutex_lock(&cache->lock) < 0) {
161 2 0 if (!exists) {
162 0 2 while (cache->memory_used + base->len > cache->memory_limit)
172 0 2 if (exists) {
189 0 8 if (p->oids) {
193 3 5 if (p->index_map.data) {
210 0 3 if (fd < 0)
213 0 3 if (p_fstat(fd, &st) < 0) {
220 0 3 !git__is_sizet(st.st_size) ||
232 0 3 if (error < 0)
237 3 0 if (hdr->idx_signature == htonl(PACK_IDX_SIGNATURE)) {
240 3 0 if (version < 2 || version > 2) {
0 3 if (version < 2 || version > 2) {
251 3 0 if (version > 1)
254 768 3 for (i = 0; i < 256; i++) {
256 0 768 if (n < nr) {
263 0 3 if (version == 1) {
271 0 0 if (idx_size != 4*256 + nr * 24 + 20 + 20) {
275 3 0 } else if (version == 2) {
292 3 0 if (nr)
295 3 0 if (idx_size < min_size || idx_size > max_size) {
0 3 if (idx_size < min_size || idx_size > max_size) {
313 3 3 if (p->index_version > -1)
318 0 3 GIT_ASSERT(name_len > strlen(".pack"));
320 0 3 if ((error = git_str_init(&idx_name, name_len)) < 0)
325 0 3 if (git_str_oom(&idx_name)) {
330 3 0 if (p->index_version == -1)
347 0 54 if (git_mutex_lock(&p->lock) < 0) {
351 0 54 if (git_mutex_lock(&p->mwf.lock) < 0) {
357 0 54 if (p->mwf.fd == -1 && packfile_open_locked(p) < 0)
0 0 if (p->mwf.fd == -1 && packfile_open_locked(p) < 0)
368 2 52 if (offset > (p->mwf.size - 20))
370 0 52 if (offset < 0)
394 53 0 GIT_ASSERT_ARG(type >= GIT_OBJECT_COMMIT && type <= GIT_OBJECT_REF_DELTA);
0 53 GIT_ASSERT_ARG(type >= GIT_OBJECT_COMMIT && type <= GIT_OBJECT_REF_DELTA);
402 45 53 while (size) {
429 43 52 while (c & 0x80) {
430 0 43 if (len <= used) {
435 0 43 if (bitsizeof(long) <= shift) {
463 0 52 if ((error = git_mutex_lock(&p->lock)) < 0)
465 0 52 if ((error = git_mutex_lock(&p->mwf.lock)) < 0) {
470 0 52 if (p->mwf.fd == -1 && (error = packfile_open_locked(p)) < 0) {
0 0 if (p->mwf.fd == -1 && (error = packfile_open_locked(p)) < 0) {
485 0 52 if (base == NULL)
490 0 52 if (error == GIT_EBUFS)
492 0 52 else if (error < 0)
513 0 2 if (error < 0) {
518 0 2 if (error < 0) {
524 0 2 if (p->mwf.fd == -1 && (error = packfile_open_locked(p)) < 0) {
0 0 if (p->mwf.fd == -1 && (error = packfile_open_locked(p)) < 0) {
533 0 2 if (error < 0)
536 2 0 if (type == GIT_OBJECT_OFS_DELTA || type == GIT_OBJECT_REF_DELTA) {
0 2 if (type == GIT_OBJECT_OFS_DELTA || type == GIT_OBJECT_REF_DELTA) {
543 0 0 if (error < 0)
546 0 0 if ((error = git_packfile_stream_open(&stream, p, curpos)) < 0)
550 0 0 if (error < 0)
557 0 2 while (type == GIT_OBJECT_OFS_DELTA || type == GIT_OBJECT_REF_DELTA) {
0 2 while (type == GIT_OBJECT_OFS_DELTA || type == GIT_OBJECT_REF_DELTA) {
560 0 0 if (error < 0)
562 0 0 if (type != GIT_OBJECT_OFS_DELTA && type != GIT_OBJECT_REF_DELTA)
0 0 if (type != GIT_OBJECT_OFS_DELTA && type != GIT_OBJECT_REF_DELTA)
568 0 0 if (error < 0)
602 0 5 if ((cached = cache_get(&p->bases, obj_offset)) != NULL) {
609 0 5 if (elem_pos == SMALL_STACK_SIZE) {
611 0 0 GIT_ERROR_CHECK_ARRAY(chain);
618 5 0 if (!use_heap) {
621 0 0 elem = git_array_alloc(chain);
0 0 elem = git_array_alloc(chain);
622 0 0 if (!elem) {
631 0 5 if (error < 0)
639 5 0 if (type != GIT_OBJECT_OFS_DELTA && type != GIT_OBJECT_REF_DELTA)
3 2 if (type != GIT_OBJECT_OFS_DELTA && type != GIT_OBJECT_REF_DELTA)
645 0 2 if (error < 0)
682 0 3 if (error < 0) {
687 0 3 if (error < 0) {
693 0 3 if (p->mwf.fd == -1)
697 0 3 if (error < 0)
705 0 3 if (error < 0)
713 0 3 stack = chain.ptr ? chain.ptr : small_stack;
716 0 3 if (cached) {
730 3 0 if (!cached) {
736 0 3 if (error < 0)
754 0 3 if (cached && stack_size == 1) {
0 0 if (cached && stack_size == 1) {
757 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, obj->len, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, obj->len, 1);
759 0 0 GIT_ERROR_CHECK_ALLOC(obj->data);
767 2 3 while (elem_pos > 0 && !error) {
2 0 while (elem_pos > 0 && !error) {
774 2 0 if (!cached)
782 0 2 if (error < 0) {
804 0 2 if (free_base) {
809 2 0 if (cached) {
814 0 2 if (error < 0)
821 0 3 if (error < 0) {
823 0 0 if (cached)
827 3 0 if (elem)
840 0 45 if (git_zstream_init(&obj->zstream, GIT_ZSTREAM_INFLATE) < 0) {
854 45 47 if (obj->done)
857 2 45 if ((in = pack_window_open(obj->p, &obj->mw, obj->curpos, &window_len)) == NULL)
860 45 0 if ((error = git_zstream_set_input(&obj->zstream, in, window_len)) < 0 ||
0 45 if ((error = git_zstream_set_input(&obj->zstream, in, window_len)) < 0 ||
871 45 0 if (git_zstream_eos(&obj->zstream))
875 0 45 if (!len && !git_zstream_eos(&obj->zstream))
0 0 if (!len && !git_zstream_eos(&obj->zstream))
900 0 5 GIT_ERROR_CHECK_ALLOC_ADD(&buffer_len, size, 1);
0 5 GIT_ERROR_CHECK_ALLOC_ADD(&buffer_len, size, 1);
902 0 5 GIT_ERROR_CHECK_ALLOC(data);
904 0 5 if ((error = git_zstream_init(&zstream, GIT_ZSTREAM_INFLATE)) < 0) {
914 0 5 if ((in = pack_window_open(p, mwindow, *position, &window_len)) == NULL) {
919 5 0 if ((error = git_zstream_set_input(&zstream, in, window_len)) < 0 ||
0 5 if ((error = git_zstream_set_input(&zstream, in, window_len)) < 0 ||
929 0 5 if (!bytes && !consumed) {
0 0 if (!bytes && !consumed) {
937 0 5 } while (!git_zstream_eos(&zstream));
939 5 0 if (total != size || !git_zstream_eos(&zstream)) {
0 5 if (total != size || !git_zstream_eos(&zstream)) {
951 0 5 if (error)
974 0 2 GIT_ASSERT_ARG(delta_base_out);
978 0 2 if (base_info == NULL)
986 0 2 if (type == GIT_OBJECT_OFS_DELTA) {
990 0 0 while (c & 128) {
991 0 0 if (left <= used)
994 0 0 if (!unsigned_base_offset || MSB(unsigned_base_offset, 7))
0 0 if (!unsigned_base_offset || MSB(unsigned_base_offset, 7))
999 0 0 if (unsigned_base_offset == 0 || (size_t)delta_obj_offset <= unsigned_base_offset)
0 0 if (unsigned_base_offset == 0 || (size_t)delta_obj_offset <= unsigned_base_offset)
1003 2 0 } else if (type == GIT_OBJECT_REF_DELTA) {
1008 2 0 if (p->has_cache) {
1011 2 0 if ((entry = git_oidmap_get(p->idx_cache, &base_oid)) != NULL) {
1012 0 2 if (entry->offset == 0)
1028 0 0 if (pack_entry_find_offset(&base_offset, &unused, p, &base_oid, GIT_OID_HEXSZ) < 0)
1034 0 0 if (base_offset == 0)
1051 0 8 if (!p)
1056 0 8 if (git_mutex_lock(&p->lock) < 0) {
1060 3 5 if (p->mwf.fd >= 0) {
1065 8 0 if (locked)
1068 0 8 if (unlink_packfile)
1089 0 3 if (pack_index_open_locked(p) < 0)
1092 0 3 if (p->mwf.fd >= 0)
1097 0 3 if (p->mwf.fd < 0)
1100 0 3 if (p_fstat(p->mwf.fd, &st) < 0) {
1106 0 3 if (!p->mwf.size) {
1107 0 0 if (!S_ISREG(st.st_mode))
1110 0 3 } else if (p->mwf.size != st.st_size)
1128 3 0 hdr.hdr_signature != htonl(PACK_SIGNATURE) ||
1139 0 3 if (git_oid_raw_cmp(sha1, idx_sha1) != 0)
1142 0 3 if (git_mwindow_file_register(&p->mwf) < 0)
1150 0 0 if (p->mwf.fd >= 0)
1164 0 4 if (path_len < strlen(".idx"))
1167 0 4 if (git_str_printf(&buf, "%.*s.pack", (int)(path_len - strlen(".idx")), path) < 0)
1178 9 0 size_t path_len = path ? strlen(path) : 0, alloc_len;
1182 0 9 if (path_len < strlen(".idx"))
1185 0 9 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*p), path_len);
0 9 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*p), path_len);
1186 0 9 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
0 9 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
1189 0 9 GIT_ERROR_CHECK_ALLOC(p);
1197 3 6 if (git__suffixcmp(path, ".idx") == 0) {
1200 3 0 if (!git_disable_pack_keep_file_checks) {
1202 0 3 if (git_fs_path_exists(p->pack_name) == true)
1209 9 0 if (p_stat(p->pack_name, &st) < 0 || !S_ISREG(st.st_mode)) {
0 9 if (p_stat(p->pack_name, &st) < 0 || !S_ISREG(st.st_mode)) {
1223 0 9 if (git_mutex_init(&p->lock) < 0) {
1229 0 9 if (git_mutex_init(&p->mwf.lock) < 0) {
1236 0 9 if (cache_init(&p->bases) < 0) {
1262 0 3 if (p->index_version == 1)
1267 3 0 if (!(off32 & 0x80000000))
1272 0 0 if (index >= end - 8)
1294 0 0 if (git_mutex_lock(&p->lock) < 0)
1297 0 0 if ((error = pack_index_open_locked(p)) < 0) {
1302 0 0 if (!p->index_map.data) {
1310 0 0 if (p->index_version > 1)
1315 0 0 if (p->oids == NULL) {
1318 0 0 if ((error = git_vector_init(&oids, p->num_objects, NULL))) {
1323 0 0 if ((error = git_vector_init(&offsets, p->num_objects, git__memcmp4))) {
1328 0 0 if (p->index_version > 1) {
1330 0 0 for (i = 0; i < p->num_objects; i++)
1333 0 0 git_vector_foreach(&offsets, i, current)
1336 0 0 for (i = 0; i < p->num_objects; i++)
1339 0 0 git_vector_foreach(&offsets, i, current)
1353 0 0 if (!oids.ptr) {
1356 0 0 GIT_ERROR_CHECK_ARRAY(oids);
1358 0 0 for (i = 0; i < p->num_objects; i++) {
1359 0 0 oid = git_array_alloc(oids);
0 0 oid = git_array_alloc(oids);
1360 0 0 if (!oid) {
1363 0 0 GIT_ERROR_CHECK_ALLOC(oid);
1370 0 0 git_array_foreach(oids, i, oid) {
0 0 git_array_foreach(oids, i, oid) {
1371 0 0 if ((error = cb(oid, data)) != 0) {
1392 0 0 if (git_mutex_lock(&p->lock) < 0)
1396 0 0 if (index == NULL) {
1397 0 0 if ((error = pack_index_open_locked(p)) < 0)
1400 0 0 if (!p->index_map.data) {
1408 0 0 if (p->index_version > 1)
1414 0 0 if (p->index_version > 1) {
1419 0 0 for (i = 0; i < p->num_objects; i++) {
1421 0 0 if (current_offset & 0x80000000) {
1423 0 0 if (large_offset_ptr >= large_offsets_end) {
1432 0 0 if ((error = cb(¤t_oid, current_offset, data)) != 0) {
1438 0 0 for (i = 0; i < p->num_objects; i++) {
1441 0 0 if ((error = cb(¤t_oid, current_offset, data)) != 0) {
1458 3 0 while (lo < hi) {
1462 3 0 if (!cmp)
1465 0 0 if (cmp > 0)
1491 0 3 if (git_mutex_lock(&p->lock) < 0)
1494 0 3 if ((error = pack_index_open_locked(p)) < 0)
1497 0 3 if (!p->index_map.data) {
1505 3 0 if (p->index_version > 1) {
1512 3 0 lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(level1_ofs[(int)short_oid->id[0] - 1]));
1514 3 0 if (p->index_version > 1) {
1528 3 0 if (pos >= 0) {
1536 0 0 if (pos < (int)p->num_objects) {
1539 0 0 if (!git_oid_raw_ncmp(short_oid->id, current, len))
1544 3 0 if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)p->num_objects) {
0 3 if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)p->num_objects) {
0 0 if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)p->num_objects) {
1548 0 0 if (!git_oid_raw_ncmp(short_oid->id, next, len)) {
1553 0 3 if (!found) {
1557 0 3 if (found > 1) {
1562 0 3 if ((offset = nth_packed_object_offset_locked(p, pos)) < 0) {
1595 0 3 GIT_ASSERT_ARG(p);
1597 3 0 if (len == GIT_OID_HEXSZ && p->num_bad_objects) {
0 3 if (len == GIT_OID_HEXSZ && p->num_bad_objects) {
1599 0 0 for (i = 0; i < p->num_bad_objects; i++)
1600 0 0 if (git_oid__cmp(short_oid, &p->bad_object_sha1[i]) == 0)
1605 0 3 if (error < 0)
1609 0 3 if (error < 0) {
1614 0 3 if (error < 0) {
1623 3 0 if (p->mwf.fd == -1)
1627 0 3 if (error < 0)