Branch Coverage

deps/libgit2/src/indexer.c
Criterion Covered Total %
branch 168 380 44.2


line true false branch
91 0 5 if ((error = p_mmap(&map, sizeof(*hdr), GIT_PROT_READ, GIT_MAP_SHARED, pack->mwf.fd, 0)) < 0)
98 0 5 if (hdr->hdr_signature != ntohl(PACK_SIGNATURE)) {
103 0 5 if (!pack_version_ok(hdr->hdr_version)) {
0 0 if (!pack_version_ok(hdr->hdr_version)) {
121 0 0 GIT_INIT_STRUCTURE_FROM_TEMPLATE(
146 4 1 if (in_opts)
150 0 5 GIT_ERROR_CHECK_ALLOC(idx);
154 0 5 idx->mode = mode ? mode : GIT_PACK_FILE_MODE;
157 5 0 if ((error = git_hash_ctx_init(&idx->hash_ctx)) < 0 ||
5 0 if ((error = git_hash_ctx_init(&idx->hash_ctx)) < 0 ||
158 5 0 (error = git_hash_ctx_init(&idx->trailer)) < 0 ||
164 0 5 if (git_repository__fsync_gitdir)
168 0 5 if (error < 0)
173 0 5 if (fd < 0)
179 0 5 if (error < 0)
183 0 5 if ((error = git_mwindow_file_register(&idx->pack->mwf)) < 0)
190 0 0 if (fd != -1)
193 0 0 if (git_buf_len(&tmp_path) > 0)
196 0 0 if (idx->pack != NULL)
216 0 2 GIT_ERROR_CHECK_ALLOC(delta);
219 0 2 if (git_vector_insert(&idx->deltas, delta) < 0)
231 0 43 if ((error = git_odb__format_object_header(&hdrlen,
242 43 0 assert(idx && stream);
0 43 assert(idx && stream);
245 0 86 if ((read = git_packfile_stream_read(stream, idx->objbuf, sizeof(idx->objbuf))) < 0)
248 0 86 if (idx->do_verify)
252 43 43 } while (read > 0);
254 0 43 if (read < 0)
265 0 2 assert(type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA);
0 0 assert(type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA);
267 2 0 if (type == GIT_OBJECT_REF_DELTA) {
273 0 0 if (error < 0)
285 0 4 assert(stream);
289 2 4 } while (read > 0);
291 2 2 if (read < 0)
305 45 45 while (size) {
307 0 45 if (ptr == NULL)
328 0 0 if ((!idx->odb || !git_odb_exists(idx->odb, oid)) &&
329 0 0 !git_oidmap_exists(idx->pack->idx_cache, oid) &&
332 0 0 GIT_ERROR_CHECK_ALLOC(dup);
346 0 0 if (obj->type != GIT_OBJECT_BLOB &&
0 0 if (obj->type != GIT_OBJECT_BLOB &&
347 0 0 obj->type != GIT_OBJECT_TREE &&
348 0 0 obj->type != GIT_OBJECT_COMMIT &&
352 0 0 if ((error = git_object__from_raw(&object, obj->data, obj->len, obj->type)) < 0)
355 0 0 if ((expected = git_oidmap_get(idx->expected_oids, &object->cached.oid)) != NULL) {
364 0 0 if (idx->odb && git_odb_exists(idx->odb, &object->cached.oid))
0 0 if (idx->odb && git_odb_exists(idx->odb, &object->cached.oid))
374 0 0 git_array_foreach(tree->entries, i, entry)
0 0 git_array_foreach(tree->entries, i, entry)
375 0 0 if (add_expected_oid(idx, entry->oid) < 0)
386 0 0 git_array_foreach(commit->parent_ids, i, parent_oid)
0 0 git_array_foreach(commit->parent_ids, i, parent_oid)
387 0 0 if (add_expected_oid(idx, parent_oid) < 0)
390 0 0 if (add_expected_oid(idx, &commit->tree_id) < 0)
399 0 0 if (add_expected_oid(idx, &tag->target) < 0)
425 0 43 GIT_ERROR_CHECK_ALLOC(entry);
428 0 43 GIT_ERROR_CHECK_ALLOC(pentry);
430 0 43 if (git_hash_final(&oid, &idx->hash_ctx)) {
435 0 43 if (entry_start > UINT31_MAX) {
442 0 43 if (idx->do_verify) {
449 0 0 if ((error = check_object_connectivity(idx, &rawobj)) < 0)
456 0 43 if (git_oidmap_exists(idx->pack->idx_cache, &pentry->sha1)) {
462 0 43 if ((error = git_oidmap_set(idx->pack->idx_cache, &pentry->sha1, pentry)) < 0) {
470 0 43 if (crc_object(&entry->crc, &idx->pack->mwf, entry_start, entry_size) < 0)
474 0 43 if (git_vector_insert(&idx->objects, entry) < 0)
477 4868 43 for (i = oid.id[0]; i < 256; ++i) {
498 0 2 if (entry_start > UINT31_MAX) {
514 0 2 if (git_vector_insert(&idx->objects, entry) < 0)
517 134 2 for (i = entry->oid.id[0]; i < 256; ++i) {
532 0 2 GIT_ERROR_CHECK_ALLOC(entry);
534 0 2 if (git_odb__hashobj(&oid, obj) < 0) {
540 0 2 GIT_ERROR_CHECK_ALLOC(pentry);
547 0 2 if (crc_object(&entry->crc, &idx->pack->mwf, entry_start, entry_size) < 0)
561 41 11 if (idx->progress_cb)
573 0 91 if (size == 0)
577 45 46 if (size >= GIT_OID_RAWSZ) {
588 8 38 if (idx->inbuf_len + size <= GIT_OID_RAWSZ) {
615 91 0 assert(data && size);
0 91 assert(data && size);
617 0 91 if ((error = git__mmap_alignment(&mmap_alignment)) < 0)
624 0 91 if ((error = p_mmap(&map, page_offset + size, GIT_PROT_WRITE, GIT_MAP_SHARED, fd, page_start)) < 0)
644 0 91 if (!size)
647 0 91 if ((error = git__mmap_alignment(&mmap_alignment)) < 0)
676 84 47 if (idx->pack->mwf.size <= idx->off + 20)
679 45 2 if (!idx->have_stream) {
681 0 45 if (error == GIT_EBUFS) {
685 0 45 if (error < 0)
693 43 2 if (type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA) {
0 43 if (type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA) {
695 0 2 if (error == GIT_EBUFS) {
699 0 2 if (error < 0)
707 0 43 if (error < 0)
715 0 45 if (error < 0)
719 4 43 if (idx->have_delta) {
726 2 45 if (error == GIT_EBUFS)
733 0 45 if (error < 0)
736 2 43 if (idx->have_delta) {
742 0 45 if (error < 0)
745 43 2 if (!idx->have_delta) {
750 0 45 if ((error = do_progress_callback(idx, stats)) != 0)
762 91 0 assert(idx && data && stats);
91 0 assert(idx && data && stats);
0 91 assert(idx && data && stats);
764 0 91 if ((error = append_to_pack(idx, data, size)) < 0)
772 5 86 if (!idx->parsed_header) {
775 0 5 if ((unsigned)idx->pack->mwf.size < sizeof(struct git_pack_header))
778 0 5 if ((error = parse_header(&idx->hdr, idx->pack)) < 0)
785 5 0 if (idx->nr_objects <= git_indexer__max_objects) {
792 0 5 if (git_oidmap_new(&idx->pack->idx_cache) < 0)
796 0 5 if (git_vector_init(&idx->objects, total_objects, objects_cmp) < 0)
799 0 5 if (git_vector_init(&idx->deltas, total_objects / 2, NULL) < 0)
809 0 5 if ((error = do_progress_callback(idx, stats)) != 0)
818 131 5 while (stats->indexed_objects < idx->nr_objects) {
819 86 45 if ((error = read_stream_object(idx, stats)) != 0) {
820 86 0 if (error == GIT_EBUFS)
840 330 0 while (slash > 0 && path->ptr[slash - 1] != '/')
320 10 while (slash > 0 && path->ptr[slash - 1] != '/')
843 0 10 if (git_buf_grow(path, slash + 1 + strlen(prefix) +
853 0 10 return git_buf_oom(path) ? -1 : 0;
882 0 0 if (git_odb_read(&obj, idx->odb, id) < 0) {
891 0 0 GIT_ERROR_CHECK_ALLOC(entry);
897 0 0 if ((error = append_to_pack(idx, hdr, hdr_len)) < 0)
903 0 0 if ((error = git_zstream_deflatebuf(&buf, data, len)) < 0)
907 0 0 if ((error = append_to_pack(idx, buf.ptr, buf.size)) < 0)
916 0 0 if ((error = append_to_pack(idx, &foo, GIT_OID_RAWSZ)) < 0)
922 0 0 GIT_ERROR_CHECK_ALLOC(pentry);
931 0 0 if (error) {
953 0 0 assert(git_vector_length(&idx->deltas) > 0);
955 0 0 if (idx->odb == NULL) {
961 0 0 git_vector_foreach(&idx->deltas, i, delta) {
962 0 0 if (!delta)
967 0 0 if (error < 0)
970 0 0 if (type == GIT_OBJECT_REF_DELTA) {
976 0 0 if (!found_ref_delta) {
983 0 0 if (base_info == NULL) {
991 0 0 if (has_entry(idx, &base))
994 0 0 if (inject_object(idx, &base) < 0)
1009 4 3 while (idx->deltas.length > 0) {
1012 4 4 git_vector_foreach(&idx->deltas, i, delta) {
1015 2 2 if (!delta)
1020 0 2 if ((error = git_packfile_unpack(&obj, idx->pack, &idx->off)) < 0) {
1021 0 0 if (error == GIT_PASSTHROUGH) {
1028 0 2 if (idx->do_verify && check_object_connectivity(idx, &obj) < 0)
0 0 if (idx->do_verify && check_object_connectivity(idx, &obj) < 0)
1032 0 2 if (hash_and_save(idx, &obj, delta->delta_off) < 0)
1039 0 2 if ((progress_cb_result = do_progress_callback(idx, stats)) < 0)
1048 2 2 if (!non_null)
1051 0 2 if (!progressed && (fix_thin_pack(idx, stats) < 0)) {
0 0 if (!progressed && (fix_thin_pack(idx, stats) < 0)) {
1075 0 0 if (write_at(idx, &idx->hdr, 0, sizeof(struct git_pack_header)) < 0)
1086 0 0 while (hashed < mwf->size) {
1088 0 0 if (ptr == NULL)
1112 0 5 if (!idx->parsed_header) {
1118 0 5 if (idx->off + 20 < idx->pack->mwf.size) {
1122 0 5 if (idx->off + 20 > idx->pack->mwf.size) {
1128 0 5 if (packfile_trailer == NULL) {
1138 0 5 if (git_oid_cmp(&file_hash, &trailer_hash)) {
1146 0 5 if ((error = resolve_deltas(idx, stats)) < 0)
1149 0 5 if (stats->indexed_objects != stats->total_objects) {
1154 0 5 if (stats->local_objects > 0) {
1155 0 0 if (update_header_and_rehash(idx, stats) < 0)
1168 0 5 if (git_oidmap_size(idx->expected_oids) > 0) {
1183 0 5 if (git_buf_oom(&filename))
1186 0 5 if (git_filebuf_open(&index_file, filename.ptr,
0 5 if (git_filebuf_open(&index_file, filename.ptr,
1198 1280 5 for (i = 0; i < 256; ++i) {
1204 45 5 git_vector_foreach(&idx->objects, i, entry) {
1209 45 5 git_vector_foreach(&idx->objects, i, entry) {
1214 45 5 git_vector_foreach(&idx->objects, i, entry) {
1217 0 45 if (entry->offset == UINT32_MAX)
1226 45 5 git_vector_foreach(&idx->objects, i, entry) {
1229 45 0 if (entry->offset != UINT32_MAX)
1239 0 5 if (git_filebuf_write(&index_file, &trailer_hash, GIT_OID_RAWSZ) < 0)
1243 0 5 if (git_filebuf_hash(&trailer_hash, &index_file) < 0)
1249 0 5 if (index_path(&filename, idx, ".idx") < 0)
1253 0 5 if (git_filebuf_commit_at(&index_file, filename.ptr) < 0)
1259 0 5 if (p_ftruncate(idx->pack->mwf.fd, idx->pack->mwf.size) < 0) {
1264 0 5 if (idx->do_fsync && p_fsync(idx->pack->mwf.fd) < 0) {
0 0 if (idx->do_fsync && p_fsync(idx->pack->mwf.fd) < 0) {
1270 0 5 if (p_close(idx->pack->mwf.fd) < 0) {
1277 0 5 if (index_path(&filename, idx, ".pack") < 0)
1281 0 5 if (p_rename(idx->pack->pack_name, git_buf_cstr(&filename)) < 0)
1307 0 5 if (idx == NULL)
1310 0 5 if (idx->have_stream)
1315 5 0 if (idx->pack->idx_cache) {
1317 45 5 git_oidmap_foreach_value(idx->pack->idx_cache, pentry, {
1326 5 0 if (!git_mutex_lock(&git__mwindow_mutex)) {
1327 0 5 if (!idx->pack_committed)
1335 0 5 while (git_oidmap_iterate((void **) &value, idx->expected_oids, &iter, &key) == 0)