Branch Coverage

deps/libgit2/src/tree.c
Criterion Covered Total %
branch 194 436 44.5


line true false branch
26 4 150 || filemode == GIT_FILEMODE_BLOB
27 2 2 || filemode == GIT_FILEMODE_BLOB_EXECUTABLE
28 1 1 || filemode == GIT_FILEMODE_LINK
29 154 44 || filemode == GIT_FILEMODE_COMMIT);
0 1 || filemode == GIT_FILEMODE_COMMIT);
35 161 348 if (GIT_MODE_TYPE(filemode) == GIT_FILEMODE_TREE)
39 3 345 if (GIT_PERMS_IS_EXEC(filemode))
43 0 345 if (GIT_MODE_TYPE(filemode) == GIT_FILEMODE_COMMIT)
47 3 342 if (GIT_MODE_TYPE(filemode) == GIT_FILEMODE_LINK)
86 0 246 TREE_ENTRY_CHECK_NAMELEN(filename_len);
88 0 246 if (GIT_ADD_SIZET_OVERFLOW(&tree_len, sizeof(git_tree_entry), filename_len) ||
94 0 246 if (!entry)
165 0 38 TREE_ENTRY_CHECK_NAMELEN(filename_len);
173 4 34 if (git_array_search(&homing,
179 34 0 for (i = homing; i < tree->entries.size; ++i) {
180 34 0 entry = git_array_get(tree->entries, i);
182 0 34 if (homing_search_cmp(&ksearch, entry) < 0)
185 34 0 if (entry->filename_len == filename_len &&
34 0 if (entry->filename_len == filename_len &&
187 34 0 if (at_pos)
196 0 0 if (homing > 0) {
200 0 0 entry = git_array_get(tree->entries, i);
202 0 0 if (homing_search_cmp(&ksearch, entry) > 0)
205 0 0 if (entry->filename_len == filename_len &&
0 0 if (entry->filename_len == filename_len &&
207 0 0 if (at_pos)
212 0 0 } while (i-- > 0);
221 2503 246 if (entry == NULL)
231 0 45 assert(source);
234 0 45 if (cpy == NULL)
264 0 166 assert(entry);
270 0 135 assert(entry);
276 0 43 assert(entry);
278 0 43 if (S_ISGITLINK(entry->attr))
280 9 34 else if (S_ISDIR(entry->attr))
291 39 0 assert(entry && object_out);
0 39 assert(entry && object_out);
300 4 34 if (tree_key_search(&idx, tree, name, name_len) < 0)
303 34 0 return git_array_get(tree->entries, idx);
309 2 0 assert(tree && filename);
0 2 assert(tree && filename);
317 0 561 assert(tree);
318 561 0 return git_array_get(tree->entries, idx);
327 0 0 assert(tree);
329 0 0 git_array_foreach(tree->entries, i, e) {
0 0 git_array_foreach(tree->entries, i, e) {
330 0 0 if (memcmp(&e->oid->id, &id->id, sizeof(id->id)) == 0)
339 0 214 assert(tree);
345 0 6 assert(bld);
352 3 0 if (path)
364 210 0 if (!buffer_len || git__isspace(*buffer))
0 210 if (!buffer_len || git__isspace(*buffer))
367 0 210 if ((error = git__strntol32(&mode, buffer, buffer_len, buffer_out, 8)) < 0)
370 210 0 if (mode < 0 || mode > UINT16_MAX)
0 210 if (mode < 0 || mode > UINT16_MAX)
389 0 101 GIT_ERROR_CHECK_ARRAY(tree->entries);
391 210 101 while (buffer < buffer_end) {
397 210 0 if (parse_mode(&attr, buffer, buffer_end - buffer, &buffer) < 0 || !buffer)
0 210 if (parse_mode(&attr, buffer, buffer_end - buffer, &buffer) < 0 || !buffer)
400 210 0 if (buffer >= buffer_end || (*buffer++) != ' ')
0 210 if (buffer >= buffer_end || (*buffer++) != ' ')
403 0 210 if ((nul = memchr(buffer, 0, buffer_end - buffer)) == NULL)
406 210 0 if ((filename_len = nul - buffer) == 0 || filename_len > UINT16_MAX)
0 210 if ((filename_len = nul - buffer) == 0 || filename_len > UINT16_MAX)
409 0 210 if ((buffer_end - (nul + 1)) < GIT_OID_RAWSZ)
414 0 210 entry = git_array_alloc(tree->entries);
210 0 entry = git_array_alloc(tree->entries);
415 0 210 GIT_ERROR_CHECK_ALLOC(entry);
434 0 101 if ((git_tree__parse_raw(tree,
439 0 101 if (git_odb_object_dup(&tree->odb_obj, odb_obj) < 0)
450 13 9 for (i = start; i < entries; ++i) {
452 13 0 if (strlen(entry->path) < dirlen ||
11 2 if (strlen(entry->path) < dirlen ||
453 11 0 memcmp(entry->path, dirname, dirlen) ||
454 11 0 (dirlen > 0 && entry->path[dirlen] != '/')) {
476 1 197 if (!valid_filemode(filemode))
479 1 196 if (!valid_entry_name(repo, filename))
482 0 196 if (git_oid_is_zero(id))
502 189 6 if (validate && ((error = check_entry(bld->repo, filename, id, filemode)) < 0))
0 189 if (validate && ((error = check_entry(bld->repo, filename, id, filemode)) < 0))
506 0 195 GIT_ERROR_CHECK_ALLOC(entry);
510 0 195 if ((error = git_strmap_set(bld->map, entry->filename, entry)) < 0) {
534 11 87 if (cache != NULL && cache->entry_count >= 0){
11 0 if (cache != NULL && cache->entry_count >= 0){
539 87 0 if ((error = git_treebuilder_new(&bld, repo, NULL)) < 0 || bld == NULL)
0 87 if ((error = git_treebuilder_new(&bld, repo, NULL)) < 0 || bld == NULL)
547 200 76 for (i = start; i < entries; ++i) {
559 194 6 if (strlen(entry->path) < dirname_len ||
189 5 if (strlen(entry->path) < dirname_len ||
560 35 154 memcmp(entry->path, dirname, dirname_len) ||
561 35 0 (dirname_len > 0 && entry->path[dirname_len] != '/')) {
566 35 154 if (*filename == '/')
569 43 146 if (next_slash) {
575 0 43 GIT_ERROR_CHECK_ALLOC(subdir);
579 0 43 if (written < 0) {
593 22 21 if (last_comp) {
601 0 43 if (error < 0)
605 0 146 if (error < 0)
610 0 87 if (git_treebuilder_write_with_buffer(oid, bld, shared_buf) < 0)
629 56 0 assert(oid && index && repo);
56 0 assert(oid && index && repo);
0 56 assert(oid && index && repo);
631 0 56 if (git_index_has_conflicts(index)) {
637 44 12 if (index->tree != NULL && index->tree->entry_count >= 0) {
1 43 if (index->tree != NULL && index->tree->entry_count >= 0) {
647 0 55 if (index->ignore_case) {
655 0 55 if (old_ignore_case)
660 0 55 if (ret < 0)
665 0 55 if ((ret = git_tree_lookup(&tree, repo, oid)) < 0)
683 94 0 assert(builder_p && repo);
0 94 assert(builder_p && repo);
686 0 94 GIT_ERROR_CHECK_ALLOC(bld);
690 0 94 if (git_strmap_new(&bld->map) < 0) {
695 4 90 if (source != NULL) {
698 6 4 git_array_foreach(source->entries, i, entry_src) {
6 0 git_array_foreach(source->entries, i, entry_src) {
699 0 6 if (append_entry(
726 9 0 assert(bld && id && filename);
9 0 assert(bld && id && filename);
0 9 assert(bld && id && filename);
728 2 7 if ((error = check_entry(bld->repo, filename, id, filemode)) < 0)
731 1 6 if ((entry = git_strmap_get(bld->map, filename)) != NULL) {
735 0 6 GIT_ERROR_CHECK_ALLOC(entry);
737 0 6 if ((error = git_strmap_set(bld->map, entry->filename, entry)) < 0) {
746 4 3 if (entry_out)
754 8 0 assert(bld && filename);
0 8 assert(bld && filename);
767 1 3 if (entry == NULL)
795 0 95 assert(bld);
796 0 95 assert(tree);
801 0 95 if ((error = git_vector_init(&entries, entrycount, entry_sort_cmp)) < 0)
804 63 32 if (tree->asize == 0 &&
0 63 if (tree->asize == 0 &&
808 0 200 git_strmap_foreach_value(bld->map, entry, {
200 95 git_strmap_foreach_value(bld->map, entry, {
815 200 95 for (i = 0; i < entries.length && !error; ++i) {
200 0 for (i = 0; i < entries.length && !error; ++i) {
822 0 200 if (git_buf_oom(tree)) {
828 95 0 if ((error = git_repository_odb__weakptr(&odb, bld->repo)) == 0)
845 0 0 assert(bld && filter);
0 0 assert(bld && filter);
847 0 0 git_strmap_foreach(bld->map, filename, entry, {
0 0 git_strmap_foreach(bld->map, filename, entry, {
861 0 95 assert(bld);
863 198 95 git_strmap_foreach_value(bld->map, e, git_tree_entry_free(e));
871 0 94 if (bld == NULL)
882 16 20 if (slash_pos == NULL)
902 0 36 if (filename_len == 0) {
909 3 33 if (entry == NULL) {
919 0 20 if (!git_tree_entry__is_tree(entry)) {
928 20 0 if (path[filename_len + 1] != '\0')
937 0 20 if (git_tree_lookup(&subtree, root->object.repo, entry->oid) < 0)
961 24 13 git_array_foreach(tree->entries, i, entry) {
24 0 git_array_foreach(tree->entries, i, entry) {
962 11 13 if (preorder) {
964 0 11 if (error < 0) { /* negative value stops iteration */
968 0 11 if (error > 0) { /* positive value skips this entry */
974 4 20 if (git_tree_entry__is_tree(entry)) {
979 0 4 if (error < 0)
986 0 4 if (git_buf_oom(path))
992 0 4 if (error != 0)
998 13 11 if (!preorder) {
1000 0 13 if (error < 0) { /* negative value stops iteration */
1020 4 5 if (mode != GIT_TREEWALK_POST && mode != GIT_TREEWALK_PRE) {
0 4 if (mode != GIT_TREEWALK_POST && mode != GIT_TREEWALK_PRE) {
1066 0 0 while ((slash = strchr(path, '/')) != NULL) {
1080 0 0 if (slash)
1094 0 0 if (git_treebuilder_entrycount(popped->bld) == 0) {
1104 0 0 if (error < 0) {
1114 0 0 GIT_ERROR_CHECK_ALLOC(component->ptr);
1117 0 0 if (current->tree) {
1120 0 0 if (to_replace && git_tree_entry_type(to_replace) != GIT_OBJECT_TREE) {
0 0 if (to_replace && git_tree_entry_type(to_replace) != GIT_OBJECT_TREE) {
1138 0 0 if ((error = git_vector_init(&entries, nupdates, compare_entries)) < 0)
1142 0 0 for (i = 0 ; i < nupdates; i++) {
1143 0 0 if ((error = git_vector_insert_sorted(&entries, (void *) &updates[i], on_dup_entry)) < 0)
1147 0 0 root_elem = git_array_alloc(stack);
0 0 root_elem = git_array_alloc(stack);
1148 0 0 GIT_ERROR_CHECK_ALLOC(root_elem);
1151 0 0 if (baseline && (error = git_tree_dup(&root_elem->tree, baseline)) < 0)
0 0 if (baseline && (error = git_tree_dup(&root_elem->tree, baseline)) < 0)
1154 0 0 if ((error = git_treebuilder_new(&root_elem->bld, repo, root_elem->tree)) < 0)
1157 0 0 for (i = 0; i < nupdates; i++) {
1158 0 0 const git_tree_update *last_update = i == 0 ? NULL : git_vector_get(&entries, i-1);
1164 0 0 if (last_update)
1173 0 0 steps_up = last_update == NULL ? 0 : count_slashes(&last_update->path[common_prefix]);
1175 0 0 for (j = 0; j < steps_up; j++) {
1176 0 0 tree_stack_entry *current, *popped = git_array_pop(stack);
1177 0 0 assert(popped);
1179 0 0 current = git_array_last(stack);
1180 0 0 assert(current);
1182 0 0 if ((error = create_popped_tree(current, popped, &component)) < 0)
1188 0 0 while (next_component(&component, path)) {
1192 0 0 last = git_array_last(stack);
1193 0 0 entry = last->tree ? git_tree_entry_byname(last->tree, component.ptr) : NULL;
1194 0 0 if (!entry)
1197 0 0 if (entry && git_tree_entry_type(entry) != GIT_OBJECT_TREE) {
0 0 if (entry && git_tree_entry_type(entry) != GIT_OBJECT_TREE) {
1203 0 0 new_entry = git_array_alloc(stack);
0 0 new_entry = git_array_alloc(stack);
1204 0 0 GIT_ERROR_CHECK_ALLOC(new_entry);
1208 0 0 if (entry && (error = git_tree_lookup(&new_entry->tree, repo, git_tree_entry_id(entry))) < 0)
0 0 if (entry && (error = git_tree_lookup(&new_entry->tree, repo, git_tree_entry_id(entry))) < 0)
1211 0 0 if ((error = git_treebuilder_new(&new_entry->bld, repo, new_entry->tree)) < 0)
1215 0 0 GIT_ERROR_CHECK_ALLOC(new_entry->name);
1226 0 0 tree_stack_entry *last = git_array_last(stack);
1229 0 0 if (e && git_tree_entry_type(e) != git_object__type_from_filemode(update->filemode)) {
0 0 if (e && git_tree_entry_type(e) != git_object__type_from_filemode(update->filemode)) {
1246 0 0 error = git_treebuilder_remove(git_array_last(stack)->bld, basename);
1256 0 0 if (error < 0)
1263 0 0 while ((popped = git_array_pop(stack)) != NULL) {
0 0 while ((popped = git_array_pop(stack)) != NULL) {
1264 0 0 current = git_array_last(stack);
1266 0 0 if (!current)
1269 0 0 if ((error = create_popped_tree(current, popped, &component)) < 0)
1279 0 0 if (error < 0)
1286 0 0 while ((e = git_array_pop(stack)) != NULL) {
0 0 while ((e = git_array_pop(stack)) != NULL) {