Branch Coverage

deps/libgit2/src/libgit2/pack-objects.c
Criterion Covered Total %
branch 309 610 50.6


line true false branch
72 34 19 if (!name)
80 108 19 while ((c = *name++) != 0) {
81 0 108 if (git__isspace(c))
94 0 7 if ((ret = git_repository_config_snapshot(&config, pb->repo)) < 0)
112 0 7 config_get("pack.deltaCacheSize", pb->max_delta_cache_size,
0 0 config_get("pack.deltaCacheSize", pb->max_delta_cache_size,
7 0 config_get("pack.deltaCacheSize", pb->max_delta_cache_size,
0 0 config_get("pack.deltaCacheSize", pb->max_delta_cache_size,
114 0 7 config_get("pack.deltaCacheLimit", pb->cache_max_small_delta_size,
0 0 config_get("pack.deltaCacheLimit", pb->cache_max_small_delta_size,
7 0 config_get("pack.deltaCacheLimit", pb->cache_max_small_delta_size,
0 0 config_get("pack.deltaCacheLimit", pb->cache_max_small_delta_size,
116 0 7 config_get("pack.deltaCacheSize", pb->big_file_threshold,
0 0 config_get("pack.deltaCacheSize", pb->big_file_threshold,
7 0 config_get("pack.deltaCacheSize", pb->big_file_threshold,
0 0 config_get("pack.deltaCacheSize", pb->big_file_threshold,
118 0 7 config_get("pack.windowMemory", pb->window_memory_limit, 0);
0 0 config_get("pack.windowMemory", pb->window_memory_limit, 0);
7 0 config_get("pack.windowMemory", pb->window_memory_limit, 0);
0 0 config_get("pack.windowMemory", pb->window_memory_limit, 0);
135 0 7 GIT_ERROR_CHECK_ALLOC(pb);
138 7 0 git_oidmap_new(&pb->walk_objects) < 0 ||
146 7 0 git_zstream_init(&pb->zstream, GIT_ZSTREAM_DEFLATE) < 0 ||
147 7 0 git_repository_odb(&pb->odb, repo) < 0 ||
154 0 7 git_mutex_init(&pb->progress_mutex) ||
173 0 6 GIT_ASSERT_ARG(pb);
192 0 6 for (i = 0, po = pb->object_list; i < pb->nr_objects; i++, po++) {
193 0 0 if (git_oidmap_set(pb->object_ix, &po->id, po) < 0)
207 0 64 GIT_ASSERT_ARG(pb);
208 0 64 GIT_ASSERT_ARG(oid);
212 11 53 if (git_oidmap_exists(pb->object_ix, oid))
215 6 47 if (pb->nr_objects >= pb->nr_alloc) {
216 0 6 GIT_ERROR_CHECK_ALLOC_ADD(&newsize, pb->nr_alloc, 1024);
0 6 GIT_ERROR_CHECK_ALLOC_ADD(&newsize, pb->nr_alloc, 1024);
217 0 6 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newsize, newsize / 2, 3);
0 6 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newsize, newsize / 2, 3);
219 0 6 if (!git__is_uint32(newsize)) {
228 0 6 GIT_ERROR_CHECK_ALLOC(pb->object_list);
230 0 6 if (rehash(pb) < 0)
237 0 53 if ((ret = git_odb_read_header(&po->size, &po->type, pb->odb, oid)) < 0)
244 0 53 if (git_oidmap_set(pb->object_ix, &po->id, po) < 0) {
251 32 21 if (pb->progress_cb) {
255 32 0 if (elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
2 30 if (elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
262 0 2 if (ret)
288 0 0 if (error < 0 && error != GIT_EBUFS)
0 0 if (error < 0 && error != GIT_EBUFS)
291 0 0 if (error == GIT_EBUFS || delta_size != po->delta_size) {
0 0 if (error == GIT_EBUFS || delta_size != po->delta_size) {
326 3 50 if (po->delta) {
327 3 0 if (po->delta_data)
329 0 0 else if ((error = get_delta(&data, pb->odb, po)) < 0)
335 0 50 if ((error = git_odb_read(&obj, pb->odb, &po->id)) < 0)
344 53 0 if ((error = git_packfile__object_header(&hdr_len, hdr, data_len, type)) < 0 ||
53 0 if ((error = git_packfile__object_header(&hdr_len, hdr, data_len, type)) < 0 ||
345 53 0 (error = write_cb(hdr, hdr_len, cb_data)) < 0 ||
349 3 50 if (type == GIT_OBJECT_REF_DELTA) {
350 3 0 if ((error = write_cb(po->delta->id.id, GIT_OID_RAWSZ, cb_data)) < 0 ||
3 0 if ((error = write_cb(po->delta->id.id, GIT_OID_RAWSZ, cb_data)) < 0 ||
356 3 50 if (po->z_delta_size) {
359 3 0 if ((error = write_cb(data, data_len, cb_data)) < 0 ||
3 0 if ((error = write_cb(data, data_len, cb_data)) < 0 ||
364 0 50 GIT_ERROR_CHECK_ALLOC(zbuf);
368 0 50 if ((error = git_zstream_set_input(&pb->zstream, data, data_len)) < 0)
371 50 50 while (!git_zstream_done(&pb->zstream)) {
372 50 0 if ((error = git_zstream_get_output(zbuf, &zbuf_len, &pb->zstream)) < 0 ||
50 0 if ((error = git_zstream_get_output(zbuf, &zbuf_len, &pb->zstream)) < 0 ||
373 50 0 (error = write_cb(zbuf, zbuf_len, cb_data)) < 0 ||
388 3 50 if (po->delta) {
417 0 56 if (po->recursing) {
420 3 53 } else if (po->written) {
425 3 50 if (po->delta) {
428 0 3 if ((error = write_one(status, pb, po->delta, write_cb, cb_data)) < 0)
432 0 3 if (*status == WRITE_ONE_RECURSIVE)
446 0 53 if (po->filled)
456 0 0 while (po) {
457 0 0 if (add_to_order) {
462 0 0 for (s = po->delta_sibling; s; s = s->delta_sibling) {
467 0 0 if (po->delta_child) {
473 0 0 if (po->delta_sibling) {
479 0 0 while (po && !po->delta_sibling) {
0 0 while (po && !po->delta_sibling) {
484 0 0 if (!po) {
499 0 0 for (root = po; root->delta; root = root->delta)
511 0 0 if ((po = git_oidmap_get(pb->object_ix, oid)) == NULL)
528 1 6 if (!pb->nr_objects)
531 0 6 if ((wo = git__mallocarray(pb->nr_objects, sizeof(*wo))) == NULL)
534 53 6 for (i = 0; i < pb->nr_objects; i++) {
547 53 6 for (i = pb->nr_objects; i > 0;) {
549 50 3 if (!po->delta)
559 0 6 if (git_tag_foreach(pb->repo, &cb_tag_foreach, pb) < 0) {
568 53 6 for (i = wo_end = 0; i < pb->nr_objects; i++) {
570 0 53 if (po->tagged)
579 0 6 for (; i < pb->nr_objects; i++) {
581 0 0 if (po->tagged)
588 0 6 for (i = last_untagged; i < pb->nr_objects; i++) {
590 0 0 if (po->type != GIT_OBJECT_COMMIT &&
0 0 if (po->type != GIT_OBJECT_COMMIT &&
599 0 6 for (i = last_untagged; i < pb->nr_objects; i++) {
601 0 0 if (po->type != GIT_OBJECT_TREE)
609 0 6 for (i = last_untagged; i < pb->nr_objects; i++) {
611 0 0 if (!po->filled)
615 0 6 if (wo_end != pb->nr_objects) {
637 0 7 if ((error = compute_write_order(&write_order, pb)) < 0)
640 0 7 if (!git__is_uint32(pb->nr_objects)) {
651 7 0 if ((error = write_cb(&ph, sizeof(ph), cb_data)) < 0 ||
7 0 if ((error = write_cb(&ph, sizeof(ph), cb_data)) < 0 ||
658 53 7 for ( ; i < pb->nr_objects; ++i) {
661 0 53 if ((error = write_one(&status, pb, po, write_cb, cb_data)) < 0)
666 0 7 } while (pb->nr_remaining && i < pb->nr_objects);
0 0 } while (pb->nr_remaining && i < pb->nr_objects);
668 0 7 if ((error = git_hash_final(entry_oid.id, &pb->ctx)) < 0)
675 0 7 for ( ; i < pb->nr_objects; ++i) {
677 0 0 if (po->delta_data) {
698 9 34 if (a->type > b->type)
700 17 17 if (a->type < b->type)
702 0 17 if (a->hash > b->hash)
704 0 17 if (a->hash < b->hash)
714 6 11 if (a->size > b->size)
716 6 5 if (a->size < b->size)
718 4 1 return a < b ? -1 : (a > b); /* newest first */
729 0 3 if (git__add_sizet_overflow(&new_size, pb->delta_cache_size, delta_size))
732 3 0 if (pb->max_delta_cache_size && new_size > pb->max_delta_cache_size)
0 3 if (pb->max_delta_cache_size && new_size > pb->max_delta_cache_size)
735 3 0 if (delta_size < pb->cache_max_small_delta_size)
739 0 0 if ((src_size >> 20) + (trg_size >> 21) > (delta_size >> 10))
757 13 20 if (trg_object->type != src_object->type) {
767 0 20 if (src->depth >= max_depth)
772 20 0 if (!trg_object->delta) {
782 0 20 if (max_size == 0)
786 0 20 sizediff = src_size < trg_size ? trg_size - src_size : 0;
787 0 20 if (sizediff >= max_size)
789 0 20 if (trg_size < src_size / 32)
793 12 8 if (!trg->data) {
794 0 12 if (git_odb_read(&obj, pb->odb, &trg_object->id) < 0)
799 0 12 GIT_ERROR_CHECK_ALLOC(trg->data);
804 0 12 if (sz != trg_size) {
812 6 14 if (!src->data) {
815 6 0 if (git_odb_read(&obj, pb->odb, &src_object->id) < 0 ||
0 6 if (git_odb_read(&obj, pb->odb, &src_object->id) < 0 ||
821 0 6 GIT_ERROR_CHECK_ALLOC(src->data);
826 0 6 if (sz != src_size) {
834 12 8 if (!src->index) {
835 0 12 if (git_delta_index_init(&src->index, src->data, src_size) < 0)
841 17 3 if (git_delta_create_from_index(&delta_buf, &delta_size, src->index, trg->data, trg_size,
845 0 3 if (trg_object->delta) {
847 0 0 if (delta_size == trg_object->delta_size &&
0 0 if (delta_size == trg_object->delta_size &&
854 0 3 GIT_ASSERT(git_packbuilder__cache_lock(pb) == 0);
856 0 3 if (trg_object->delta_data) {
858 0 0 GIT_ASSERT(pb->delta_cache_size >= trg_object->delta_size);
862 3 0 if (delta_cacheable(pb, src_size, trg_size, delta_size)) {
866 0 3 GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0);
868 0 3 if (overflow) {
874 0 3 GIT_ERROR_CHECK_ALLOC(trg_object->delta_data);
877 0 0 GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0);
894 0 0 while (child) {
896 0 0 if (m < c)
907 0 24 if (n->index) {
913 0 24 if (n->data) {
928 19 11 if (pb->progress_cb) {
932 16 3 if (force || elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
16 0 if (force || elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
1 15 if (force || elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
939 0 4 if (ret)
959 0 6 GIT_ERROR_CHECK_ALLOC(array);
965 0 30 GIT_ASSERT(git_packbuilder__progress_lock(pb) == 0);
966 6 24 if (!*list_size) {
967 0 6 GIT_ASSERT(git_packbuilder__progress_unlock(pb) == 0);
976 0 24 GIT_ASSERT(git_packbuilder__progress_unlock(pb) == 0);
981 0 24 while (pb->window_memory_limit &&
0 0 while (pb->window_memory_limit &&
982 0 0 mem_usage > pb->window_memory_limit &&
995 0 24 if (po->delta_child) {
998 0 0 if (delta_limit > max_depth)
1005 44 0 while (--j > 0) {
1010 33 11 if (other_idx >= window)
1014 11 33 if (!m->object)
1017 0 33 if (try_delta(pb, n, m, max_depth, &mem_usage, &ret) < 0)
1019 13 20 if (ret < 0)
1021 3 17 else if (ret > 0)
1039 3 21 if (po->delta_data) {
1040 0 3 if (git_zstream_deflatebuf(&zbuf, po->delta_data, po->delta_size) < 0)
1045 0 3 GIT_ERROR_CHECK_ALLOC(po->delta_data);
1051 0 3 GIT_ASSERT(git_packbuilder__cache_lock(pb) == 0);
1054 0 3 GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0);
1062 3 21 if (po->delta && max_depth <= n->depth)
0 3 if (po->delta && max_depth <= n->depth)
1070 3 21 if (po->delta) {
1074 5 3 while (dist--) {
1084 24 0 if (count + 1 < window)
1086 0 24 if (idx >= window)
1092 66 6 for (i = 0; i < window; ++i) {
1126 3 3 while (me->remaining) {
1132 0 3 GIT_ASSERT_WITH_RETVAL(git_packbuilder__progress_lock(me->pb) == 0, NULL);
1135 0 3 GIT_ASSERT_WITH_RETVAL(git_packbuilder__progress_unlock(me->pb) == 0, NULL);
1137 0 3 if (git_mutex_lock(&me->mutex)) {
1142 3 3 while (!me->data_ready)
1167 3 3 if (!pb->nr_threads)
1170 3 3 if (pb->nr_threads <= 1) {
1176 0 3 GIT_ERROR_CHECK_ALLOC(p);
1179 48 3 for (i = 0; i < pb->nr_threads; ++i) {
1183 48 0 if (sub_size < 2*window && i+1 < pb->nr_threads)
45 3 if (sub_size < 2*window && i+1 < pb->nr_threads)
1193 3 45 while (sub_size && sub_size < list_size &&
0 3 while (sub_size && sub_size < list_size &&
0 0 while (sub_size && sub_size < list_size &&
1194 0 0 list[sub_size]->hash &&
1207 48 3 for (i = 0; i < pb->nr_threads; ++i) {
1208 45 3 if (!p[i].list_size)
1216 0 3 if (ret) {
1231 3 3 while (active_threads) {
1240 0 3 GIT_ASSERT(git_packbuilder__progress_lock(pb) == 0);
1242 99 3 for (i = 0; !target && i < pb->nr_threads; i++)
96 3 for (i = 0; !target && i < pb->nr_threads; i++)
1243 3 93 if (!p[i].working)
1245 3 3 if (target)
1253 48 3 for (i = 0; i < pb->nr_threads; i++)
1254 0 48 if (p[i].remaining > 2*window &&
0 0 if (p[i].remaining > 2*window &&
1255 0 0 (!victim || victim->remaining < p[i].remaining))
1258 0 3 if (victim) {
1261 0 0 while (sub_size && list[0]->hash &&
0 0 while (sub_size && list[0]->hash &&
0 0 while (sub_size && list[0]->hash &&
1266 0 0 if (!sub_size) {
1283 0 3 GIT_ASSERT(git_packbuilder__progress_unlock(pb) == 0);
1285 0 3 if (git_mutex_lock(&target->mutex)) {
1295 3 0 if (!sub_size) {
1316 10 1 if (pb->nr_objects == 0 || pb->done)
4 6 if (pb->nr_objects == 0 || pb->done)
1323 3 3 if (pb->progress_cb)
1327 0 6 GIT_ERROR_CHECK_ALLOC(delta_list);
1329 53 6 for (i = 0; i < pb->nr_objects; ++i) {
1333 24 29 if (po->size < 50 || po->size > pb->big_file_threshold)
0 24 if (po->size < 50 || po->size > pb->big_file_threshold)
1339 6 0 if (n > 1) {
1341 0 6 if (ll_find_deltas(pb, delta_list, n,
1360 0 4 PREPARE_PACK;
1366 0 3 PREPARE_PACK;
1373 0 0 GIT_BUF_WRAP_PRIVATE(buf, git_packbuilder__write_buf, pb);
0 0 GIT_BUF_WRAP_PRIVATE(buf, git_packbuilder__write_buf, pb);
1397 0 4 PREPARE_PACK;
1399 0 4 if (path == NULL) {
1400 0 0 if ((error = git_repository__item_path(&object_path, pb->repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0)
1402 0 0 if ((error = git_str_joinpath(&object_path, git_str_cstr(&object_path), "pack")) < 0)
1410 0 4 if ((error = git_indexer_new(&indexer, path, mode, pb->odb, &opts)) < 0)
1413 4 0 if (!git_repository__configmap_lookup(&t, pb->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t)
0 4 if (!git_repository__configmap_lookup(&t, pb->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t)
1419 0 4 if ((error = git_packbuilder_foreach(pb, write_cb, &ctx)) < 0)
1422 0 4 if ((error = git_indexer_commit(indexer, &stats)) < 0)
1430 0 4 GIT_ERROR_CHECK_ALLOC(pb->pack_name);
1460 0 11 if (git_tree_entry_type(entry) == GIT_OBJECT_COMMIT)
1463 11 0 if (!(error = git_str_sets(&ctx->buf, root)) &&
11 0 if (!(error = git_str_sets(&ctx->buf, root)) &&
1479 0 4 if (git_packbuilder_insert_tree(pb, git_commit_tree_id(commit)) < 0)
1492 4 0 if (!(error = git_tree_lookup(&tree, pb->repo, oid)) &&
4 0 if (!(error = git_tree_lookup(&tree, pb->repo, oid)) &&
1506 0 1 GIT_ASSERT_ARG(pb);
1507 0 1 GIT_ASSERT_ARG(id);
1509 0 1 if ((error = git_object_lookup(&obj, pb->repo, id, GIT_OBJECT_ANY)) < 0)
1523 0 0 if ((error = git_packbuilder_insert(pb, id, name)) < 0)
1553 0 36 if (!obj) {
1569 36 8 if ((obj = git_oidmap_get(pb->walk_objects, id)) == NULL) {
1570 0 36 if ((error = lookup_walk_object(&obj, pb, id)) < 0)
1573 0 36 if ((error = git_oidmap_set(pb->walk_objects, &obj->id, obj)) < 0)
1586 0 0 if ((error = retrieve_object(&obj, pb, id)) < 0)
1601 0 0 if ((error = retrieve_object(&obj, pb, id)) < 0)
1604 0 0 if (obj->uninteresting)
1609 0 0 if ((error = git_tree_lookup(&tree, pb->repo, id)) < 0)
1612 0 0 for (i = 0; i < git_tree_entrycount(tree); i++) {
1617 0 0 if ((error = mark_tree_uninteresting(pb, entry_id)) < 0)
1621 0 0 if ((error = mark_blob_uninteresting(pb, entry_id)) < 0)
1646 3 3 for (list = commits; list; list = list->next) {
1647 3 0 if (!list->item->uninteresting)
1650 0 0 if ((error = git_commit_lookup(&commit, pb->repo, &list->item->oid)) < 0)
1656 0 0 if (error < 0)
1671 0 17 if ((error = retrieve_object(&obj, pb, git_tree_id(tree))) < 0)
1674 17 0 if (obj->seen || obj->uninteresting)
0 17 if (obj->seen || obj->uninteresting)
1679 0 17 if ((error = git_packbuilder_insert(pb, &obj->id, NULL)))
1682 26 17 for (i = 0; i < git_tree_entrycount(tree); i++) {
1687 0 8 if ((error = git_tree_lookup(&subtree, pb->repo, entry_id)) < 0)
1693 0 8 if (error < 0)
1698 0 18 if ((error = retrieve_object(&obj, pb, entry_id)) < 0)
1700 0 18 if (obj->uninteresting)
1703 0 18 if ((error = git_packbuilder_insert(pb, entry_id, name)) < 0)
1724 0 9 if ((error = git_packbuilder_insert(pb, &obj->id, NULL)) < 0)
1727 0 9 if ((error = git_commit_lookup(&commit, pb->repo, &obj->id)) < 0)
1730 0 9 if ((error = git_tree_lookup(&tree, pb->repo, git_commit_tree_id(commit))) < 0)
1733 0 9 if ((error = pack_objects_insert_tree(pb, tree)) < 0)
1748 0 3 GIT_ASSERT_ARG(pb);
1749 0 3 GIT_ASSERT_ARG(walk);
1751 0 3 if ((error = mark_edges_uninteresting(pb, walk->user_input)) < 0)
1762 9 3 while ((error = git_revwalk_next(&id, walk)) == 0) {
1763 0 9 if ((error = retrieve_object(&obj, pb, &id)) < 0)
1766 9 0 if (obj->seen || obj->uninteresting)
0 9 if (obj->seen || obj->uninteresting)
1769 0 9 if ((error = pack_objects_insert_commit(pb, obj)) < 0)
1773 3 0 if (error == GIT_ITEROVER)
1781 0 3 if (!pb)
1792 0 7 if (pb == NULL)
1803 7 0 if (pb->odb)
1806 7 0 if (pb->object_ix)
1809 6 1 if (pb->object_list)