Branch Coverage

deps/libgit2/src/pack-objects.c
Criterion Covered Total %
branch 253 508 49.8


line true false branch
79 34 19 if (!name)
87 108 19 while ((c = *name++) != 0) {
88 0 108 if (git__isspace(c))
101 0 7 if ((ret = git_repository_config_snapshot(&config, pb->repo)) < 0)
119 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,
121 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,
123 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,
125 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);
142 0 7 GIT_ERROR_CHECK_ALLOC(pb);
145 7 0 git_oidmap_new(&pb->walk_objects) < 0 ||
153 7 0 git_zstream_init(&pb->zstream, GIT_ZSTREAM_DEFLATE) < 0 ||
154 7 0 git_repository_odb(&pb->odb, repo) < 0 ||
180 0 6 assert(pb);
186 0 6 assert(1 == pb->nr_threads);
199 0 6 for (i = 0, po = pb->object_list; i < pb->nr_objects; i++, po++) {
200 0 0 if (git_oidmap_set(pb->object_ix, &po->id, po) < 0)
214 64 0 assert(pb && oid);
0 64 assert(pb && oid);
218 11 53 if (git_oidmap_exists(pb->object_ix, oid))
221 6 47 if (pb->nr_objects >= pb->nr_alloc) {
222 0 6 GIT_ERROR_CHECK_ALLOC_ADD(&newsize, pb->nr_alloc, 1024);
0 6 GIT_ERROR_CHECK_ALLOC_ADD(&newsize, pb->nr_alloc, 1024);
223 0 6 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newsize, newsize / 2, 3);
0 6 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newsize, newsize / 2, 3);
225 0 6 if (!git__is_uint32(newsize)) {
234 0 6 GIT_ERROR_CHECK_ALLOC(pb->object_list);
236 0 6 if (rehash(pb) < 0)
243 0 53 if ((ret = git_odb_read_header(&po->size, &po->type, pb->odb, oid)) < 0)
250 0 53 if (git_oidmap_set(pb->object_ix, &po->id, po) < 0) {
257 32 21 if (pb->progress_cb) {
261 2 30 if (elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
268 0 2 if (ret)
294 0 0 if (error < 0 && error != GIT_EBUFS)
0 0 if (error < 0 && error != GIT_EBUFS)
297 0 0 if (error == GIT_EBUFS || delta_size != po->delta_size) {
0 0 if (error == GIT_EBUFS || delta_size != po->delta_size) {
332 3 50 if (po->delta) {
333 3 0 if (po->delta_data)
335 0 0 else if ((error = get_delta(&data, pb->odb, po)) < 0)
341 0 50 if ((error = git_odb_read(&obj, pb->odb, &po->id)) < 0)
352 53 0 if ((error = write_cb(hdr, hdr_len, cb_data)) < 0 ||
53 0 if ((error = write_cb(hdr, hdr_len, cb_data)) < 0 ||
356 3 50 if (type == GIT_OBJECT_REF_DELTA) {
357 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 ||
363 3 50 if (po->z_delta_size) {
366 3 0 if ((error = write_cb(data, data_len, cb_data)) < 0 ||
3 0 if ((error = write_cb(data, data_len, cb_data)) < 0 ||
371 0 50 GIT_ERROR_CHECK_ALLOC(zbuf);
375 0 50 if ((error = git_zstream_set_input(&pb->zstream, data, data_len)) < 0)
378 50 50 while (!git_zstream_done(&pb->zstream)) {
379 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 ||
380 50 0 (error = write_cb(zbuf, zbuf_len, cb_data)) < 0 ||
395 3 50 if (po->delta) {
424 0 56 if (po->recursing) {
427 3 53 } else if (po->written) {
432 3 50 if (po->delta) {
435 0 3 if ((error = write_one(status, pb, po->delta, write_cb, cb_data)) < 0)
439 0 3 if (*status == WRITE_ONE_RECURSIVE)
453 0 53 if (po->filled)
463 0 0 while (po) {
464 0 0 if (add_to_order) {
469 0 0 for (s = po->delta_sibling; s; s = s->delta_sibling) {
474 0 0 if (po->delta_child) {
480 0 0 if (po->delta_sibling) {
486 0 0 while (po && !po->delta_sibling) {
0 0 while (po && !po->delta_sibling) {
491 0 0 if (!po) {
506 0 0 for (root = po; root->delta; root = root->delta)
518 0 0 if ((po = git_oidmap_get(pb->object_ix, oid)) == NULL)
533 0 7 if ((wo = git__mallocarray(pb->nr_objects, sizeof(*wo))) == NULL)
536 53 7 for (i = 0; i < pb->nr_objects; i++) {
549 53 7 for (i = pb->nr_objects; i > 0;) {
551 50 3 if (!po->delta)
561 0 7 if (git_tag_foreach(pb->repo, &cb_tag_foreach, pb) < 0) {
570 53 7 for (i = wo_end = 0; i < pb->nr_objects; i++) {
572 0 53 if (po->tagged)
581 0 7 for (; i < pb->nr_objects; i++) {
583 0 0 if (po->tagged)
590 0 7 for (i = last_untagged; i < pb->nr_objects; i++) {
592 0 0 if (po->type != GIT_OBJECT_COMMIT &&
0 0 if (po->type != GIT_OBJECT_COMMIT &&
601 0 7 for (i = last_untagged; i < pb->nr_objects; i++) {
603 0 0 if (po->type != GIT_OBJECT_TREE)
611 0 7 for (i = last_untagged; i < pb->nr_objects; i++) {
613 0 0 if (!po->filled)
617 0 7 if (wo_end != pb->nr_objects) {
639 0 7 if (write_order == NULL)
642 0 7 if (!git__is_uint32(pb->nr_objects)) {
652 7 0 if ((error = write_cb(&ph, sizeof(ph), cb_data)) < 0 ||
7 0 if ((error = write_cb(&ph, sizeof(ph), cb_data)) < 0 ||
659 53 7 for ( ; i < pb->nr_objects; ++i) {
662 0 53 if ((error = write_one(&status, pb, po, write_cb, cb_data)) < 0)
667 0 7 } while (pb->nr_remaining && i < pb->nr_objects);
0 0 } while (pb->nr_remaining && i < pb->nr_objects);
669 0 7 if ((error = git_hash_final(&entry_oid, &pb->ctx)) < 0)
676 0 7 for ( ; i < pb->nr_objects; ++i) {
678 0 0 if (po->delta_data) {
699 9 34 if (a->type > b->type)
701 17 17 if (a->type < b->type)
703 0 17 if (a->hash > b->hash)
705 0 17 if (a->hash < b->hash)
715 6 11 if (a->size > b->size)
717 6 5 if (a->size < b->size)
719 4 1 return a < b ? -1 : (a > b); /* newest first */
730 0 3 if (git__add_sizet_overflow(&new_size, pb->delta_cache_size, delta_size))
733 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)
736 3 0 if (delta_size < pb->cache_max_small_delta_size)
740 0 0 if ((src_size >> 20) + (trg_size >> 21) > (delta_size >> 10))
758 13 20 if (trg_object->type != src_object->type) {
768 0 20 if (src->depth >= max_depth)
773 20 0 if (!trg_object->delta) {
783 0 20 if (max_size == 0)
787 0 20 sizediff = src_size < trg_size ? trg_size - src_size : 0;
788 0 20 if (sizediff >= max_size)
790 0 20 if (trg_size < src_size / 32)
794 12 8 if (!trg->data) {
795 0 12 if (git_odb_read(&obj, pb->odb, &trg_object->id) < 0)
800 0 12 GIT_ERROR_CHECK_ALLOC(trg->data);
805 0 12 if (sz != trg_size) {
813 6 14 if (!src->data) {
816 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 ||
822 0 6 GIT_ERROR_CHECK_ALLOC(src->data);
827 0 6 if (sz != src_size) {
835 12 8 if (!src->index) {
836 0 12 if (git_delta_index_init(&src->index, src->data, src_size) < 0)
842 17 3 if (git_delta_create_from_index(&delta_buf, &delta_size, src->index, trg->data, trg_size,
846 0 3 if (trg_object->delta) {
848 0 0 if (delta_size == trg_object->delta_size &&
0 0 if (delta_size == trg_object->delta_size &&
856 0 3 if (trg_object->delta_data) {
858 0 0 assert(pb->delta_cache_size >= trg_object->delta_size);
862 3 0 if (delta_cacheable(pb, src_size, trg_size, delta_size)) {
868 0 3 if (overflow) {
874 0 3 GIT_ERROR_CHECK_ALLOC(trg_object->delta_data);
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 >= MIN_PROGRESS_UPDATE_INTERVAL) {
1 15 if (force || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
939 0 4 if (ret)
959 0 6 GIT_ERROR_CHECK_ALLOC(array);
966 6 24 if (!*list_size) {
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);
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) {
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;
1392 0 4 PREPARE_PACK;
1394 0 4 if (path == NULL) {
1395 0 0 if ((error = git_repository_item_path(&object_path, pb->repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0)
1397 0 0 if ((error = git_buf_joinpath(&object_path, git_buf_cstr(&object_path), "pack")) < 0)
1405 0 4 if ((error = git_indexer_new(&indexer, path, mode, pb->odb, &opts)) < 0)
1408 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)
1414 0 4 if ((error = git_packbuilder_foreach(pb, write_cb, &ctx)) < 0)
1417 0 4 if ((error = git_indexer_commit(indexer, &stats)) < 0)
1443 0 11 if (git_tree_entry_type(entry) == GIT_OBJECT_COMMIT)
1446 11 0 if (!(error = git_buf_sets(&ctx->buf, root)) &&
11 0 if (!(error = git_buf_sets(&ctx->buf, root)) &&
1462 0 4 if (git_packbuilder_insert_tree(pb, git_commit_tree_id(commit)) < 0)
1475 4 0 if (!(error = git_tree_lookup(&tree, pb->repo, oid)) &&
4 0 if (!(error = git_tree_lookup(&tree, pb->repo, oid)) &&
1489 1 0 assert(pb && id);
0 1 assert(pb && id);
1491 0 1 if ((error = git_object_lookup(&obj, pb->repo, id, GIT_OBJECT_ANY)) < 0)
1505 0 0 if ((error = git_packbuilder_insert(pb, id, name)) < 0)
1535 0 36 if (!obj) {
1551 36 8 if ((obj = git_oidmap_get(pb->walk_objects, id)) == NULL) {
1552 0 36 if ((error = lookup_walk_object(&obj, pb, id)) < 0)
1555 0 36 if ((error = git_oidmap_set(pb->walk_objects, &obj->id, obj)) < 0)
1568 0 0 if ((error = retrieve_object(&obj, pb, id)) < 0)
1583 0 0 if ((error = retrieve_object(&obj, pb, id)) < 0)
1586 0 0 if (obj->uninteresting)
1591 0 0 if ((error = git_tree_lookup(&tree, pb->repo, id)) < 0)
1594 0 0 for (i = 0; i < git_tree_entrycount(tree); i++) {
1599 0 0 if ((error = mark_tree_uninteresting(pb, entry_id)) < 0)
1603 0 0 if ((error = mark_blob_uninteresting(pb, entry_id)) < 0)
1628 3 3 for (list = commits; list; list = list->next) {
1629 3 0 if (!list->item->uninteresting)
1632 0 0 if ((error = git_commit_lookup(&commit, pb->repo, &list->item->oid)) < 0)
1638 0 0 if (error < 0)
1653 0 17 if ((error = retrieve_object(&obj, pb, git_tree_id(tree))) < 0)
1656 17 0 if (obj->seen || obj->uninteresting)
0 17 if (obj->seen || obj->uninteresting)
1661 0 17 if ((error = git_packbuilder_insert(pb, &obj->id, NULL)))
1664 26 17 for (i = 0; i < git_tree_entrycount(tree); i++) {
1669 0 8 if ((error = git_tree_lookup(&subtree, pb->repo, entry_id)) < 0)
1675 0 8 if (error < 0)
1680 0 18 if ((error = retrieve_object(&obj, pb, entry_id)) < 0)
1682 0 18 if (obj->uninteresting)
1685 0 18 if ((error = git_packbuilder_insert(pb, entry_id, name)) < 0)
1706 0 9 if ((error = git_packbuilder_insert(pb, &obj->id, NULL)) < 0)
1709 0 9 if ((error = git_commit_lookup(&commit, pb->repo, &obj->id)) < 0)
1712 0 9 if ((error = git_tree_lookup(&tree, pb->repo, git_commit_tree_id(commit))) < 0)
1715 0 9 if ((error = pack_objects_insert_tree(pb, tree)) < 0)
1730 3 0 assert(pb && walk);
0 3 assert(pb && walk);
1732 0 3 if ((error = mark_edges_uninteresting(pb, walk->user_input)) < 0)
1743 9 3 while ((error = git_revwalk_next(&id, walk)) == 0) {
1744 0 9 if ((error = retrieve_object(&obj, pb, &id)) < 0)
1747 9 0 if (obj->seen || obj->uninteresting)
0 9 if (obj->seen || obj->uninteresting)
1750 0 9 if ((error = pack_objects_insert_commit(pb, obj)) < 0)
1754 3 0 if (error == GIT_ITEROVER)
1762 0 3 if (!pb)
1773 0 7 if (pb == NULL)
1784 7 0 if (pb->odb)
1787 7 0 if (pb->object_ix)
1790 6 1 if (pb->object_list)