Branch Coverage

deps/libgit2/src/pack.c
Criterion Covered Total %
branch 165 418 39.4


line true false branch
56 0 2 if (!e)
69 2 0 if (e != NULL) {
70 0 2 assert(e->refcount.val == 0);
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) {
209 0 3 if (fd < 0)
212 0 3 if (p_fstat(fd, &st) < 0) {
219 0 3 !git__is_sizet(st.st_size) ||
231 0 3 if (error < 0)
236 3 0 if (hdr->idx_signature == htonl(PACK_IDX_SIGNATURE)) {
239 3 0 if (version < 2 || version > 2) {
0 3 if (version < 2 || version > 2) {
250 3 0 if (version > 1)
253 768 3 for (i = 0; i < 256; i++) {
255 0 768 if (n < nr) {
262 0 3 if (version == 1) {
270 0 0 if (idx_size != 4*256 + nr * 24 + 20 + 20) {
274 3 0 } else if (version == 2) {
291 3 0 if (nr)
294 3 0 if (idx_size < min_size || idx_size > max_size) {
0 3 if (idx_size < min_size || idx_size > max_size) {
311 0 3 if (p->index_version > -1)
315 0 3 assert(name_len > strlen(".pack")); /* checked by git_pack_file alloc */
317 0 3 if (git_buf_init(&idx_name, name_len) < 0)
322 0 3 if (git_buf_oom(&idx_name)) {
327 0 3 if ((error = git_mutex_lock(&p->lock)) < 0) {
332 3 0 if (p->index_version == -1)
348 0 54 if (p->mwf.fd == -1 && packfile_open(p) < 0)
0 0 if (p->mwf.fd == -1 && packfile_open(p) < 0)
359 2 52 if (offset > (p->mwf.size - 20))
361 0 52 if (offset < 0)
380 53 0 assert(type >= GIT_OBJECT_COMMIT && type <= GIT_OBJECT_REF_DELTA);
0 53 assert(type >= GIT_OBJECT_COMMIT && type <= GIT_OBJECT_REF_DELTA);
388 45 53 while (size) {
414 43 52 while (c & 0x80) {
415 0 43 if (len <= used) {
420 0 43 if (bitsizeof(long) <= shift) {
456 0 52 if (base == NULL)
461 0 52 if (ret == GIT_EBUFS)
463 0 52 else if (ret < 0)
484 0 2 if (error < 0)
487 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) {
494 0 0 if (error < 0)
497 0 0 if ((error = git_packfile_stream_open(&stream, p, curpos)) < 0)
501 0 0 if (error < 0)
508 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) {
511 0 0 if (error < 0)
513 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)
519 0 0 if (error < 0)
553 0 5 if ((cached = cache_get(&p->bases, obj_offset)) != NULL) {
560 0 5 if (elem_pos == SMALL_STACK_SIZE) {
562 0 0 GIT_ERROR_CHECK_ARRAY(chain);
569 5 0 if (!use_heap) {
572 0 0 elem = git_array_alloc(chain);
0 0 elem = git_array_alloc(chain);
573 0 0 if (!elem) {
583 0 5 if (error < 0)
591 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)
597 0 2 if (error < 0)
638 0 3 if (error < 0)
646 0 3 stack = chain.ptr ? chain.ptr : small_stack;
649 0 3 if (cached) {
663 3 0 if (!cached) {
669 0 3 if (error < 0)
687 0 3 if (cached && stack_size == 1) {
0 0 if (cached && stack_size == 1) {
690 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, obj->len, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, obj->len, 1);
692 0 0 GIT_ERROR_CHECK_ALLOC(obj->data);
700 2 3 while (elem_pos > 0 && !error) {
2 0 while (elem_pos > 0 && !error) {
707 2 0 if (!cached)
715 0 2 if (error < 0) {
737 0 2 if (free_base) {
742 2 0 if (cached) {
747 0 2 if (error < 0)
754 0 3 if (error < 0) {
756 0 0 if (cached)
760 3 0 if (elem)
773 0 45 if (git_zstream_init(&obj->zstream, GIT_ZSTREAM_INFLATE) < 0) {
787 45 47 if (obj->done)
790 2 45 if ((in = pack_window_open(obj->p, &obj->mw, obj->curpos, &window_len)) == NULL)
793 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 ||
804 45 0 if (git_zstream_eos(&obj->zstream))
808 0 45 if (!len && !git_zstream_eos(&obj->zstream))
0 0 if (!len && !git_zstream_eos(&obj->zstream))
833 0 5 GIT_ERROR_CHECK_ALLOC_ADD(&buffer_len, size, 1);
0 5 GIT_ERROR_CHECK_ALLOC_ADD(&buffer_len, size, 1);
835 0 5 GIT_ERROR_CHECK_ALLOC(data);
837 0 5 if ((error = git_zstream_init(&zstream, GIT_ZSTREAM_INFLATE)) < 0) {
847 0 5 if ((in = pack_window_open(p, mwindow, *position, &window_len)) == NULL) {
852 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 ||
860 0 5 if (!bytes)
865 0 5 } while (!git_zstream_eos(&zstream));
867 5 0 if (total != size || !git_zstream_eos(&zstream)) {
0 5 if (total != size || !git_zstream_eos(&zstream)) {
879 0 5 if (error)
902 0 2 assert(delta_base_out);
906 0 2 if (base_info == NULL)
914 0 2 if (type == GIT_OBJECT_OFS_DELTA) {
918 0 0 while (c & 128) {
919 0 0 if (left <= used)
922 0 0 if (!unsigned_base_offset || MSB(unsigned_base_offset, 7))
0 0 if (!unsigned_base_offset || MSB(unsigned_base_offset, 7))
927 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)
931 2 0 } else if (type == GIT_OBJECT_REF_DELTA) {
933 2 0 if (p->has_cache) {
938 2 0 if ((entry = git_oidmap_get(p->idx_cache, &oid)) != NULL) {
939 0 2 if (entry->offset == 0)
955 0 0 if (pack_entry_find_offset(&base_offset, &unused, p, (git_oid *)base_info, GIT_OID_HEXSZ) < 0)
961 0 0 if (base_offset == 0)
976 3 5 if (p->mwf.fd >= 0) {
982 0 8 if (unlink_packfile)
988 0 8 if (!p)
1011 0 3 if (p->index_version == -1 && pack_index_open(p) < 0)
0 0 if (p->index_version == -1 && pack_index_open(p) < 0)
1015 0 3 if (git_mutex_lock(&p->lock) < 0)
1018 0 3 if (p->mwf.fd >= 0) {
1025 0 3 if (p->mwf.fd < 0)
1033 0 3 if (!p->mwf.size) {
1034 0 0 if (!S_ISREG(st.st_mode))
1037 0 3 } else if (p->mwf.size != st.st_size)
1055 0 3 hdr.hdr_signature != htonl(PACK_SIGNATURE) ||
1056 0 0 !pack_version_ok(hdr.hdr_version))
1061 3 0 p_lseek(p->mwf.fd, p->mwf.size - GIT_OID_RAWSZ, SEEK_SET) == -1 ||
1067 0 3 if (git_oid__cmp(&sha1, (git_oid *)idx_sha1) != 0)
1076 0 0 if (p->mwf.fd >= 0)
1092 0 4 if (path_len < strlen(".idx"))
1095 0 4 if (git_buf_printf(&buf, "%.*s.pack", (int)(path_len - strlen(".idx")), path) < 0)
1106 9 0 size_t path_len = path ? strlen(path) : 0, alloc_len;
1110 0 9 if (path_len < strlen(".idx"))
1113 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);
1114 0 9 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
0 9 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
1117 0 9 GIT_ERROR_CHECK_ALLOC(p);
1125 3 6 if (git__suffixcmp(path, ".idx") == 0) {
1128 3 0 if (!git_disable_pack_keep_file_checks) {
1130 0 3 if (git_path_exists(p->pack_name) == true)
1137 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)) {
1151 0 9 if (git_mutex_init(&p->lock)) {
1157 0 9 if (cache_init(&p->bases) < 0) {
1178 0 3 if (p->index_version == 1) {
1184 3 0 if (!(off & 0x80000000))
1189 0 0 if (index >= end - 8)
1210 0 0 if (index == NULL) {
1211 0 0 if ((error = pack_index_open(p)) < 0)
1214 0 0 assert(p->index_map.data);
1219 0 0 if (p->index_version > 1) {
1225 0 0 if (p->oids == NULL) {
1228 0 0 if ((error = git_vector_init(&oids, p->num_objects, NULL)))
1231 0 0 if ((error = git_vector_init(&offsets, p->num_objects, git__memcmp4)))
1234 0 0 if (p->index_version > 1) {
1236 0 0 for (i = 0; i < p->num_objects; i++)
1239 0 0 git_vector_foreach(&offsets, i, current)
1242 0 0 for (i = 0; i < p->num_objects; i++)
1245 0 0 git_vector_foreach(&offsets, i, current)
1253 0 0 for (i = 0; i < p->num_objects; i++)
1254 0 0 if ((error = cb(p->oids[i], data)) != 0)
1265 3 0 while (lo < hi) {
1269 3 0 if (!cmp)
1272 0 0 if (cmp > 0)
1297 3 0 if (p->index_version == -1) {
1300 0 3 if ((error = pack_index_open(p)) < 0)
1302 0 3 assert(p->index_map.data);
1308 3 0 if (p->index_version > 1) {
1315 3 0 lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(level1_ofs[(int)short_oid->id[0] - 1]));
1317 3 0 if (p->index_version > 1) {
1331 3 0 if (pos >= 0) {
1339 0 0 if (pos < (int)p->num_objects) {
1342 0 0 if (!git_oid_ncmp(short_oid, (const git_oid *)current, len))
1347 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) {
1351 0 0 if (!git_oid_ncmp(short_oid, (const git_oid *)next, len)) {
1356 0 3 if (!found)
1358 0 3 if (found > 1)
1361 0 3 if ((offset = nth_packed_object_offset(p, pos)) < 0) {
1391 0 3 assert(p);
1393 3 0 if (len == GIT_OID_HEXSZ && p->num_bad_objects) {
0 3 if (len == GIT_OID_HEXSZ && p->num_bad_objects) {
1395 0 0 for (i = 0; i < p->num_bad_objects; i++)
1396 0 0 if (git_oid__cmp(short_oid, &p->bad_object_sha1[i]) == 0)
1401 0 3 if (error < 0)
1407 3 0 if (p->mwf.fd == -1 && (error = packfile_open(p)) < 0)
0 3 if (p->mwf.fd == -1 && (error = packfile_open(p)) < 0)