Branch Coverage

deps/libgit2/src/iterator.c
Criterion Covered Total %
branch 424 718 59.0


line true false branch
31 3 750 if (ignore_case)
36 3 750 iter->strcomp = ignore_case ? git__strcasecmp : git__strcmp;
37 3 750 iter->strncomp = ignore_case ? git__strncasecmp : git__strncmp;
38 3 750 iter->prefixcomp = ignore_case ? git__prefixcmp_icase : git__prefixcmp;
39 3 750 iter->entry_srch = ignore_case ? git_index_entry_isrch : git_index_entry_srch;
47 33 784 if (start && *start) {
33 0 if (start && *start) {
49 0 33 GIT_ERROR_CHECK_ALLOC(iter->start);
54 33 784 if (end && *end) {
33 0 if (end && *end) {
56 0 33 GIT_ERROR_CHECK_ALLOC(iter->end);
69 0 64 if (iter->start) {
75 0 64 if (iter->end) {
93 0 753 if (git_vector_init(&iter->pathlist, pathlist->count, NULL) < 0)
96 98 753 for (i = 0; i < pathlist->count; i++) {
97 0 98 if (!pathlist->strings[i])
100 0 98 if (git_vector_insert(&iter->pathlist, pathlist->strings[i]) < 0)
114 736 17 git_iterator_options *options = given_opts ? given_opts : &default_opts;
123 3 750 if ((iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0) {
125 421 329 } else if ((iter->flags & GIT_ITERATOR_DONT_IGNORE_CASE) != 0) {
127 297 32 } else if (repo) {
130 0 297 if ((error = git_repository_index__weakptr(&index, iter->repo)) < 0)
135 0 297 if (ignore_case == 1)
144 719 34 if (repo &&
719 0 if (repo &&
145 719 0 (iter->flags & GIT_ITERATOR_PRECOMPOSE_UNICODE) == 0 &&
148 0 719 if (git_repository__configmap_lookup(&precompose, repo, GIT_CONFIGMAP_PRECOMPOSE) < 0)
150 0 719 else if (precompose)
154 171 582 if ((iter->flags & GIT_ITERATOR_DONT_AUTOEXPAND))
157 753 0 if ((error = iterator_range_init(iter, options->start, options->end)) < 0 ||
0 753 if ((error = iterator_range_init(iter, options->start, options->end)) < 0 ||
179 26 1454 if (iter->start == NULL || iter->started == true)
14 12 if (iter->start == NULL || iter->started == true)
187 12 0 if (iter->started)
196 0 0 if (is_submodule && iter->start_len && path_len == iter->start_len - 1 &&
0 0 if (is_submodule && iter->start_len && path_len == iter->start_len - 1 &&
0 0 if (is_submodule && iter->start_len && path_len == iter->start_len - 1 &&
0 0 if (is_submodule && iter->start_len && path_len == iter->start_len - 1 &&
204 0 0 if (path_len > 0 && path[path_len-1] == '/' &&
213 1454 26 if (iter->end == NULL)
215 0 26 else if (iter->ended)
231 1339 135 if (iter->pathlist.length == 0)
239 135 0 if (path_len && path[path_len-1] == '/')
6 129 if (path_len && path[path_len-1] == '/')
242 115 81 for (i = iter->pathlist_walk_idx; i < iter->pathlist.length; i++) {
246 115 0 if (p_len && p[p_len-1] == '/')
0 115 if (p_len && p[p_len-1] == '/')
257 80 35 if (cmp == 0) {
263 74 6 if (p[cmp_len] == '\0' &&
24 50 if (p[cmp_len] == '\0' &&
264 0 24 (path[cmp_len] == '\0' || path[cmp_len] == '/'))
271 0 30 if (p[cmp_len] == '/' && path[cmp_len] == '/')
0 0 if (p[cmp_len] == '/' && path[cmp_len] == '/')
276 31 4 else if (cmp < 0) {
282 4 0 else if (cmp > 0) {
305 0 145 if (iter->pathlist.length == 0)
317 38 107 if (error == 0) {
318 38 0 if (path_len && path[path_len-1] == '/')
0 38 if (path_len && path[path_len-1] == '/')
328 64 43 while ((p = git_vector_get(&iter->pathlist, idx)) != NULL) {
329 47 17 if (iter->prefixcomp(p, path) != 0)
333 0 17 assert(p[path_len]);
336 8 9 if (p[path_len] == '/') {
337 0 8 return (p[path_len+1] == '\0') ?
342 9 0 if (p[path_len] > '/')
357 17 0 if (e)
406 0 17 GIT_ERROR_CHECK_ALLOC(iter);
463 260 0 &iter->frames.ptr[iter->frames.size-2] : NULL;
469 1691 278 return iter->frames.size ? &iter->frames.ptr[iter->frames.size-1] : NULL;
475 8 0 return git_path_cmp(
501 0 4 if (!c && a->parent_path != b->parent_path)
0 0 if (!c && a->parent_path != b->parent_path)
504 0 4 if (!c)
516 455 698 if (entry->parent_path)
521 526 627 if (git_tree_entry__is_tree(entry->tree_entry))
524 0 1153 if (git_buf_oom(out))
543 324 260 new_frame = git_array_alloc(iter->frames);
260 0 new_frame = git_array_alloc(iter->frames);
544 0 584 GIT_ERROR_CHECK_ALLOC(new_frame);
546 0 584 if ((error = git_tree_dup(&dup, tree)) < 0)
552 260 324 if (frame_entry &&
0 260 if (frame_entry &&
557 8 576 tree_iterator_entry_sort_icase : NULL;
559 0 584 if ((error = git_vector_init(&new_frame->entries,
563 986 584 git_array_foreach(dup->entries, i, tree_entry) {
986 0 git_array_foreach(dup->entries, i, tree_entry) {
564 0 986 if ((new_entry = git_pool_malloc(&iter->entry_pool, 1)) == NULL) {
573 0 986 if ((error = git_vector_insert(&new_frame->entries, new_entry)) < 0)
577 576 8 git_vector_set_sorted(&new_frame->entries,
581 0 584 if (error < 0) {
583 0 0 git_array_pop(iter->frames);
608 0 4 while (parent_frame->next_idx < parent_frame->entries.length) {
611 0 0 if (strcasecmp(filename, entry->tree_entry->filename) != 0)
614 0 0 if ((error = git_tree_lookup(&tree,
618 0 0 if (git_vector_insert(&parent_frame->similar_trees, tree) < 0)
621 0 0 path = git_array_alloc(parent_frame->similar_paths);
0 0 path = git_array_alloc(parent_frame->similar_paths);
622 0 0 GIT_ERROR_CHECK_ALLOC(path);
626 0 0 if ((error = tree_iterator_compute_path(path, entry)) < 0)
629 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size,
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&new_size,
633 0 0 git_array_foreach(tree->entries, i, tree_entry) {
0 0 git_array_foreach(tree->entries, i, tree_entry) {
635 0 0 GIT_ERROR_CHECK_ALLOC(new_entry);
640 0 0 if ((error = git_vector_insert(&frame->entries, new_entry)) < 0)
644 0 0 if (error)
660 260 0 if ((error = git_tree_lookup(&tree,
661 260 0 iter->base.repo, entry->tree_entry->oid)) < 0 ||
672 4 256 if (iterator__ignore_case(&iter->base))
688 0 584 assert(iter->frames.size);
690 584 0 frame = git_array_pop(iter->frames);
696 0 584 buf = git_array_pop(frame->similar_paths);
698 0 584 } while (buf != NULL);
702 0 584 git_vector_foreach(&frame->similar_trees, i, tree)
715 280 0 if (!iterator__has_been_accessed(i))
718 0 0 if (!iter->frames.size) {
756 278 1431 if ((frame = tree_iterator_current_frame(iter)) == NULL) {
762 538 893 if (frame->next_idx == frame->entries.length) {
770 544 349 if (frame->next_idx == 0 && !git_vector_is_sorted(&frame->entries))
6 538 if (frame->next_idx == 0 && !git_vector_is_sorted(&frame->entries))
781 10 883 if (iterator__ignore_case(&iter->base) &&
4 6 if (iterator__ignore_case(&iter->base) &&
782 0 4 prev_entry &&
786 0 893 if ((error = tree_iterator_compute_path(&iter->entry_path, entry)) < 0)
790 0 893 if (!iterator_has_started(&iter->base, iter->entry_path.ptr, false))
794 6 887 if (iterator_has_ended(&iter->base, iter->entry_path.ptr)) {
800 20 867 if (!iterator_pathlist_next_is(&iter->base, iter->entry_path.ptr))
806 260 607 if (is_tree && !iterator__include_trees(iter)) {
260 0 if (is_tree && !iterator__include_trees(iter)) {
812 260 0 if (iterator__do_autoexpand(iter)) {
813 0 260 if ((error = tree_iterator_frame_push(iter, entry)) < 0)
825 0 607 if (is_tree && iterator__do_autoexpand(iter))
0 0 if (is_tree && iterator__do_autoexpand(iter))
831 891 0 if (out)
832 607 284 *out = (error == 0) ? &iter->entry : NULL;
845 0 0 if (out)
848 0 0 if ((frame = tree_iterator_current_frame(iter)) == NULL)
858 0 0 assert(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
860 0 0 if (prev_entry) {
861 0 0 if (!git_tree_entry__is_tree(prev_entry->tree_entry))
864 0 0 if ((error = tree_iterator_frame_push(iter, prev_entry)) < 0)
885 46 324 while (iter->frames.size)
902 0 324 if ((error = tree_iterator_frame_init(iter, iter->root, NULL)) < 0)
947 17 284 if (tree == NULL)
951 0 284 GIT_ERROR_CHECK_ALLOC(iter);
956 284 0 if ((error = iterator_init_common(&iter->base,
957 284 0 git_tree_owner(tree), NULL, options)) < 0 ||
958 284 0 (error = git_tree_dup(&iter->root, tree)) < 0 ||
977 0 0 assert(i->type == GIT_ITERATOR_TREE);
994 0 0 assert(i->type == GIT_ITERATOR_TREE);
998 0 0 assert(depth < iter->frames.size);
1052 176 0 &iter->frames.ptr[iter->frames.size-2] : NULL;
1058 2049 207 return iter->frames.size ? &iter->frames.ptr[iter->frames.size-1] : NULL;
1065 243 0 NULL : frame->entries.contents[frame->next_idx-1];
1101 9 260 if (iter->tree) {
1106 1 8 if (error < 0 && error != GIT_ENOTFOUND)
0 1 if (error < 0 && error != GIT_ENOTFOUND)
1109 8 1 if (!error) {
1115 269 0 if (!is_submodule && iter->base.index) {
206 63 if (!is_submodule && iter->base.index) {
1121 206 0 if (error < 0 && error != GIT_ENOTFOUND)
0 206 if (error < 0 && error != GIT_ENOTFOUND)
1124 0 206 if (!error) {
1140 239 213 const char *path = frame_entry ? frame_entry->path : "";
1142 93 359 if (!iterator__honor_ignores(&iter->base))
1145 0 359 if (git_ignore__lookup(&new_frame->is_ignored,
1152 176 183 if (frame_entry) {
1161 176 0 if (new_frame->is_ignored <= GIT_IGNORE_NOTFOUND)
1171 359 93 if (iterator__honor_ignores(&iter->base))
1189 46 1200 if (iter->base.start_len) {
1196 6 40 if (cmp == 0) {
1197 1 5 if (iter->base.start[path_len] == '/')
1200 0 5 else if (iter->base.start[path_len] != '\0')
1204 20 26 if (cmp < 0)
1208 26 1200 if (iter->base.end_len) {
1211 14 12 if (cmp > 0)
1218 145 1067 if (iter->base.pathlist.length) {
1220 8 137 if (frame_entry && frame_entry->match != ITERATOR_PATHLIST_IS_PARENT)
0 8 if (frame_entry && frame_entry->match != ITERATOR_PATHLIST_IS_PARENT)
1225 99 46 if (match == ITERATOR_PATHLIST_NONE)
1229 46 0 if (match == ITERATOR_PATHLIST_IS_DIR ||
8 38 if (match == ITERATOR_PATHLIST_IS_DIR ||
1244 191 922 if (!iterator__ignore_dot_git(&iter->base))
1247 0 922 if ((len = path_len) < 4)
1250 0 922 if (path[len - 1] == '/')
1253 305 617 if (git__tolower(path[len - 1]) != 't' ||
137 168 if (git__tolower(path[len - 1]) != 't' ||
1254 137 0 git__tolower(path[len - 2]) != 'i' ||
1255 0 137 git__tolower(path[len - 3]) != 'g' ||
1259 0 137 return (len == 4 || path[len - 5] == '/');
0 0 return (len == 4 || path[len - 5] == '/');
1269 0 0 if (S_ISDIR(entry->st.st_mode)) {
1274 0 0 if (iter->base.type == GIT_ITERATOR_WORKDIR)
1278 0 0 if (!(error = git_buf_joinpath(&fullpath, iter->root, entry->path)))
1303 0 976 GIT_ERROR_CHECK_ALLOC_ADD(&entry_size,
0 976 GIT_ERROR_CHECK_ALLOC_ADD(&entry_size,
1305 0 976 GIT_ERROR_CHECK_ALLOC_ADD(&entry_size, entry_size, 2);
0 976 GIT_ERROR_CHECK_ALLOC_ADD(&entry_size, entry_size, 2);
1308 0 976 GIT_ERROR_CHECK_ALLOC(entry);
1316 269 707 if (S_ISDIR(entry->st.st_mode))
1321 0 976 if (iter->base.flags & GIT_ITERATOR_INCLUDE_HASH)
1324 976 0 if (!error)
1343 0 454 if (iter->frames.size == FILESYSTEM_MAX_DEPTH) {
1349 215 239 new_frame = git_array_alloc(iter->frames);
239 0 new_frame = git_array_alloc(iter->frames);
1350 0 454 GIT_ERROR_CHECK_ALLOC(new_frame);
1354 239 215 if (frame_entry)
1359 0 454 if (git_buf_oom(&root)) {
1364 239 215 new_frame->path_len = frame_entry ? frame_entry->path_len : 0;
1367 2 452 if ((error = git_path_diriter_init(
1373 2 450 if ((error = git_vector_init(&new_frame->entries, 64,
0 452 if ((error = git_vector_init(&new_frame->entries, 64,
1384 1246 452 while ((error = git_path_diriter_next(&diriter)) == 0) {
1388 0 1246 if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0)
1391 0 1246 assert(path_len > iter->root_len);
1402 133 1113 if (!filesystem_iterator_examine_path(&dir_expected, &pathlist_match,
1410 0 1113 if ((error = git_path_diriter_stat(&statbuf, &diriter)) < 0) {
1412 0 0 if (error == GIT_ENOTFOUND)
1425 709 404 if (!S_ISDIR(statbuf.st_mode) &&
0 709 if (!S_ISDIR(statbuf.st_mode) &&
1426 0 0 !S_ISREG(statbuf.st_mode) &&
1427 0 0 !S_ISLNK(statbuf.st_mode) &&
1431 137 976 if (filesystem_iterator_is_dot_git(iter, path, path_len))
1435 269 707 if (S_ISDIR(statbuf.st_mode)) {
1438 0 269 if ((error = filesystem_iterator_is_submodule(&submodule,
1442 0 269 if (submodule)
1447 0 707 else if (dir_expected)
1450 0 976 if ((error = filesystem_iterator_entry_init(&entry,
1457 452 0 if (error == GIT_ITEROVER)
1464 2 452 if (error < 0)
1465 2 0 git_array_pop(iter->frames);
1476 0 452 assert(iter->frames.size);
1478 452 0 frame = git_array_pop(iter->frames);
1514 0 895 if (iter->base.flags & GIT_ITERATOR_INCLUDE_HASH)
1527 171 73 if (!iterator__has_been_accessed(i))
1530 0 73 if (!iter->frames.size) {
1548 269 689 if (S_ISDIR(entry->st.st_mode)) {
1553 128 561 if (!iterator__descend_symlinks(iter) || !S_ISLNK(entry->st.st_mode)) {
128 0 if (!iterator__descend_symlinks(iter) || !S_ISLNK(entry->st.st_mode)) {
1558 0 0 if ((error = git_buf_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
0 0 if ((error = git_buf_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
1583 207 1404 if ((frame = filesystem_iterator_current_frame(iter)) == NULL) {
1589 446 958 if (frame->next_idx == frame->entries.length) {
1598 0 958 if ((error = filesystem_iterator_is_dir(&is_dir, iter, entry)) < 0)
1601 269 689 if (is_dir) {
1602 63 206 if (iterator__do_autoexpand(iter)) {
1608 0 63 if (error == GIT_ENOTFOUND)
1610 0 63 else if (error < 0)
1614 63 206 if (!iterator__include_trees(iter))
1622 1102 0 if (out)
1623 895 207 *out = (error == 0) ? &iter->entry : NULL;
1636 176 0 if (out)
1639 0 176 if ((frame = filesystem_iterator_current_frame(iter)) == NULL)
1649 0 176 assert(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
1651 176 0 if (prev_entry) {
1652 176 0 if (prev_entry->st.st_mode != GIT_FILEMODE_COMMIT &&
0 176 if (prev_entry->st.st_mode != GIT_FILEMODE_COMMIT &&
1656 0 176 if ((error = filesystem_iterator_frame_push(iter, prev_entry)) < 0)
1671 6 0 if (i->type != GIT_ITERATOR_FS &&
0 6 if (i->type != GIT_ITERATOR_FS &&
1704 0 405 if (git_ignore__lookup(&iter->current_is_ignored,
1711 395 10 if (iter->current_is_ignored <= GIT_IGNORE_NOTFOUND) {
1720 405 11 if (iter->current_is_ignored == GIT_IGNORE_UNCHECKED)
1730 49 332 if (i->type != GIT_ITERATOR_WORKDIR)
1743 0 7 if (i->type != GIT_ITERATOR_WORKDIR)
1765 0 67 assert(iterator__has_been_accessed(i));
1768 0 67 assert(current_frame);
1770 0 67 assert(current_entry);
1772 0 67 if ((error = git_iterator_current(&entry, i)) < 0)
1775 49 18 if (!S_ISDIR(entry->mode)) {
1776 1 48 if (filesystem_iterator_current_is_ignored(iter))
1783 0 18 if ((error = git_buf_puts(&iter->tmp_buf, entry->path)) < 0)
1798 0 18 *status = current_entry->match == ITERATOR_PATHLIST_IS_PARENT ?
1801 36 0 while (entry && !iter->base.prefixcomp(entry->path, base)) {
35 1 while (entry && !iter->base.prefixcomp(entry->path, base)) {
1802 0 35 if (filesystem_iterator_current_is_ignored(iter)) {
1807 18 17 } else if (S_ISDIR(entry->mode)) {
1810 18 0 if (!error)
1814 0 0 else if (error == GIT_ENOTFOUND)
1826 0 0 if ((error = git_iterator_advance(&entry, i)) < 0)
1831 34 0 while (entry && !iter->base.prefixcomp(entry->path, base)) {
17 17 while (entry && !iter->base.prefixcomp(entry->path, base)) {
1832 1 16 if ((error = git_iterator_advance(&entry, i)) < 0)
1836 17 1 if (!error)
1844 6 215 while (iter->frames.size)
1859 183 32 if (iterator__honor_ignores(&iter->base) &&
0 183 if (iterator__honor_ignores(&iter->base) &&
1864 2 213 if ((error = filesystem_iterator_frame_push(iter, NULL)) < 0)
1886 171 38 if (iter->index)
1915 0 209 if (root == NULL)
1919 0 209 GIT_ERROR_CHECK_ALLOC(iter);
1927 0 209 GIT_ERROR_CHECK_ALLOC(iter->root);
1931 209 0 if (root_len == 0 || root[root_len-1] != '/') {
0 209 if (root_len == 0 || root[root_len-1] != '/') {
1938 0 209 if ((error = git_buf_puts(&iter->current_path, iter->root)) < 0)
1941 0 209 if ((error = iterator_init_common(&iter->base, repo, index, options)) < 0)
1944 2 207 if (tree && (error = git_tree_dup(&iter->tree, tree)) < 0)
0 2 if (tree && (error = git_tree_dup(&iter->tree, tree)) < 0)
1947 171 38 if (index &&
0 171 if (index &&
1955 0 209 GIT_PATH_DIR_PRECOMPOSE_UNICODE : 0);
1957 2 207 if ((error = filesystem_iterator_init(iter)) < 0)
1987 124 53 if (!repo_workdir) {
1988 0 124 if (git_repository__ensure_not_bare(repo, "scan working directory") < 0)
1995 177 0 if (given_opts)
2027 259 0 if (!iterator__has_been_accessed(i))
2030 0 0 if (iter->entry == NULL) {
2047 0 0 prev_path = iter->entry ? iter->entry->path : "";
2053 0 0 if ((dirsep = strchr(relative_path, '/')) == NULL)
2068 0 0 assert(iterator__has_been_accessed(&iter->base));
2069 0 0 assert(S_ISDIR(iter->entry->mode));
2074 0 0 if (++iter->next_idx >= iter->entries.length)
2079 0 0 if (iter->base.strncomp(iter->tree_buf.ptr, next_entry->path,
2099 260 587 if (iter->next_idx >= iter->entries.length) {
2105 0 587 if (iter->skip_tree) {
2113 0 587 if (!iterator_has_started(&iter->base, entry->path, is_submodule)) {
2118 0 587 if (iterator_has_ended(&iter->base, entry->path)) {
2124 65 522 if (!iterator_pathlist_next_is(&iter->base, entry->path)) {
2130 22 500 if (git_index_entry_is_conflict(entry) &&
22 0 if (git_index_entry_is_conflict(entry) &&
2153 500 260 iter->entry = (error == 0) ? entry : NULL;
2155 760 0 if (out)
2166 0 0 if (! S_ISDIR(iter->tree_entry.mode)) {
2167 0 0 if (out)
2186 0 0 if ((error = index_iterator_current(&entry, i)) < 0)
2189 0 0 if (S_ISDIR(entry->mode))
2245 0 260 if (index == NULL)
2249 0 260 GIT_ERROR_CHECK_ALLOC(iter);
2254 260 0 if ((error = iterator_init_common(&iter->base, repo, index, options)) < 0 ||
260 0 if ((error = iterator_init_common(&iter->base, repo, index, options)) < 0 ||
2255 260 0 (error = git_index_snapshot_new(&iter->entries, index)) < 0 ||
2259 0 260 git_vector_set_cmp(&iter->entries, iterator__ignore_case(&iter->base) ?
2277 0 64 if (iterator_reset_range(i, start, end) < 0)
2285 0 0 assert(!iterator__has_been_accessed(i));
2291 94 770 if (iter == NULL)
2313 0 0 if ((error = git_iterator_current(&iterator_item, iterator)) < 0)
2316 0 0 if ((error = cb(iterator_item, data)) != 0)
2320 0 0 if ((error = git_iterator_advance(&iterator_item, iterator)) < 0)
2323 0 0 if ((error = cb(iterator_item, data)) != 0)
2328 0 0 if (error == GIT_ITEROVER)
2349 0 22 GIT_ERROR_CHECK_ALLOC(iterator_item);
2350 0 22 GIT_ERROR_CHECK_ALLOC(cur_items);
2353 66 22 for (i = 0; i < cnt; i++) {
2356 0 66 if (error < 0 && error != GIT_ITEROVER)
0 0 if (error < 0 && error != GIT_ITEROVER)
2361 210 70 for (i = 0; i < cnt; i++)
2367 210 70 for (i = 0; i < cnt; i++) {
2368 70 140 if (iterator_item[i] == NULL)
2371 48 92 if (first_match == NULL) {
2377 1 91 if (path_diff < 0) {
2382 2 1 for (j = 0; j < i; j++)
2387 90 1 } else if (path_diff == 0) {
2393 22 48 if (first_match == NULL)
2396 0 48 if ((error = cb(cur_items, data)) != 0)
2400 144 48 for (i = 0; i < cnt; i++) {
2401 7 137 if (cur_items[i] == NULL)
2406 66 71 if (error < 0 && error != GIT_ITEROVER)
0 66 if (error < 0 && error != GIT_ITEROVER)
2415 22 0 if (error == GIT_ITEROVER)