Branch Coverage

deps/libgit2/src/indexer.c
Criterion Covered Total %
branch 167 378 44.1


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(
144 4 1 if (in_opts)
148 0 5 GIT_ERROR_CHECK_ALLOC(idx);
152 0 5 idx->mode = mode ? mode : GIT_PACK_FILE_MODE;
155 5 0 if ((error = git_hash_ctx_init(&idx->hash_ctx)) < 0 ||
5 0 if ((error = git_hash_ctx_init(&idx->hash_ctx)) < 0 ||
156 5 0 (error = git_hash_ctx_init(&idx->trailer)) < 0 ||
162 0 5 if (git_repository__fsync_gitdir)
166 0 5 if (error < 0)
171 0 5 if (fd < 0)
177 0 5 if (error < 0)
181 0 5 if ((error = git_mwindow_file_register(&idx->pack->mwf)) < 0)
188 0 0 if (fd != -1)
191 0 0 if (git_buf_len(&tmp_path) > 0)
194 0 0 if (idx->pack != NULL)
214 0 2 GIT_ERROR_CHECK_ALLOC(delta);
217 0 2 if (git_vector_insert(&idx->deltas, delta) < 0)
229 0 43 if ((error = git_odb__format_object_header(&hdrlen,
240 43 0 assert(idx && stream);
0 43 assert(idx && stream);
243 0 86 if ((read = git_packfile_stream_read(stream, idx->objbuf, sizeof(idx->objbuf))) < 0)
246 0 86 if (idx->do_verify)
250 43 43 } while (read > 0);
252 0 43 if (read < 0)
263 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);
265 2 0 if (type == GIT_OBJECT_REF_DELTA) {
271 0 0 if (error < 0)
283 0 4 assert(stream);
287 2 4 } while (read > 0);
289 2 2 if (read < 0)
303 45 45 while (size) {
305 0 45 if (ptr == NULL)
326 0 0 if ((!idx->odb || !git_odb_exists(idx->odb, oid)) &&
327 0 0 !git_oidmap_exists(idx->pack->idx_cache, oid) &&
330 0 0 GIT_ERROR_CHECK_ALLOC(dup);
344 0 0 if (obj->type != GIT_OBJECT_BLOB &&
0 0 if (obj->type != GIT_OBJECT_BLOB &&
345 0 0 obj->type != GIT_OBJECT_TREE &&
346 0 0 obj->type != GIT_OBJECT_COMMIT &&
350 0 0 if ((error = git_object__from_raw(&object, obj->data, obj->len, obj->type)) < 0)
353 0 0 if ((expected = git_oidmap_get(idx->expected_oids, &object->cached.oid)) != NULL) {
362 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))
372 0 0 git_array_foreach(tree->entries, i, entry)
0 0 git_array_foreach(tree->entries, i, entry)
373 0 0 if (add_expected_oid(idx, entry->oid) < 0)
384 0 0 git_array_foreach(commit->parent_ids, i, parent_oid)
0 0 git_array_foreach(commit->parent_ids, i, parent_oid)
385 0 0 if (add_expected_oid(idx, parent_oid) < 0)
388 0 0 if (add_expected_oid(idx, &commit->tree_id) < 0)
397 0 0 if (add_expected_oid(idx, &tag->target) < 0)
423 0 43 GIT_ERROR_CHECK_ALLOC(entry);
426 0 43 GIT_ERROR_CHECK_ALLOC(pentry);
430 0 43 if (entry_start > UINT31_MAX) {
437 0 43 if (idx->do_verify) {
444 0 0 if ((error = check_object_connectivity(idx, &rawobj)) < 0)
451 0 43 if (git_oidmap_exists(idx->pack->idx_cache, &pentry->sha1)) {
457 0 43 if ((error = git_oidmap_set(idx->pack->idx_cache, &pentry->sha1, pentry)) < 0) {
465 0 43 if (crc_object(&entry->crc, &idx->pack->mwf, entry_start, entry_size) < 0)
469 0 43 if (git_vector_insert(&idx->objects, entry) < 0)
472 5230 43 for (i = oid.id[0]; i < 256; ++i) {
493 0 2 if (entry_start > UINT31_MAX) {
509 0 2 if (git_vector_insert(&idx->objects, entry) < 0)
512 134 2 for (i = entry->oid.id[0]; i < 256; ++i) {
527 0 2 GIT_ERROR_CHECK_ALLOC(entry);
529 0 2 if (git_odb__hashobj(&oid, obj) < 0) {
535 0 2 GIT_ERROR_CHECK_ALLOC(pentry);
542 0 2 if (crc_object(&entry->crc, &idx->pack->mwf, entry_start, entry_size) < 0)
556 41 11 if (idx->progress_cb)
568 0 91 if (size == 0)
572 45 46 if (size >= GIT_OID_RAWSZ) {
583 8 38 if (idx->inbuf_len + size <= GIT_OID_RAWSZ) {
610 91 0 assert(data && size);
0 91 assert(data && size);
612 0 91 if ((error = git__mmap_alignment(&mmap_alignment)) < 0)
619 0 91 if ((error = p_mmap(&map, page_offset + size, GIT_PROT_WRITE, GIT_MAP_SHARED, fd, page_start)) < 0)
639 0 91 if (!size)
642 0 91 if ((error = git__mmap_alignment(&mmap_alignment)) < 0)
671 84 47 if (idx->pack->mwf.size <= idx->off + 20)
674 45 2 if (!idx->have_stream) {
676 0 45 if (error == GIT_EBUFS) {
680 0 45 if (error < 0)
688 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) {
690 0 2 if (error == GIT_EBUFS) {
694 0 2 if (error < 0)
702 0 43 if (error < 0)
710 0 45 if (error < 0)
714 4 43 if (idx->have_delta) {
721 2 45 if (error == GIT_EBUFS)
728 0 45 if (error < 0)
731 2 43 if (idx->have_delta) {
737 0 45 if (error < 0)
740 43 2 if (!idx->have_delta) {
745 0 45 if ((error = do_progress_callback(idx, stats)) != 0)
757 91 0 assert(idx && data && stats);
91 0 assert(idx && data && stats);
0 91 assert(idx && data && stats);
759 0 91 if ((error = append_to_pack(idx, data, size)) < 0)
767 5 86 if (!idx->parsed_header) {
770 0 5 if ((unsigned)idx->pack->mwf.size < sizeof(struct git_pack_header))
773 0 5 if ((error = parse_header(&idx->hdr, idx->pack)) < 0)
780 5 0 if (idx->nr_objects <= git_indexer__max_objects) {
787 0 5 if (git_oidmap_new(&idx->pack->idx_cache) < 0)
791 0 5 if (git_vector_init(&idx->objects, total_objects, objects_cmp) < 0)
794 0 5 if (git_vector_init(&idx->deltas, total_objects / 2, NULL) < 0)
804 0 5 if ((error = do_progress_callback(idx, stats)) != 0)
813 131 5 while (stats->indexed_objects < idx->nr_objects) {
814 86 45 if ((error = read_stream_object(idx, stats)) != 0) {
815 86 0 if (error == GIT_EBUFS)
835 330 0 while (slash > 0 && path->ptr[slash - 1] != '/')
320 10 while (slash > 0 && path->ptr[slash - 1] != '/')
838 0 10 if (git_buf_grow(path, slash + 1 + strlen(prefix) +
848 0 10 return git_buf_oom(path) ? -1 : 0;
877 0 0 if (git_odb_read(&obj, idx->odb, id) < 0) {
886 0 0 GIT_ERROR_CHECK_ALLOC(entry);
892 0 0 if ((error = append_to_pack(idx, hdr, hdr_len)) < 0)
898 0 0 if ((error = git_zstream_deflatebuf(&buf, data, len)) < 0)
902 0 0 if ((error = append_to_pack(idx, buf.ptr, buf.size)) < 0)
911 0 0 if ((error = append_to_pack(idx, &foo, GIT_OID_RAWSZ)) < 0)
917 0 0 GIT_ERROR_CHECK_ALLOC(pentry);
926 0 0 if (error) {
948 0 0 assert(git_vector_length(&idx->deltas) > 0);
950 0 0 if (idx->odb == NULL) {
956 0 0 git_vector_foreach(&idx->deltas, i, delta) {
957 0 0 if (!delta)
962 0 0 if (error < 0)
965 0 0 if (type == GIT_OBJECT_REF_DELTA) {
971 0 0 if (!found_ref_delta) {
978 0 0 if (base_info == NULL) {
986 0 0 if (has_entry(idx, &base))
989 0 0 if (inject_object(idx, &base) < 0)
1004 4 3 while (idx->deltas.length > 0) {
1007 4 4 git_vector_foreach(&idx->deltas, i, delta) {
1010 2 2 if (!delta)
1015 0 2 if ((error = git_packfile_unpack(&obj, idx->pack, &idx->off)) < 0) {
1016 0 0 if (error == GIT_PASSTHROUGH) {
1023 0 2 if (idx->do_verify && check_object_connectivity(idx, &obj) < 0)
0 0 if (idx->do_verify && check_object_connectivity(idx, &obj) < 0)
1027 0 2 if (hash_and_save(idx, &obj, delta->delta_off) < 0)
1034 0 2 if ((progress_cb_result = do_progress_callback(idx, stats)) < 0)
1043 2 2 if (!non_null)
1046 0 2 if (!progressed && (fix_thin_pack(idx, stats) < 0)) {
0 0 if (!progressed && (fix_thin_pack(idx, stats) < 0)) {
1070 0 0 if (write_at(idx, &idx->hdr, 0, sizeof(struct git_pack_header)) < 0)
1081 0 0 while (hashed < mwf->size) {
1083 0 0 if (ptr == NULL)
1107 0 5 if (!idx->parsed_header) {
1113 0 5 if (idx->off + 20 < idx->pack->mwf.size) {
1117 0 5 if (idx->off + 20 > idx->pack->mwf.size) {
1123 0 5 if (packfile_trailer == NULL) {
1133 0 5 if (git_oid_cmp(&file_hash, &trailer_hash)) {
1141 0 5 if ((error = resolve_deltas(idx, stats)) < 0)
1144 0 5 if (stats->indexed_objects != stats->total_objects) {
1149 0 5 if (stats->local_objects > 0) {
1150 0 0 if (update_header_and_rehash(idx, stats) < 0)
1163 0 5 if (git_oidmap_size(idx->expected_oids) > 0) {
1178 0 5 if (git_buf_oom(&filename))
1181 0 5 if (git_filebuf_open(&index_file, filename.ptr,
0 5 if (git_filebuf_open(&index_file, filename.ptr,
1193 1280 5 for (i = 0; i < 256; ++i) {
1199 45 5 git_vector_foreach(&idx->objects, i, entry) {
1204 45 5 git_vector_foreach(&idx->objects, i, entry) {
1209 45 5 git_vector_foreach(&idx->objects, i, entry) {
1212 0 45 if (entry->offset == UINT32_MAX)
1221 45 5 git_vector_foreach(&idx->objects, i, entry) {
1224 45 0 if (entry->offset != UINT32_MAX)
1234 0 5 if (git_filebuf_write(&index_file, &trailer_hash, GIT_OID_RAWSZ) < 0)
1238 0 5 if (git_filebuf_hash(&trailer_hash, &index_file) < 0)
1244 0 5 if (index_path(&filename, idx, ".idx") < 0)
1248 0 5 if (git_filebuf_commit_at(&index_file, filename.ptr) < 0)
1254 0 5 if (p_ftruncate(idx->pack->mwf.fd, idx->pack->mwf.size) < 0) {
1259 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) {
1265 0 5 if (p_close(idx->pack->mwf.fd) < 0) {
1272 0 5 if (index_path(&filename, idx, ".pack") < 0)
1276 0 5 if (p_rename(idx->pack->pack_name, git_buf_cstr(&filename)) < 0)
1302 0 5 if (idx == NULL)
1305 0 5 if (idx->have_stream)
1310 5 0 if (idx->pack->idx_cache) {
1312 45 5 git_oidmap_foreach_value(idx->pack->idx_cache, pentry, {
1321 5 0 if (!git_mutex_lock(&git__mwindow_mutex)) {
1322 0 5 if (!idx->pack_committed)
1330 0 5 while (git_oidmap_iterate((void **) &value, idx->expected_oids, &iter, &key) == 0)