Branch Coverage

deps/libgit2/src/odb.c
Criterion Covered Total %
branch 217 538 40.3


line true false branch
47 1925 0 if (odb->rc.owner != NULL) {
64 1 1031 if (!git_oid_cmp(id, &empty_tree))
76 635 1 if ((type = odb_hardcoded_type(id)) == GIT_OBJECT_INVALID)
82 0 1 GIT_ERROR_CHECK_ALLOC(raw->data);
96 1350 0 int hdr_max = (hdr_size > INT_MAX-2) ? (INT_MAX-2) : (int)hdr_size;
101 1350 0 if (len < 0 || len >= hdr_max) {
0 1350 if (len < 0 || len >= hdr_max) {
117 970 0 assert(id && obj);
0 970 assert(id && obj);
119 0 970 if (!git_object_typeisloose(obj->type)) {
124 0 970 if (!obj->data && obj->len != 0) {
0 0 if (!obj->data && obj->len != 0) {
129 0 970 if ((error = git_odb__format_object_header(&hdrlen,
146 764 0 if (object != NULL) {
158 762 0 if (object != NULL) {
193 3 1049 if (object == NULL)
207 0 97 if (!git_object_typeisloose(type)) {
212 0 97 if ((error = git_hash_ctx_init(&ctx)) < 0)
215 0 97 if ((error = git_odb__format_object_header(&hdr_len, hdr,
219 0 97 if ((error = git_hash_update(&ctx, hdr, hdr_len)) < 0)
222 86 97 while (size > 0 && (read_len = p_read(fd, buffer, sizeof(buffer))) > 0) {
86 0 while (size > 0 && (read_len = p_read(fd, buffer, sizeof(buffer))) > 0) {
223 0 86 if ((error = git_hash_update(&ctx, buffer, read_len)) < 0)
232 97 0 if (read_len < 0 || size > 0) {
0 97 if (read_len < 0 || size > 0) {
252 97 27 if (!fl)
259 27 0 if (!(error = git_futils_readbuffer_fd(&raw, fd, size))) {
266 27 0 if (!error)
281 0 0 if (git_path_lstat(path, &st) < 0)
284 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) {
291 0 0 if (S_ISLNK(st.st_mode)) {
296 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, size, 1);
298 0 0 GIT_ERROR_CHECK_ALLOC(link_data);
302 0 0 if (read_len != size) {
312 0 0 if (fd < 0)
326 0 0 if ((fd = git_futils_open_ro(path)) < 0)
329 0 0 if ((error = git_futils_filesize(&size, fd)) < 0)
332 0 0 if (!git__is_sizet(size)) {
349 0 968 assert(id);
379 0 0 assert(stream->written + len <= stream->size);
399 0 0 GIT_ERROR_CHECK_BLOBSIZE(size);
403 0 0 GIT_ERROR_CHECK_ALLOC(stream);
408 0 0 if (stream->buffer == NULL) {
437 1 78 if (backend_b->priority == backend_a->priority) {
438 0 1 if (backend_a->is_alternate)
440 1 0 if (backend_b->is_alternate)
450 0 36 GIT_ERROR_CHECK_ALLOC(db);
452 0 36 if (git_cache_init(&db->own_cache) < 0) {
456 0 36 if (git_vector_init(&db->backends, 4, backend_sort_cmp) < 0) {
473 74 0 assert(odb && backend);
0 74 assert(odb && backend);
475 0 74 GIT_ERROR_CHECK_VERSION(backend, GIT_ODB_BACKEND_VERSION, "git_odb_backend");
478 0 74 assert(!backend->odb || backend->odb == odb);
0 0 assert(!backend->odb || backend->odb == odb);
481 0 74 GIT_ERROR_CHECK_ALLOC(internal);
488 0 74 if (git_vector_insert(&odb->backends, internal) < 0) {
510 0 7 assert(odb);
526 0 0 assert(out && odb);
0 0 assert(out && odb);
529 0 0 if (internal && internal->backend) {
0 0 if (internal && internal->backend) {
555 0 35 if (p_stat(objects_dir, &st) < 0) {
556 0 0 if (as_alternates)
566 0 35 for (i = 0; i < db->backends.length; ++i) {
568 0 0 if (backend->disk_inode == inode)
595 0 35 if (alternate_depth > GIT_ALTERNATES_MAX_DEPTH)
598 0 35 if (git_buf_joinpath(&alternates_path, objects_dir, GIT_ALTERNATES_FILE) < 0)
601 35 0 if (git_path_exists(alternates_path.ptr) == false) {
606 0 0 if (git_futils_readbuffer(&alternates_buf, alternates_path.ptr) < 0) {
614 0 0 while ((alternate = git__strtok(&buffer, "\r\n")) != NULL) {
615 0 0 if (*alternate == '\0' || *alternate == '#')
0 0 if (*alternate == '\0' || *alternate == '#')
623 0 0 if (*alternate == '.' && !alternate_depth) {
0 0 if (*alternate == '.' && !alternate_depth) {
624 0 0 if ((result = git_buf_joinpath(&alternates_path, objects_dir, alternate)) < 0)
629 0 0 if ((result = git_odb__add_default_backends(odb, alternate, true, alternate_depth + 1)) < 0)
648 2 0 assert(out && objects_dir);
0 2 assert(out && objects_dir);
652 0 2 if (git_odb_new(&db) < 0)
655 0 2 if (git_odb__add_default_backends(db, objects_dir, 0, 0) < 0) {
666 33 0 if (caps == GIT_ODB_CAP_FROM_OWNER) {
670 0 33 if (!repo) {
675 33 0 if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_FSYNCOBJECTFILES))
686 74 36 for (i = 0; i < db->backends.length; ++i) {
704 10 201 if (db == NULL)
707 36 165 GIT_REFCOUNT_DEC(db, odb_free);
36 0 GIT_REFCOUNT_DEC(db, odb_free);
718 8 4 for (i = 0; i < db->backends.length && !found; ++i) {
8 0 for (i = 0; i < db->backends.length && !found; ++i) {
722 0 8 if (only_refreshed && !b->refresh)
0 0 if (only_refreshed && !b->refresh)
725 8 0 if (b->exists != NULL)
740 914 449 for (i = 0; i < db->backends.length && !found; ++i) {
912 2 for (i = 0; i < db->backends.length && !found; ++i) {
744 332 580 if (only_refreshed && !b->refresh)
169 163 if (only_refreshed && !b->refresh)
747 735 8 if (b->freshen != NULL)
749 8 0 else if (b->exists != NULL)
758 288 0 assert(db && id);
0 288 assert(db && id);
760 125 163 if (odb_freshen_1(db, id, false))
763 163 0 if (!git_odb_refresh(db))
774 4 0 assert(db && id);
0 4 assert(db && id);
776 0 4 if (git_oid_is_zero(id))
779 0 4 if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
784 4 0 if (odb_exists_1(db, id, false))
787 0 0 if (!git_odb_refresh(db))
801 0 0 for (i = 0; i < db->backends.length; ++i) {
805 0 0 if (only_refreshed && !b->refresh)
0 0 if (only_refreshed && !b->refresh)
808 0 0 if (!b->exists_prefix)
812 0 0 if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH)
0 0 if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH)
814 0 0 if (error)
818 0 0 if (num_found) {
819 0 0 if (git_oid__cmp(&last_found, &found))
827 0 0 if (!num_found)
830 0 0 if (out)
842 0 0 assert(db && short_id);
0 0 assert(db && short_id);
844 0 0 if (len < GIT_OID_MINPREFIXLEN)
847 0 0 if (len >= GIT_OID_HEXSZ) {
848 0 0 if (git_odb_exists(db, short_id)) {
849 0 0 if (out)
862 0 0 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
0 0 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
865 0 0 if (error == GIT_ENOTFOUND)
878 0 0 assert(db && ids);
0 0 assert(db && ids);
880 0 0 for (i = 0; i < count; i++) {
884 0 0 if (!query->type)
888 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) {
892 0 0 if (!error) {
902 0 0 if (query->length >= GIT_OID_HEXSZ) {
906 0 0 if (!error) {
907 0 0 if (query->type != GIT_OBJECT_ANY && query->type != actual_type)
0 0 if (query->type != GIT_OBJECT_ANY && query->type != actual_type)
944 3 379 if (object)
959 396 0 if (!only_refreshed && (ht = odb_hardcoded_type(id)) != GIT_OBJECT_INVALID) {
0 396 if (!only_refreshed && (ht = odb_hardcoded_type(id)) != GIT_OBJECT_INVALID) {
965 787 0 for (i = 0; i < db->backends.length; ++i) {
969 0 787 if (only_refreshed && !b->refresh)
0 0 if (only_refreshed && !b->refresh)
972 0 787 if (!b->read_header) {
990 0 0 return passthrough ? GIT_PASSTHROUGH : GIT_ENOTFOUND;
1000 399 0 assert(db && id && out && len_p && type_p);
399 0 assert(db && id && out && len_p && type_p);
399 0 assert(db && id && out && len_p && type_p);
399 0 assert(db && id && out && len_p && type_p);
0 399 assert(db && id && out && len_p && type_p);
1004 0 399 if (git_oid_is_zero(id))
1007 3 396 if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
1016 0 396 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
0 0 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
1019 0 396 if (error == GIT_ENOTFOUND)
1023 396 0 if (!error)
1026 0 0 if (error == GIT_PASSTHROUGH) {
1032 0 0 if (!error) {
1052 636 2 if (!only_refreshed) {
1053 0 636 if ((error = odb_read_hardcoded(&found, &raw, id)) < 0)
1057 1281 619 for (i = 0; i < db->backends.length && !found; ++i) {
1262 19 for (i = 0; i < db->backends.length && !found; ++i) {
1061 4 1258 if (only_refreshed && !b->refresh)
2 2 if (only_refreshed && !b->refresh)
1064 1260 0 if (b->read != NULL) {
1066 1260 0 if (error == GIT_PASSTHROUGH || error == GIT_ENOTFOUND)
627 633 if (error == GIT_PASSTHROUGH || error == GIT_ENOTFOUND)
1069 0 633 if (error < 0)
1076 4 634 if (!found)
1079 634 0 if (git_odb__strict_hash_verification) {
1080 0 634 if ((error = git_odb_hash(&hashed, raw.data, raw.len, raw.type)) < 0)
1083 0 634 if (!git_oid_equal(id, &hashed)) {
1090 0 634 if ((object = odb_object__alloc(id, &raw)) == NULL) {
1098 0 634 if (error)
1107 636 0 assert(out && db && id);
636 0 assert(out && db && id);
0 636 assert(out && db && id);
1109 0 636 if (git_oid_is_zero(id))
1113 0 636 if (*out != NULL)
1118 2 634 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
2 0 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
1121 2 634 if (error == GIT_ENOTFOUND)
1133 0 0 if (git_oid_is_zero(id))
1136 0 0 if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
1144 0 0 if (error == GIT_PASSTHROUGH) {
1146 0 0 if (!error)
1165 292 146 for (i = 0; i < db->backends.length; ++i) {
1169 16 276 if (only_refreshed && !b->refresh)
8 8 if (only_refreshed && !b->refresh)
1172 284 0 if (b->read_prefix != NULL) {
1176 130 154 if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH) {
0 130 if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH) {
1181 0 130 if (error)
1187 0 130 if (found && git_oid__cmp(&full_oid, &found_full_oid)) {
0 0 if (found && git_oid__cmp(&full_oid, &found_full_oid)) {
1205 16 130 if (!found)
1208 130 0 if (git_odb__strict_hash_verification) {
1211 0 130 if ((error = git_odb_hash(&hash, raw.data, raw.len, raw.type)) < 0)
1214 0 130 if (!git_oid_equal(&found_full_oid, &hash)) {
1220 0 130 if ((object = odb_object__alloc(&found_full_oid, &raw)) == NULL) {
1228 0 130 if (error)
1240 138 0 assert(out && db);
0 138 assert(out && db);
1242 0 138 if (len < GIT_OID_MINPREFIXLEN)
1245 0 138 if (len > GIT_OID_HEXSZ)
1248 122 16 if (len == GIT_OID_HEXSZ) {
1250 0 122 if (*out != NULL)
1258 8 130 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
8 0 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
1261 8 130 if (error == GIT_ENOTFOUND)
1272 2 1 git_vector_foreach(&db->backends, i, internal) {
1275 0 2 if (error != 0)
1289 171 0 assert(oid && db);
0 171 assert(oid && db);
1293 0 171 if (git_oid_is_zero(oid))
1296 51 120 if (git_odb__freshen(db, oid))
1299 240 114 for (i = 0; i < db->backends.length && error < 0; ++i) {
234 6 for (i = 0; i < db->backends.length && error < 0; ++i) {
1304 0 234 if (internal->is_alternate)
1307 120 114 if (b->write != NULL)
1311 0 120 if (!error || error == GIT_PASSTHROUGH)
0 0 if (!error || error == GIT_PASSTHROUGH)
1318 0 0 if ((error = git_odb_open_wstream(&stream, db, len, type)) != 0)
1334 0 63 if ((error = git_odb__format_object_header(&hdrlen,
1348 63 0 assert(stream && db);
0 63 assert(stream && db);
1350 126 63 for (i = 0; i < db->backends.length && error < 0; ++i) {
126 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
1355 0 126 if (internal->is_alternate)
1358 63 63 if (b->writestream != NULL) {
1361 0 63 } else if (b->write != NULL) {
1367 0 63 if (error < 0) {
1368 0 0 if (error == GIT_PASSTHROUGH)
1370 0 0 else if (!writes)
1377 0 63 GIT_ERROR_CHECK_ALLOC(ctx);
1379 63 0 if ((error = git_hash_ctx_init(ctx)) < 0 ||
63 0 if ((error = git_hash_ctx_init(ctx)) < 0 ||
1388 0 63 if (error)
1412 0 62 if (stream->received_bytes > stream->declared_size)
1421 0 63 if (stream->received_bytes != stream->declared_size)
1427 20 43 if (git_odb__freshen(stream->backend->odb, out))
1440 0 63 if (stream == NULL)
1458 0 0 assert(stream && db);
0 0 assert(stream && db);
1460 0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
1464 0 0 if (b->readstream != NULL) {
1470 0 0 if (error == GIT_PASSTHROUGH)
1472 0 0 if (error < 0 && !reads)
0 0 if (error < 0 && !reads)
1483 0 0 assert(out && db);
0 0 assert(out && db);
1485 0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
1490 0 0 if (internal->is_alternate)
1493 0 0 if (b->writepack != NULL) {
1499 0 0 if (error == GIT_PASSTHROUGH)
1501 0 0 if (error < 0 && !writes)
0 0 if (error < 0 && !writes)
1527 0 175 assert(db);
1529 355 175 for (i = 0; i < db->backends.length; ++i) {
1533 175 180 if (b->refresh != NULL) {
1535 0 175 if (error < 0)
1559 1622 0 if (oid != NULL) {
1584 0 0 GIT_INIT_STRUCTURE_FROM_TEMPLATE(