Branch Coverage

deps/libgit2/src/odb.c
Criterion Covered Total %
branch 218 540 40.3


line true false branch
47 1950 0 if (odb->rc.owner != NULL) {
64 1 1044 if (!git_oid_cmp(id, &empty_tree))
76 648 1 if ((type = odb_hardcoded_type(id)) == GIT_OBJECT_INVALID)
82 0 1 GIT_ERROR_CHECK_ALLOC(raw->data);
96 1403 0 int hdr_max = (hdr_size > INT_MAX-2) ? (INT_MAX-2) : (int)hdr_size;
101 1403 0 if (len < 0 || len >= hdr_max) {
0 1403 if (len < 0 || len >= hdr_max) {
117 994 0 assert(id && obj);
0 994 assert(id && obj);
119 0 994 if (!git_object_typeisloose(obj->type)) {
124 0 994 if (!obj->data && obj->len != 0) {
0 0 if (!obj->data && obj->len != 0) {
129 0 994 if ((error = git_odb__format_object_header(&hdrlen,
146 776 0 if (object != NULL) {
158 774 0 if (object != NULL) {
193 3 1073 if (object == NULL)
207 0 126 if (!git_object_typeisloose(type)) {
212 0 126 if ((error = git_hash_ctx_init(&ctx)) < 0)
215 0 126 if ((error = git_odb__format_object_header(&hdr_len, hdr,
219 0 126 if ((error = git_hash_update(&ctx, hdr, hdr_len)) < 0)
222 109 126 while (size > 0 && (read_len = p_read(fd, buffer, sizeof(buffer))) > 0) {
109 0 while (size > 0 && (read_len = p_read(fd, buffer, sizeof(buffer))) > 0) {
223 0 109 if ((error = git_hash_update(&ctx, buffer, read_len)) < 0)
232 126 0 if (read_len < 0 || size > 0) {
0 126 if (read_len < 0 || size > 0) {
252 126 39 if (!fl)
259 39 0 if (!(error = git_futils_readbuffer_fd(&raw, fd, size))) {
266 39 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 992 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 202 if (db == NULL)
707 36 166 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 649 3 if (!only_refreshed) {
1053 0 649 if ((error = odb_read_hardcoded(&found, &raw, id)) < 0)
1057 1309 633 for (i = 0; i < db->backends.length && !found; ++i) {
1290 19 for (i = 0; i < db->backends.length && !found; ++i) {
1061 6 1284 if (only_refreshed && !b->refresh)
3 3 if (only_refreshed && !b->refresh)
1064 1287 0 if (b->read != NULL) {
1066 1287 0 if (error == GIT_PASSTHROUGH || error == GIT_ENOTFOUND)
642 645 if (error == GIT_PASSTHROUGH || error == GIT_ENOTFOUND)
1069 0 645 if (error < 0)
1076 6 646 if (!found)
1079 646 0 if (git_odb__strict_hash_verification) {
1080 0 646 if ((error = git_odb_hash(&hashed, raw.data, raw.len, raw.type)) < 0)
1083 0 646 if (!git_oid_equal(id, &hashed)) {
1090 0 646 if ((object = odb_object__alloc(id, &raw)) == NULL) {
1098 0 646 if (error)
1107 649 0 assert(out && db && id);
649 0 assert(out && db && id);
0 649 assert(out && db && id);
1109 0 649 if (git_oid_is_zero(id))
1113 0 649 if (*out != NULL)
1118 3 646 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
3 0 if (error == GIT_ENOTFOUND && !git_odb_refresh(db))
1121 3 646 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);
1291 0 171 if ((error = git_odb_hash(oid, data, len, type)) < 0)
1294 0 171 if (git_oid_is_zero(oid))
1297 51 120 if (git_odb__freshen(db, oid))
1300 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) {
1305 0 234 if (internal->is_alternate)
1308 120 114 if (b->write != NULL)
1312 0 120 if (!error || error == GIT_PASSTHROUGH)
0 0 if (!error || error == GIT_PASSTHROUGH)
1319 0 0 if ((error = git_odb_open_wstream(&stream, db, len, type)) != 0)
1335 0 63 if ((error = git_odb__format_object_header(&hdrlen,
1349 63 0 assert(stream && db);
0 63 assert(stream && db);
1351 126 63 for (i = 0; i < db->backends.length && error < 0; ++i) {
126 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
1356 0 126 if (internal->is_alternate)
1359 63 63 if (b->writestream != NULL) {
1362 0 63 } else if (b->write != NULL) {
1368 0 63 if (error < 0) {
1369 0 0 if (error == GIT_PASSTHROUGH)
1371 0 0 else if (!writes)
1378 0 63 GIT_ERROR_CHECK_ALLOC(ctx);
1380 63 0 if ((error = git_hash_ctx_init(ctx)) < 0 ||
63 0 if ((error = git_hash_ctx_init(ctx)) < 0 ||
1389 0 63 if (error)
1413 0 62 if (stream->received_bytes > stream->declared_size)
1422 0 63 if (stream->received_bytes != stream->declared_size)
1428 20 43 if (git_odb__freshen(stream->backend->odb, out))
1441 0 63 if (stream == NULL)
1459 0 0 assert(stream && db);
0 0 assert(stream && db);
1461 0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
1465 0 0 if (b->readstream != NULL) {
1471 0 0 if (error == GIT_PASSTHROUGH)
1473 0 0 if (error < 0 && !reads)
0 0 if (error < 0 && !reads)
1484 0 0 assert(out && db);
0 0 assert(out && db);
1486 0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
0 0 for (i = 0; i < db->backends.length && error < 0; ++i) {
1491 0 0 if (internal->is_alternate)
1494 0 0 if (b->writepack != NULL) {
1500 0 0 if (error == GIT_PASSTHROUGH)
1502 0 0 if (error < 0 && !writes)
0 0 if (error < 0 && !writes)
1530 0 176 assert(db);
1532 357 176 for (i = 0; i < db->backends.length; ++i) {
1536 176 181 if (b->refresh != NULL) {
1538 0 176 if (error < 0)
1562 1638 0 if (oid != NULL) {
1587 0 0 GIT_INIT_STRUCTURE_FROM_TEMPLATE(