Branch Coverage

deps/libgit2/src/attr_file.c
Criterion Covered Total %
branch 149 366 40.7


line true false branch
40 0 2502 GIT_ERROR_CHECK_ALLOC(attrs);
42 0 2502 if (git_mutex_init(&attrs->lock) < 0) {
47 0 2502 if (git_pool_init(&attrs->pool, 1) < 0)
66 0 2502 if (need_lock && git_mutex_lock(&file->lock) < 0) {
0 0 if (need_lock && git_mutex_lock(&file->lock) < 0) {
71 44 2502 git_vector_foreach(&file->rules, i, rule)
83 668 8131 if (!file)
85 2502 5629 GIT_REFCOUNT_DEC(file, attr_file_free);
2502 0 GIT_REFCOUNT_DEC(file, attr_file_free);
96 1308 0 if ((error = git_repository_index__weakptr(&idx, repo)) < 0 ||
1308 0 if ((error = git_repository_index__weakptr(&idx, repo)) < 0 ||
100 0 0 if (!(entry = git_index_get_byindex(idx, pos)))
137 0 1308 if ((error = attr_file_oid_from_index(&id, repo, entry->path)) < 0 ||
0 0 if ((error = attr_file_oid_from_index(&id, repo, entry->path)) < 0 ||
145 0 0 GIT_ERROR_CHECK_BLOBSIZE(blobsize);
155 15 2473 if (p_stat(entry->fullpath, &st) < 0 ||
15 0 if (p_stat(entry->fullpath, &st) < 0 ||
156 15 0 S_ISDIR(st.st_mode) ||
157 0 15 (fd = git_futils_open_ro(entry->fullpath)) < 0 ||
161 15 2473 if (fd >= 0)
167 0 0 if ((error = git_repository_head_tree(&tree, repo)) < 0 ||
0 0 if ((error = git_repository_head_tree(&tree, repo)) < 0 ||
168 0 0 (error = git_tree_entry_bypath(&tree_entry, tree, entry->path)) < 0 ||
178 0 0 GIT_ERROR_CHECK_BLOBSIZE(blobsize);
179 0 0 if ((error = git_buf_put(&content,
190 0 2502 if ((error = git_attr_file__new(&file, entry, source)) < 0)
197 0 2502 if (bom == GIT_BOM_UTF8)
203 117 2385 if (attr_session)
206 2488 14 if (parser && (error = parser(repo, file, content_str, allow_macros)) < 0) {
0 2488 if (parser && (error = parser(repo, file, content_str, allow_macros)) < 0) {
212 2473 29 if (nonexistent)
214 0 29 else if (source == GIT_ATTR_FILE__FROM_INDEX)
216 0 29 else if (source == GIT_ATTR_FILE__FROM_HEAD)
218 15 14 else if (source == GIT_ATTR_FILE__FROM_FILE)
238 0 3127 if (!file)
244 465 2662 if (attr_session && attr_session->key == file->session_key)
361 104 if (attr_session && attr_session->key == file->session_key)
246 2401 365 else if (file->nonexistent)
261 0 0 if ((error = attr_file_oid_from_index(
272 0 0 if ((error = git_repository_head_tree(&tree, repo)) < 0)
302 2131 0 if (attrs->entry && git_path_root(attrs->entry->path) < 0 &&
306 0 2131 if (git_mutex_lock(&attrs->lock) < 0) {
311 2131 0 while (!error && *scan) {
0 2131 while (!error && *scan) {
313 0 0 if (!rule) {
315 0 0 GIT_ERROR_CHECK_ALLOC(rule);
322 0 0 if ((error = git_attr_fnmatch__parse(&rule->match, &attrs->pool, context, &scan)) < 0 ||
0 0 if ((error = git_attr_fnmatch__parse(&rule->match, &attrs->pool, context, &scan)) < 0 ||
325 0 0 if (error != GIT_ENOTFOUND)
331 0 0 if (rule->match.flags & GIT_ATTR_FNMATCH_MACRO) {
333 0 0 if (!allow_macros)
335 0 0 if ((error = git_attr_cache__insert_macro(repo, rule)) < 0)
337 0 0 } else if ((error = git_vector_insert(&attrs->rules, rule)) < 0)
354 0 4 assert(name);
355 20 4 while ((c = (int)*name++) != 0)
375 0 0 git_attr_file__foreach_matching_rule(file, path, i, rule) {
0 0 git_attr_file__foreach_matching_rule(file, path, i, rule) {
378 0 0 if (!git_vector_bsearch(&pos, &rule->assigns, &name)) {
394 0 0 if ((error = git_futils_readbuffer(&content, path)) < 0)
402 0 0 if ((error = git_attr_file__new(&file, NULL, GIT_ATTR_FILE__FROM_FILE)) < 0 ||
0 0 if ((error = git_attr_file__new(&file, NULL, GIT_ATTR_FILE__FROM_FILE)) < 0 ||
403 0 0 (error = git_attr_file__parse_buffer(NULL, file, content.ptr, true)) < 0 ||
409 0 0 if (error < 0)
429 0 2343 if (match->containing_dir) {
430 0 0 if (match->flags & GIT_ATTR_FNMATCH_ICASE) {
431 0 0 if (git__strncasecmp(path->path, match->containing_dir, match->containing_dir_length))
434 0 0 if (git__prefixcmp(path->path, match->containing_dir))
441 0 2343 if (match->flags & GIT_ATTR_FNMATCH_ICASE)
444 0 2343 if (match->flags & GIT_ATTR_FNMATCH_FULLPATH) {
451 0 2343 if ((match->flags & GIT_ATTR_FNMATCH_DIRECTORY) && !path->is_dir) {
0 0 if ((match->flags & GIT_ATTR_FNMATCH_DIRECTORY) && !path->is_dir) {
459 0 0 if (!(match->flags & GIT_ATTR_FNMATCH_IGNORE) ||
0 0 if (!(match->flags & GIT_ATTR_FNMATCH_IGNORE) ||
465 0 0 !strcasecmp(match->pattern, relpath) :
468 0 0 if (samename)
483 0 0 if (rule->match.flags & GIT_ATTR_FNMATCH_NEGATIVE)
497 0 0 if (git_vector_bsearch(&pos, &rule->assigns, &key))
511 0 1416 if (git_path_join_unrooted(&info->full, path, base, &root) < 0)
517 1937 0 while (info->full.size > 0) {
518 1416 521 if (info->full.ptr[info->full.size - 1] != '/')
525 70 1416 while (*info->path == '/')
530 249 1167 if (info->basename)
532 249 1167 if (!info->basename || !*info->basename)
0 249 if (!info->basename || !*info->basename)
600 132 0 for (n = len; n; n--) {
601 132 0 if (p[n-1] != ' ' && p[n-1] != '\t')
132 0 if (p[n-1] != ' ' && p[n-1] != '\t')
612 0 0 while (i > 1 && p[i-2] == '\\')
0 0 while (i > 1 && p[i-2] == '\\')
614 0 0 if ((n - i) % 2)
625 0 132 if (!str)
628 653 132 for (scan = str; *scan; scan++) {
629 653 0 if (!escaped && *scan == '\\') {
0 653 if (!escaped && *scan == '\\') {
635 0 653 if (escaped && !git__isspace(*scan))
0 0 if (escaped && !git__isspace(*scan))
642 0 132 if (pos != scan)
663 160 0 assert(spec && base && *base);
160 0 assert(spec && base && *base);
0 160 assert(spec && base && *base);
665 0 160 if (parse_optimized_patterns(spec, pool, *base))
673 0 160 while (!allow_space && git__isspace(*pattern))
0 0 while (!allow_space && git__isspace(*pattern))
676 160 0 if (!*pattern || *pattern == '#' || *pattern == '\n' ||
132 28 if (!*pattern || *pattern == '#' || *pattern == '\n' ||
132 0 if (!*pattern || *pattern == '#' || *pattern == '\n' ||
0 132 if (!*pattern || *pattern == '#' || *pattern == '\n' ||
677 0 0 (*pattern == '\r' && *(pattern + 1) == '\n')) {
682 0 132 if (*pattern == '[' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWMACRO) != 0) {
0 0 if (*pattern == '[' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWMACRO) != 0) {
683 0 0 if (strncmp(pattern, "[attr]", 6) == 0) {
690 0 132 if (*pattern == '!' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWNEG) != 0) {
0 0 if (*pattern == '!' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWNEG) != 0) {
698 699 88 for (scan = pattern; *scan != '\0'; ++scan) {
701 0 699 if (c == '\\' && !escaped) {
0 0 if (c == '\\' && !escaped) {
704 44 655 } else if (git__isspace(c) && !escaped) {
44 0 } else if (git__isspace(c) && !escaped) {
705 44 0 if (!allow_space || (c != ' ' && c != '\t' && c != '\r'))
44 0 if (!allow_space || (c != ' ' && c != '\t' && c != '\r'))
44 0 if (!allow_space || (c != ' ' && c != '\t' && c != '\r'))
0 44 if (!allow_space || (c != ' ' && c != '\t' && c != '\r'))
707 11 644 } else if (c == '/') {
711 5 6 if (slash_count == 1 && pattern == scan)
0 5 if (slash_count == 1 && pattern == scan)
713 16 628 } else if (git__iswildcard(c) && !escaped) {
16 0 } else if (git__iswildcard(c) && !escaped) {
723 0 132 if ((spec->length = scan - pattern) == 0)
731 0 132 if (pattern[spec->length - 1] == '\r')
732 0 0 if (--spec->length == 0)
738 0 132 if (spec->length == 0)
741 2 130 if (pattern[spec->length - 1] == '/') {
744 2 0 if (--slash_count <= 0)
748 0 132 if (context) {
751 0 0 if (slash) {
761 0 132 if (!spec->pattern) {
777 0 160 if (!pattern[1] && (pattern[0] == '*' || pattern[0] == '.')) {
0 0 if (!pattern[1] && (pattern[0] == '*' || pattern[0] == '.')) {
0 0 if (!pattern[1] && (pattern[0] == '*' || pattern[0] == '.')) {
793 32 32 if (b->name_hash < a->name_hash)
795 32 0 else if (b->name_hash > a->name_hash)
816 0 0 GIT_REFCOUNT_DEC(*old, git_attr_assignment__free);
0 0 GIT_REFCOUNT_DEC(*old, git_attr_assignment__free);
831 16 0 assert(assigns && !assigns->length);
0 16 assert(assigns && !assigns->length);
835 64 16 while (*scan && *scan != '\n') {
64 0 while (*scan && *scan != '\n') {
839 48 64 while (git__isspace(*scan) && *scan != '\n') scan++;
48 0 while (git__isspace(*scan) && *scan != '\n') scan++;
842 64 0 if (!assign) {
844 0 64 GIT_ERROR_CHECK_ALLOC(assign);
852 64 0 if (*scan == '-') {
855 0 0 } else if (*scan == '!') {
858 0 0 } else if (*scan == '#') /* comment rest of line */
863 320 16 while (*scan && !git__isspace(*scan) && *scan != '=') {
272 48 while (*scan && !git__isspace(*scan) && *scan != '=') {
272 0 while (*scan && !git__isspace(*scan) && *scan != '=') {
868 0 64 if (scan == name_start) {
872 0 0 while (*scan && !git__isspace(*scan)) scan++;
0 0 while (*scan && !git__isspace(*scan)) scan++;
878 0 64 GIT_ERROR_CHECK_ALLOC(assign->name);
881 0 64 if (*scan == '=') {
882 0 0 for (value_start = ++scan; *scan && !git__isspace(*scan); ++scan);
0 0 for (value_start = ++scan; *scan && !git__isspace(*scan); ++scan);
885 0 0 if (scan > value_start) {
887 0 0 GIT_ERROR_CHECK_ALLOC(assign->value);
892 64 0 if (repo != NULL && assign->value == git_attr__true) {
0 64 if (repo != NULL && assign->value == git_attr__true) {
896 0 0 if (macro != NULL) {
900 0 0 git_vector_foreach(¯o->assigns, i, massign) {
905 0 0 if (error < 0 && error != GIT_EEXISTS) {
0 0 if (error < 0 && error != GIT_EEXISTS) {
915 0 64 if (error < 0 && error != GIT_EEXISTS)
0 0 if (error < 0 && error != GIT_EEXISTS)
922 0 16 if (assign != NULL)
927 0 16 return (assigns->length == 0) ? GIT_ENOTFOUND : 0;
935 2131 60 if (!rule)
938 16 44 if (!(rule->match.flags & GIT_ATTR_FNMATCH_IGNORE)) {
939 64 16 git_vector_foreach(&rule->assigns, i, assign)
940 64 0 GIT_REFCOUNT_DEC(assign, git_attr_assignment__free);
64 0 GIT_REFCOUNT_DEC(assign, git_attr_assignment__free);
957 0 355 assert(repo);
967 0 355 if (!session)