Branch Coverage

deps/libgit2/src/libgit2/tree.c
Criterion Covered Total %
branch 193 436 44.2


line true false branch
27 4 150 || filemode == GIT_FILEMODE_BLOB
28 2 2 || filemode == GIT_FILEMODE_BLOB_EXECUTABLE
29 1 1 || filemode == GIT_FILEMODE_LINK
30 154 44 || filemode == GIT_FILEMODE_COMMIT);
0 1 || filemode == GIT_FILEMODE_COMMIT);
36 161 348 if (GIT_MODE_TYPE(filemode) == GIT_FILEMODE_TREE)
40 3 345 if (GIT_PERMS_IS_EXEC(filemode))
44 0 345 if (GIT_MODE_TYPE(filemode) == GIT_FILEMODE_COMMIT)
48 3 342 if (GIT_MODE_TYPE(filemode) == GIT_FILEMODE_LINK)
88 0 246 TREE_ENTRY_CHECK_NAMELEN(filename_len);
90 0 246 if (GIT_ADD_SIZET_OVERFLOW(&tree_len, sizeof(git_tree_entry), filename_len) ||
96 0 246 if (!entry)
159 0 38 TREE_ENTRY_CHECK_NAMELEN(filename_len);
167 4 34 if (git_array_search(&homing,
173 34 0 for (i = homing; i < tree->entries.size; ++i) {
174 34 0 entry = git_array_get(tree->entries, i);
176 0 34 if (homing_search_cmp(&ksearch, entry) < 0)
179 34 0 if (entry->filename_len == filename_len &&
34 0 if (entry->filename_len == filename_len &&
181 34 0 if (at_pos)
190 0 0 if (homing > 0) {
194 0 0 entry = git_array_get(tree->entries, i);
196 0 0 if (homing_search_cmp(&ksearch, entry) > 0)
199 0 0 if (entry->filename_len == filename_len &&
0 0 if (entry->filename_len == filename_len &&
201 0 0 if (at_pos)
206 0 0 } while (i-- > 0);
215 2427 246 if (entry == NULL)
225 0 45 GIT_ASSERT_ARG(source);
228 0 45 if (cpy == NULL)
258 0 166 GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL);
264 0 135 GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL);
270 0 43 GIT_ASSERT_ARG_WITH_RETVAL(entry, GIT_OBJECT_INVALID);
272 0 43 if (S_ISGITLINK(entry->attr))
274 9 34 else if (S_ISDIR(entry->attr))
285 0 39 GIT_ASSERT_ARG(entry);
286 0 39 GIT_ASSERT_ARG(object_out);
296 4 34 if (tree_key_search(&idx, tree, name, name_len) < 0)
299 34 0 return git_array_get(tree->entries, idx);
305 0 2 GIT_ASSERT_ARG_WITH_RETVAL(tree, NULL);
306 0 2 GIT_ASSERT_ARG_WITH_RETVAL(filename, NULL);
314 0 561 GIT_ASSERT_ARG_WITH_RETVAL(tree, NULL);
315 561 0 return git_array_get(tree->entries, idx);
324 0 0 GIT_ASSERT_ARG_WITH_RETVAL(tree, NULL);
326 0 0 git_array_foreach(tree->entries, i, e) {
0 0 git_array_foreach(tree->entries, i, e) {
327 0 0 if (git_oid_equal(&e->oid, id))
336 0 214 GIT_ASSERT_ARG_WITH_RETVAL(tree, 0);
342 0 6 GIT_ASSERT_ARG_WITH_RETVAL(bld, 0);
349 3 0 if (path)
372 210 0 if (!buffer_len || git__isspace(*buffer))
0 210 if (!buffer_len || git__isspace(*buffer))
375 0 210 if ((error = git__strntol32(&mode, buffer, buffer_len, buffer_out, 8)) < 0)
378 210 0 if (mode < 0 || mode > UINT16_MAX)
0 210 if (mode < 0 || mode > UINT16_MAX)
397 0 101 GIT_ERROR_CHECK_ARRAY(tree->entries);
399 210 101 while (buffer < buffer_end) {
405 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)
408 210 0 if (buffer >= buffer_end || (*buffer++) != ' ')
0 210 if (buffer >= buffer_end || (*buffer++) != ' ')
411 0 210 if ((nul = memchr(buffer, 0, buffer_end - buffer)) == NULL)
414 210 0 if ((filename_len = nul - buffer) == 0 || filename_len > UINT16_MAX)
0 210 if ((filename_len = nul - buffer) == 0 || filename_len > UINT16_MAX)
417 0 210 if ((buffer_end - (nul + 1)) < GIT_OID_RAWSZ)
422 0 210 entry = git_array_alloc(tree->entries);
0 0 entry = git_array_alloc(tree->entries);
423 0 210 GIT_ERROR_CHECK_ALLOC(entry);
445 101 0 if ((error = git_tree__parse_raw(tree, data, size)) < 0 ||
0 101 if ((error = git_tree__parse_raw(tree, data, size)) < 0 ||
457 13 9 for (i = start; i < entries; ++i) {
459 13 0 if (strlen(entry->path) < dirlen ||
11 2 if (strlen(entry->path) < dirlen ||
460 11 0 memcmp(entry->path, dirname, dirlen) ||
461 11 0 (dirlen > 0 && entry->path[dirlen] != '/')) {
483 1 197 if (!valid_filemode(filemode))
486 1 196 if (!valid_entry_name(repo, filename))
489 0 196 if (git_oid_is_zero(id))
513 0 95 if ((error = git_vector_init(&entries, entrycount, entry_sort_cmp)) < 0)
516 62 33 if (buf->asize == 0 &&
0 62 if (buf->asize == 0 &&
520 0 200 git_strmap_foreach_value(bld->map, entry, {
200 95 git_strmap_foreach_value(bld->map, entry, {
527 200 95 for (i = 0; i < entries.length && !error; ++i) {
200 0 for (i = 0; i < entries.length && !error; ++i) {
534 0 200 if (git_str_oom(buf)) {
540 95 0 if ((error = git_repository_odb__weakptr(&odb, bld->repo)) == 0)
559 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))
563 0 195 GIT_ERROR_CHECK_ALLOC(entry);
567 0 195 if ((error = git_strmap_set(bld->map, entry->filename, entry)) < 0) {
591 11 87 if (cache != NULL && cache->entry_count >= 0){
11 0 if (cache != NULL && cache->entry_count >= 0){
596 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)
604 200 76 for (i = start; i < entries; ++i) {
616 194 6 if (strlen(entry->path) < dirname_len ||
189 5 if (strlen(entry->path) < dirname_len ||
617 35 154 memcmp(entry->path, dirname, dirname_len) ||
618 35 0 (dirname_len > 0 && entry->path[dirname_len] != '/')) {
623 35 154 if (*filename == '/')
626 43 146 if (next_slash) {
632 0 43 GIT_ERROR_CHECK_ALLOC(subdir);
636 0 43 if (written < 0) {
650 22 21 if (last_comp) {
658 0 43 if (error < 0)
662 0 146 if (error < 0)
667 0 87 if (git_treebuilder__write_with_buffer(oid, bld, shared_buf) < 0)
686 0 56 GIT_ASSERT_ARG(oid);
687 0 56 GIT_ASSERT_ARG(index);
688 0 56 GIT_ASSERT_ARG(repo);
690 0 56 if (git_index_has_conflicts(index)) {
696 44 12 if (index->tree != NULL && index->tree->entry_count >= 0) {
1 43 if (index->tree != NULL && index->tree->entry_count >= 0) {
706 0 55 if (index->ignore_case) {
714 0 55 if (old_ignore_case)
719 0 55 if (ret < 0)
724 0 55 if ((ret = git_tree_lookup(&tree, repo, oid)) < 0)
742 0 94 GIT_ASSERT_ARG(builder_p);
743 0 94 GIT_ASSERT_ARG(repo);
746 0 94 GIT_ERROR_CHECK_ALLOC(bld);
750 0 94 if (git_strmap_new(&bld->map) < 0) {
755 4 90 if (source != NULL) {
758 6 4 git_array_foreach(source->entries, i, entry_src) {
6 0 git_array_foreach(source->entries, i, entry_src) {
759 0 6 if (append_entry(
786 0 9 GIT_ASSERT_ARG(bld);
787 0 9 GIT_ASSERT_ARG(id);
788 0 9 GIT_ASSERT_ARG(filename);
790 2 7 if ((error = check_entry(bld->repo, filename, id, filemode)) < 0)
793 1 6 if ((entry = git_strmap_get(bld->map, filename)) != NULL) {
797 0 6 GIT_ERROR_CHECK_ALLOC(entry);
799 0 6 if ((error = git_strmap_set(bld->map, entry->filename, entry)) < 0) {
808 4 3 if (entry_out)
816 0 8 GIT_ASSERT_ARG_WITH_RETVAL(bld, NULL);
817 0 8 GIT_ASSERT_ARG_WITH_RETVAL(filename, NULL);
831 1 3 if (entry == NULL)
842 0 8 GIT_ASSERT_ARG(oid);
843 0 8 GIT_ASSERT_ARG(bld);
856 0 0 GIT_ASSERT_ARG(bld);
857 0 0 GIT_ASSERT_ARG(filter);
859 0 0 git_strmap_foreach(bld->map, filename, entry, {
0 0 git_strmap_foreach(bld->map, filename, entry, {
873 0 95 GIT_ASSERT_ARG(bld);
875 198 95 git_strmap_foreach_value(bld->map, e, git_tree_entry_free(e));
883 0 94 if (bld == NULL)
895 16 20 if (slash_pos == NULL)
915 0 36 if (filename_len == 0) {
922 3 33 if (entry == NULL) {
932 0 20 if (!git_tree_entry__is_tree(entry)) {
941 20 0 if (path[filename_len + 1] != '\0')
950 0 20 if (git_tree_lookup(&subtree, root->object.repo, &entry->oid) < 0)
974 24 13 git_array_foreach(tree->entries, i, entry) {
24 0 git_array_foreach(tree->entries, i, entry) {
975 11 13 if (preorder) {
977 0 11 if (error < 0) { /* negative value stops iteration */
981 0 11 if (error > 0) { /* positive value skips this entry */
987 4 20 if (git_tree_entry__is_tree(entry)) {
992 0 4 if (error < 0)
999 0 4 if (git_str_oom(path))
1005 0 4 if (error != 0)
1011 13 11 if (!preorder) {
1013 0 13 if (error < 0) { /* negative value stops iteration */
1033 4 5 if (mode != GIT_TREEWALK_POST && mode != GIT_TREEWALK_PRE) {
0 4 if (mode != GIT_TREEWALK_POST && mode != GIT_TREEWALK_PRE) {
1079 0 0 while ((slash = strchr(path, '/')) != NULL) {
1093 0 0 if (slash)
1107 0 0 if (git_treebuilder_entrycount(popped->bld) == 0) {
1117 0 0 if (error < 0) {
1127 0 0 GIT_ERROR_CHECK_ALLOC(component->ptr);
1130 0 0 if (current->tree) {
1133 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) {
1151 0 0 if ((error = git_vector_init(&entries, nupdates, compare_entries)) < 0)
1155 0 0 for (i = 0 ; i < nupdates; i++) {
1156 0 0 if ((error = git_vector_insert_sorted(&entries, (void *) &updates[i], on_dup_entry)) < 0)
1160 0 0 root_elem = git_array_alloc(stack);
0 0 root_elem = git_array_alloc(stack);
1161 0 0 GIT_ERROR_CHECK_ALLOC(root_elem);
1164 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)
1167 0 0 if ((error = git_treebuilder_new(&root_elem->bld, repo, root_elem->tree)) < 0)
1170 0 0 for (i = 0; i < nupdates; i++) {
1171 0 0 const git_tree_update *last_update = i == 0 ? NULL : git_vector_get(&entries, i-1);
1177 0 0 if (last_update)
1186 0 0 steps_up = last_update == NULL ? 0 : count_slashes(&last_update->path[common_prefix]);
1188 0 0 for (j = 0; j < steps_up; j++) {
1189 0 0 tree_stack_entry *current, *popped = git_array_pop(stack);
1190 0 0 GIT_ASSERT(popped);
1192 0 0 current = git_array_last(stack);
1193 0 0 GIT_ASSERT(current);
1195 0 0 if ((error = create_popped_tree(current, popped, &component)) < 0)
1201 0 0 while (next_component(&component, path)) {
1205 0 0 last = git_array_last(stack);
1206 0 0 entry = last->tree ? git_tree_entry_byname(last->tree, component.ptr) : NULL;
1207 0 0 if (!entry)
1210 0 0 if (entry && git_tree_entry_type(entry) != GIT_OBJECT_TREE) {
0 0 if (entry && git_tree_entry_type(entry) != GIT_OBJECT_TREE) {
1216 0 0 new_entry = git_array_alloc(stack);
0 0 new_entry = git_array_alloc(stack);
1217 0 0 GIT_ERROR_CHECK_ALLOC(new_entry);
1221 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)
1224 0 0 if ((error = git_treebuilder_new(&new_entry->bld, repo, new_entry->tree)) < 0)
1228 0 0 GIT_ERROR_CHECK_ALLOC(new_entry->name);
1239 0 0 tree_stack_entry *last = git_array_last(stack);
1242 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)) {
1258 0 0 tree_stack_entry *last = git_array_last(stack);
1270 0 0 if (error < 0)
1277 0 0 while ((popped = git_array_pop(stack)) != NULL) {
0 0 while ((popped = git_array_pop(stack)) != NULL) {
1278 0 0 current = git_array_last(stack);
1280 0 0 if (!current)
1283 0 0 if ((error = create_popped_tree(current, popped, &component)) < 0)
1293 0 0 if (error < 0)
1300 0 0 while ((e = git_array_pop(stack)) != NULL) {
0 0 while ((e = git_array_pop(stack)) != NULL) {