Branch Coverage

deps/libgit2/src/libgit2/odb.c
Criterion Covered Total %
branch 243 622 39.0


line true false branch
49 1938 0 if (owner != NULL) {
62 1 1032 if (!git_oid_cmp(id, &git_oid__empty_tree_sha1))
74 648 1 if ((type = odb_hardcoded_type(id)) == GIT_OBJECT_INVALID)
80 0 1 GIT_ERROR_CHECK_ALLOC(raw->data);
94 1394 0 int hdr_max = (hdr_size > INT_MAX-2) ? (INT_MAX-2) : (int)hdr_size;
99 1394 0 if (len < 0 || len >= hdr_max) {
0 1394 if (len < 0 || len >= hdr_max) {
115 0 994 GIT_ASSERT_ARG(id);
116 0 994 GIT_ASSERT_ARG(obj);
118 0 994 if (!git_object_typeisloose(obj->type)) {
123 0 994 if (!obj->data && obj->len != 0) {
0 0 if (!obj->data && obj->len != 0) {
128 0 994 if ((error = git_odb__format_object_header(&hdrlen,
145 776 0 if (object != NULL) {
157 774 0 if (object != NULL) {
192 3 1073 if (object == NULL)
206 0 117 if (!git_object_typeisloose(type)) {
211 0 117 if ((error = git_hash_ctx_init(&ctx, GIT_HASH_ALGORITHM_SHA1)) < 0)
214 0 117 if ((error = git_odb__format_object_header(&hdr_len, hdr,
218 0 117 if ((error = git_hash_update(&ctx, hdr, hdr_len)) < 0)
221 100 117 while (size > 0 && (read_len = p_read(fd, buffer, sizeof(buffer))) > 0) {
100 0 while (size > 0 && (read_len = p_read(fd, buffer, sizeof(buffer))) > 0) {
222 0 100 if ((error = git_hash_update(&ctx, buffer, read_len)) < 0)
231 117 0 if (read_len < 0 || size > 0) {
0 117 if (read_len < 0 || size > 0) {
251 117 39 if (!fl)
258 39 0 if (!(error = git_futils_readbuffer_fd(&raw, fd, size))) {
263 39 0 if (!error)
278 0 0 if (git_fs_path_lstat(path, &st) < 0)
281 0 0 if (!git__is_int(st.st_size) || (int)st.st_size < 0) {
0 0 if (!git__is_int(st.st_size) || (int)st.st_size < 0) {
288 0 0 if (S_ISLNK(st.st_mode)) {
293 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, size, 1);
295 0 0 GIT_ERROR_CHECK_ALLOC(link_data);
298 0 0 if (read_len == -1) {
303 0 0 GIT_ASSERT(read_len <= size);
310 0 0 if (fd < 0)
324 0 0 if ((fd = git_futils_open_ro(path)) < 0)
327 0 0 if ((error = git_futils_filesize(&size, fd)) < 0)
330 0 0 if (!git__is_sizet(size)) {
347 0 992 GIT_ASSERT_ARG(id);
377 0 0 GIT_ASSERT(stream->written + len <= stream->size);
397 0 0 GIT_ERROR_CHECK_BLOBSIZE(size);
401 0 0 GIT_ERROR_CHECK_ALLOC(stream);
406 0 0 if (stream->buffer == NULL) {
435 1 78 if (backend_b->priority == backend_a->priority) {
436 0 1 if (backend_a->is_alternate)
438 1 0 if (backend_b->is_alternate)
448 0 36 GIT_ERROR_CHECK_ALLOC(db);
450 0 36 if (git_mutex_init(&db->lock) < 0) {
454 0 36 if (git_cache_init(&db->own_cache) < 0) {
459 0 36 if (git_vector_init(&db->backends, 4, backend_sort_cmp) < 0) {
477 0 74 GIT_ASSERT_ARG(odb);
478 0 74 GIT_ASSERT_ARG(backend);
480 0 74 GIT_ERROR_CHECK_VERSION(backend, GIT_ODB_BACKEND_VERSION, "git_odb_backend");
483 0 74 GIT_ASSERT(!backend->odb || backend->odb == odb);
0 0 GIT_ASSERT(!backend->odb || backend->odb == odb);
486 0 74 GIT_ERROR_CHECK_ALLOC(internal);
493 0 74 if (git_mutex_lock(&odb->lock) < 0) {
497 0 74 if (git_vector_insert(&odb->backends, internal) < 0) {
523 0 7 GIT_ASSERT_ARG(odb);
525 0 7 if (git_mutex_lock(&odb->lock) < 0) {
530 7 0 if (locked)
548 0 0 GIT_ASSERT_ARG(out);
549 0 0 GIT_ASSERT_ARG(odb);
552 0 0 if ((error = git_mutex_lock(&odb->lock)) < 0) {
558 0 0 if (!internal || !internal->backend) {
0 0 if (!internal || !internal->backend) {
587 0 35 if (p_stat(objects_dir, &st) < 0) {
588 0 0 if (as_alternates)
598 0 35 if (git_mutex_lock(&db->lock) < 0) {
602 0 35 for (i = 0; i < db->backends.length; ++i) {
604 0 0 if (backend->disk_inode == inode) {
622 0 35 if (git_mutex_lock(&db->lock) < 0) {
626 35 0 if (!db->cgraph && git_commit_graph_new(&db->cgraph, objects_dir, false) < 0) {
0 35 if (!db->cgraph && git_commit_graph_new(&db->cgraph, objects_dir, false) < 0) {
644 0 35 if (alternate_depth > GIT_ALTERNATES_MAX_DEPTH)
647 0 35 if (git_str_joinpath(&alternates_path, objects_dir, GIT_ALTERNATES_FILE) < 0)
650 35 0 if (git_fs_path_exists(alternates_path.ptr) == false) {
655 0 0 if (git_futils_readbuffer(&alternates_buf, alternates_path.ptr) < 0) {
663 0 0 while ((alternate = git__strtok(&buffer, "\r\n")) != NULL) {
664 0 0 if (*alternate == '\0' || *alternate == '#')
0 0 if (*alternate == '\0' || *alternate == '#')
672 0 0 if (*alternate == '.' && !alternate_depth) {
0 0 if (*alternate == '.' && !alternate_depth) {
673 0 0 if ((result = git_str_joinpath(&alternates_path, objects_dir, alternate)) < 0)
678 0 0 if ((result = git_odb__add_default_backends(odb, alternate, true, alternate_depth + 1)) < 0)
697 0 0 GIT_ASSERT_ARG(odb);
699 0 0 if ((error = git_mutex_lock(&odb->lock)) < 0) {
714 0 2 GIT_ASSERT_ARG(out);
715 0 2 GIT_ASSERT_ARG(objects_dir);
719 0 2 if (git_odb_new(&db) < 0)
722 0 2 if (git_odb__add_default_backends(db, objects_dir, 0, 0) < 0) {
733 33 0 if (caps == GIT_ODB_CAP_FROM_OWNER) {
737 0 33 if (!repo) {
742 33 0 if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_FSYNCOBJECTFILES))
754 0 36 if (git_mutex_lock(&db->lock) < 0) {
758 74 36 for (i = 0; i < db->backends.length; ++i) {
766 36 0 if (locked)
780 10 202 if (db == NULL)
783 36 166 GIT_REFCOUNT_DEC(db, odb_free);
36 0 GIT_REFCOUNT_DEC(db, odb_free);
795 0 4 if ((error = git_mutex_lock(&db->lock)) < 0) {
799 8 4 for (i = 0; i < db->backends.length && !found; ++i) {
8 0 for (i = 0; i < db->backends.length && !found; ++i) {
803 0 8 if (only_refreshed && !b->refresh)
0 0 if (only_refreshed && !b->refresh)
806 8 0 if (b->exists != NULL)
819 0 179 if ((error = git_mutex_lock(&db->lock)) < 0) {
823 0 179 if (!db->cgraph) {
828 179 0 if (error)
846 0 454 if ((error = git_mutex_lock(&db->lock)) < 0) {
850 920 452 for (i = 0; i < db->backends.length && !found; ++i) {
918 2 for (i = 0; i < db->backends.length && !found; ++i) {
854 332 586 if (only_refreshed && !b->refresh)
169 163 if (only_refreshed && !b->refresh)
857 741 8 if (b->freshen != NULL)
859 8 0 else if (b->exists != NULL)
869 0 291 GIT_ASSERT_ARG(db);
870 0 291 GIT_ASSERT_ARG(id);
872 128 163 if (odb_freshen_1(db, id, false))
875 163 0 if (!git_odb_refresh(db))
891 0 4 GIT_ASSERT_ARG(db);
892 0 4 GIT_ASSERT_ARG(id);
894 0 4 if (git_oid_is_zero(id))
897 0 4 if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
902 4 0 if (odb_exists_1(db, id, false))
905 0 0 if (!(flags & GIT_ODB_LOOKUP_NO_REFRESH) && !git_odb_refresh(db))
0 0 if (!(flags & GIT_ODB_LOOKUP_NO_REFRESH) && !git_odb_refresh(db))
919 0 0 if ((error = git_mutex_lock(&db->lock)) < 0) {
924 0 0 for (i = 0; i < db->backends.length; ++i) {
928 0 0 if (only_refreshed && !b->refresh)
0 0 if (only_refreshed && !b->refresh)
931 0 0 if (!b->exists_prefix)
935 0 0 if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH)
0 0 if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH)
937 0 0 if (error) {
943 0 0 if (num_found) {
944 0 0 if (git_oid__cmp(&last_found, &found)) {
955 0 0 if (!num_found)
958 0 0 if (out)
970 0 0 GIT_ASSERT_ARG(db);
971 0 0 GIT_ASSERT_ARG(short_id);
973 0 0 if (len < GIT_OID_MINPREFIXLEN)
976 0 0 if (len >= GIT_OID_HEXSZ) {
977 0 0 if (git_odb_exists(db, short_id)) {
978 0 0 if (out)
991 0 0 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
0 0 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
994 0 0 if (error == GIT_ENOTFOUND)
1007 0 0 GIT_ASSERT_ARG(db);
1008 0 0 GIT_ASSERT_ARG(ids);
1010 0 0 for (i = 0; i < count; i++) {
1014 0 0 if (!query->type)
1018 0 0 if (query->length >= GIT_OID_MINPREFIXLEN && query->length < GIT_OID_HEXSZ) {
0 0 if (query->length >= GIT_OID_MINPREFIXLEN && query->length < GIT_OID_HEXSZ) {
1022 0 0 if (!error) {
1032 0 0 if (query->length >= GIT_OID_HEXSZ) {
1036 0 0 if (!error) {
1037 0 0 if (query->type != GIT_OBJECT_ANY && query->type != actual_type)
0 0 if (query->type != GIT_OBJECT_ANY && query->type != actual_type)
1074 3 367 if (object)
1089 384 0 if (!only_refreshed && (ht = odb_hardcoded_type(id)) != GIT_OBJECT_INVALID) {
0 384 if (!only_refreshed && (ht = odb_hardcoded_type(id)) != GIT_OBJECT_INVALID) {
1095 0 384 if ((error = git_mutex_lock(&db->lock)) < 0) {
1099 763 0 for (i = 0; i < db->backends.length; ++i) {
1103 0 763 if (only_refreshed && !b->refresh)
0 0 if (only_refreshed && !b->refresh)
1106 0 763 if (!b->read_header) {
1126 0 0 return passthrough ? GIT_PASSTHROUGH : GIT_ENOTFOUND;
1136 0 387 GIT_ASSERT_ARG(db);
1137 0 387 GIT_ASSERT_ARG(id);
1138 0 387 GIT_ASSERT_ARG(out);
1139 0 387 GIT_ASSERT_ARG(len_p);
1140 0 387 GIT_ASSERT_ARG(type_p);
1144 0 387 if (git_oid_is_zero(id))
1147 3 384 if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
1156 0 384 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
0 0 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
1159 0 384 if (error == GIT_ENOTFOUND)
1163 384 0 if (!error)
1166 0 0 if (error == GIT_PASSTHROUGH) {
1172 0 0 if (!error) {
1192 649 3 if (!only_refreshed) {
1193 0 649 if ((error = odb_read_hardcoded(&found, &raw, id)) < 0)
1197 0 652 if ((error = git_mutex_lock(&db->lock)) < 0) {
1201 1309 633 for (i = 0; i < db->backends.length && !found; ++i) {
1290 19 for (i = 0; i < db->backends.length && !found; ++i) {
1205 6 1284 if (only_refreshed && !b->refresh)
3 3 if (only_refreshed && !b->refresh)
1208 1287 0 if (b->read != NULL) {
1210 1287 0 if (error == GIT_PASSTHROUGH || error == GIT_ENOTFOUND)
642 645 if (error == GIT_PASSTHROUGH || error == GIT_ENOTFOUND)
1213 0 645 if (error < 0) {
1223 6 646 if (!found)
1226 646 0 if (git_odb__strict_hash_verification) {
1227 0 646 if ((error = git_odb_hash(&hashed, raw.data, raw.len, raw.type)) < 0)
1230 0 646 if (!git_oid_equal(id, &hashed)) {
1237 0 646 if ((object = odb_object__alloc(id, &raw)) == NULL) {
1245 0 646 if (error)
1254 0 649 GIT_ASSERT_ARG(out);
1255 0 649 GIT_ASSERT_ARG(db);
1256 0 649 GIT_ASSERT_ARG(id);
1258 0 649 if (git_oid_is_zero(id))
1262 0 649 if (*out != NULL)
1267 3 646 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
3 0 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
1270 3 646 if (error == GIT_ENOTFOUND)
1282 0 0 if (git_oid_is_zero(id))
1285 0 0 if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
1293 0 0 if (error == GIT_PASSTHROUGH) {
1295 0 0 if (!error)
1314 0 146 if ((error = git_mutex_lock(&db->lock)) < 0) {
1318 292 146 for (i = 0; i < db->backends.length; ++i) {
1322 16 276 if (only_refreshed && !b->refresh)
8 8 if (only_refreshed && !b->refresh)
1325 284 0 if (b->read_prefix != NULL) {
1329 130 154 if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH) {
0 130 if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH) {
1334 0 130 if (error) {
1342 0 130 if (found && git_oid__cmp(&full_oid, &found_full_oid)) {
0 0 if (found && git_oid__cmp(&full_oid, &found_full_oid)) {
1362 16 130 if (!found)
1365 130 0 if (git_odb__strict_hash_verification) {
1368 0 130 if ((error = git_odb_hash(&hash, raw.data, raw.len, raw.type)) < 0)
1371 0 130 if (!git_oid_equal(&found_full_oid, &hash)) {
1377 0 130 if ((object = odb_object__alloc(&found_full_oid, &raw)) == NULL) {
1385 0 130 if (error)
1397 0 138 GIT_ASSERT_ARG(out);
1398 0 138 GIT_ASSERT_ARG(db);
1400 0 138 if (len < GIT_OID_MINPREFIXLEN)
1403 0 138 if (len > GIT_OID_HEXSZ)
1406 122 16 if (len == GIT_OID_HEXSZ) {
1408 0 122 if (*out != NULL)
1416 8 130 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
8 0 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
1419 8 130 if (error == GIT_ENOTFOUND)
1433 0 1 if ((error = git_mutex_lock(&db->lock)) < 0) {
1440 0 1 if (error < 0)
1443 2 1 git_vector_foreach(&backends, i, internal) {
1446 0 2 if (error != 0)
1463 0 171 GIT_ASSERT_ARG(oid);
1464 0 171 GIT_ASSERT_ARG(db);
1466 0 171 if ((error = git_odb_hash(oid, data, len, type)) < 0)
1469 0 171 if (git_oid_is_zero(oid))
1472 51 120 if (git_odb__freshen(db, oid))
1475 0 120 if ((error = git_mutex_lock(&db->lock)) < 0) {
1479 240 114 for (i = 0, error = GIT_ERROR; i < db->backends.length && error < 0; ++i) {
234 6 for (i = 0, error = GIT_ERROR; i < db->backends.length && error < 0; ++i) {
1484 0 234 if (internal->is_alternate)
1487 120 114 if (b->write != NULL)
1492 0 120 if (!error || error == GIT_PASSTHROUGH)
0 0 if (!error || error == GIT_PASSTHROUGH)
1499 0 0 if ((error = git_odb_open_wstream(&stream, db, len, type)) != 0)
1502 0 0 if ((error = stream->write(stream, data, len)) == 0)
1515 0 63 if ((error = git_odb__format_object_header(&hdrlen,
1529 0 63 GIT_ASSERT_ARG(stream);
1530 0 63 GIT_ASSERT_ARG(db);
1532 0 63 if ((error = git_mutex_lock(&db->lock)) < 0) {
1537 126 63 for (i = 0; i < db->backends.length && error < 0; ++i) {
126 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
1542 0 126 if (internal->is_alternate)
1545 63 63 if (b->writestream != NULL) {
1548 0 63 } else if (b->write != NULL) {
1555 0 63 if (error < 0) {
1556 0 0 if (error == GIT_PASSTHROUGH)
1558 0 0 else if (!writes)
1565 0 63 GIT_ERROR_CHECK_ALLOC(ctx);
1567 63 0 if ((error = git_hash_ctx_init(ctx, GIT_HASH_ALGORITHM_SHA1)) < 0 ||
63 0 if ((error = git_hash_ctx_init(ctx, GIT_HASH_ALGORITHM_SHA1)) < 0 ||
1576 0 63 if (error)
1600 0 62 if (stream->received_bytes > stream->declared_size)
1609 0 63 if (stream->received_bytes != stream->declared_size)
1615 20 43 if (git_odb__freshen(stream->backend->odb, out))
1628 0 63 if (stream == NULL)
1646 0 0 GIT_ASSERT_ARG(stream);
1647 0 0 GIT_ASSERT_ARG(db);
1649 0 0 if ((error = git_mutex_lock(&db->lock)) < 0) {
1654 0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
1658 0 0 if (b->readstream != NULL) {
1665 0 0 if (error == GIT_PASSTHROUGH)
1667 0 0 if (error < 0 && !reads)
0 0 if (error < 0 && !reads)
1678 0 0 GIT_ASSERT_ARG(out);
1679 0 0 GIT_ASSERT_ARG(db);
1681 0 0 if ((error = git_mutex_lock(&db->lock)) < 0) {
1686 0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
1691 0 0 if (internal->is_alternate)
1694 0 0 if (b->writepack != NULL) {
1701 0 0 if (error == GIT_PASSTHROUGH)
1703 0 0 if (error < 0 && !writes)
0 0 if (error < 0 && !writes)
1714 0 0 GIT_ASSERT_ARG(db);
1716 0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
1721 0 0 if (internal->is_alternate)
1724 0 0 if (b->writemidx != NULL) {
1730 0 0 if (error == GIT_PASSTHROUGH)
1732 0 0 if (error < 0 && !writes)
0 0 if (error < 0 && !writes)
1762 0 176 GIT_ASSERT_ARG(db);
1764 0 176 if ((error = git_mutex_lock(&db->lock)) < 0) {
1768 357 176 for (i = 0; i < db->backends.length; ++i) {
1772 176 181 if (b->refresh != NULL) {
1774 0 176 if (error < 0) {
1780 174 2 if (db->cgraph)
1803 1629 0 if (oid != NULL) {
1828 0 0 GIT_INIT_STRUCTURE_FROM_TEMPLATE(