Branch Coverage

deps/libgit2/src/attr_file.c
Criterion Covered Total %
branch 148 364 40.6


line true false branch
40 0 2158 GIT_ERROR_CHECK_ALLOC(attrs);
42 0 2158 if (git_mutex_init(&attrs->lock) < 0) {
61 0 2158 if (need_lock && git_mutex_lock(&file->lock) < 0) {
0 0 if (need_lock && git_mutex_lock(&file->lock) < 0) {
66 44 2158 git_vector_foreach(&file->rules, i, rule)
78 584 7099 if (!file)
80 2158 4941 GIT_REFCOUNT_DEC(file, attr_file_free);
2158 0 GIT_REFCOUNT_DEC(file, attr_file_free);
91 1132 0 if ((error = git_repository_index__weakptr(&idx, repo)) < 0 ||
1132 0 if ((error = git_repository_index__weakptr(&idx, repo)) < 0 ||
95 0 0 if (!(entry = git_index_get_byindex(idx, pos)))
132 0 1132 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 ||
140 0 0 GIT_ERROR_CHECK_BLOBSIZE(blobsize);
150 15 2129 if (p_stat(entry->fullpath, &st) < 0 ||
15 0 if (p_stat(entry->fullpath, &st) < 0 ||
151 15 0 S_ISDIR(st.st_mode) ||
152 0 15 (fd = git_futils_open_ro(entry->fullpath)) < 0 ||
156 15 2129 if (fd >= 0)
162 0 0 if ((error = git_repository_head_tree(&tree, repo)) < 0 ||
0 0 if ((error = git_repository_head_tree(&tree, repo)) < 0 ||
163 0 0 (error = git_tree_entry_bypath(&tree_entry, tree, entry->path)) < 0 ||
173 0 0 GIT_ERROR_CHECK_BLOBSIZE(blobsize);
174 0 0 if ((error = git_buf_put(&content,
185 0 2158 if ((error = git_attr_file__new(&file, entry, source)) < 0)
192 0 2158 if (bom == GIT_BOM_UTF8)
198 117 2041 if (attr_session)
201 2144 14 if (parser && (error = parser(repo, file, content_str, allow_macros)) < 0) {
0 2144 if (parser && (error = parser(repo, file, content_str, allow_macros)) < 0) {
207 2129 29 if (nonexistent)
209 0 29 else if (source == GIT_ATTR_FILE__FROM_INDEX)
211 0 29 else if (source == GIT_ATTR_FILE__FROM_HEAD)
213 15 14 else if (source == GIT_ATTR_FILE__FROM_FILE)
233 0 2783 if (!file)
239 465 2318 if (attr_session && attr_session->key == file->session_key)
361 104 if (attr_session && attr_session->key == file->session_key)
241 2057 365 else if (file->nonexistent)
256 0 0 if ((error = attr_file_oid_from_index(
267 0 0 if ((error = git_repository_head_tree(&tree, repo)) < 0)
297 1787 0 if (attrs->entry && git_path_root(attrs->entry->path) < 0 &&
301 0 1787 if (git_mutex_lock(&attrs->lock) < 0) {
306 1787 0 while (!error && *scan) {
0 1787 while (!error && *scan) {
308 0 0 if (!rule) {
310 0 0 GIT_ERROR_CHECK_ALLOC(rule);
317 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 ||
320 0 0 if (error != GIT_ENOTFOUND)
326 0 0 if (rule->match.flags & GIT_ATTR_FNMATCH_MACRO) {
328 0 0 if (!allow_macros)
330 0 0 if ((error = git_attr_cache__insert_macro(repo, rule)) < 0)
332 0 0 } else if ((error = git_vector_insert(&attrs->rules, rule)) < 0)
349 0 4 assert(name);
350 20 4 while ((c = (int)*name++) != 0)
370 0 0 git_attr_file__foreach_matching_rule(file, path, i, rule) {
0 0 git_attr_file__foreach_matching_rule(file, path, i, rule) {
373 0 0 if (!git_vector_bsearch(&pos, &rule->assigns, &name)) {
389 0 0 if ((error = git_futils_readbuffer(&content, path)) < 0)
397 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 ||
398 0 0 (error = git_attr_file__parse_buffer(NULL, file, content.ptr, true)) < 0 ||
404 0 0 if (error < 0)
424 0 2343 if (match->containing_dir) {
425 0 0 if (match->flags & GIT_ATTR_FNMATCH_ICASE) {
426 0 0 if (git__strncasecmp(path->path, match->containing_dir, match->containing_dir_length))
429 0 0 if (git__prefixcmp(path->path, match->containing_dir))
436 0 2343 if (match->flags & GIT_ATTR_FNMATCH_ICASE)
439 0 2343 if (match->flags & GIT_ATTR_FNMATCH_FULLPATH) {
446 0 2343 if ((match->flags & GIT_ATTR_FNMATCH_DIRECTORY) && !path->is_dir) {
0 0 if ((match->flags & GIT_ATTR_FNMATCH_DIRECTORY) && !path->is_dir) {
454 0 0 if (!(match->flags & GIT_ATTR_FNMATCH_IGNORE) ||
0 0 if (!(match->flags & GIT_ATTR_FNMATCH_IGNORE) ||
460 0 0 !strcasecmp(match->pattern, relpath) :
463 0 0 if (samename)
478 0 0 if (rule->match.flags & GIT_ATTR_FNMATCH_NEGATIVE)
492 0 0 if (git_vector_bsearch(&pos, &rule->assigns, &key))
506 0 1332 if (git_path_join_unrooted(&info->full, path, base, &root) < 0)
512 1853 0 while (info->full.size > 0) {
513 1332 521 if (info->full.ptr[info->full.size - 1] != '/')
520 70 1332 while (*info->path == '/')
525 247 1085 if (info->basename)
527 247 1085 if (!info->basename || !*info->basename)
0 247 if (!info->basename || !*info->basename)
595 132 0 for (n = len; n; n--) {
596 132 0 if (p[n-1] != ' ' && p[n-1] != '\t')
132 0 if (p[n-1] != ' ' && p[n-1] != '\t')
607 0 0 while (i > 1 && p[i-2] == '\\')
0 0 while (i > 1 && p[i-2] == '\\')
609 0 0 if ((n - i) % 2)
620 0 132 if (!str)
623 653 132 for (scan = str; *scan; scan++) {
624 653 0 if (!escaped && *scan == '\\') {
0 653 if (!escaped && *scan == '\\') {
630 0 653 if (escaped && !git__isspace(*scan))
0 0 if (escaped && !git__isspace(*scan))
637 0 132 if (pos != scan)
658 160 0 assert(spec && base && *base);
160 0 assert(spec && base && *base);
0 160 assert(spec && base && *base);
660 0 160 if (parse_optimized_patterns(spec, pool, *base))
668 0 160 while (!allow_space && git__isspace(*pattern))
0 0 while (!allow_space && git__isspace(*pattern))
671 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' ||
672 0 0 (*pattern == '\r' && *(pattern + 1) == '\n')) {
677 0 132 if (*pattern == '[' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWMACRO) != 0) {
0 0 if (*pattern == '[' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWMACRO) != 0) {
678 0 0 if (strncmp(pattern, "[attr]", 6) == 0) {
685 0 132 if (*pattern == '!' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWNEG) != 0) {
0 0 if (*pattern == '!' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWNEG) != 0) {
693 699 88 for (scan = pattern; *scan != '\0'; ++scan) {
696 0 699 if (c == '\\' && !escaped) {
0 0 if (c == '\\' && !escaped) {
699 44 655 } else if (git__isspace(c) && !escaped) {
44 0 } else if (git__isspace(c) && !escaped) {
700 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'))
702 11 644 } else if (c == '/') {
706 5 6 if (slash_count == 1 && pattern == scan)
0 5 if (slash_count == 1 && pattern == scan)
708 16 628 } else if (git__iswildcard(c) && !escaped) {
16 0 } else if (git__iswildcard(c) && !escaped) {
718 0 132 if ((spec->length = scan - pattern) == 0)
726 0 132 if (pattern[spec->length - 1] == '\r')
727 0 0 if (--spec->length == 0)
733 0 132 if (spec->length == 0)
736 2 130 if (pattern[spec->length - 1] == '/') {
739 2 0 if (--slash_count <= 0)
743 0 132 if (context) {
746 0 0 if (slash) {
756 0 132 if (!spec->pattern) {
772 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] == '.')) {
788 32 32 if (b->name_hash < a->name_hash)
790 32 0 else if (b->name_hash > a->name_hash)
811 0 0 GIT_REFCOUNT_DEC(*old, git_attr_assignment__free);
0 0 GIT_REFCOUNT_DEC(*old, git_attr_assignment__free);
826 16 0 assert(assigns && !assigns->length);
0 16 assert(assigns && !assigns->length);
830 64 16 while (*scan && *scan != '\n') {
64 0 while (*scan && *scan != '\n') {
834 48 64 while (git__isspace(*scan) && *scan != '\n') scan++;
48 0 while (git__isspace(*scan) && *scan != '\n') scan++;
837 64 0 if (!assign) {
839 0 64 GIT_ERROR_CHECK_ALLOC(assign);
847 64 0 if (*scan == '-') {
850 0 0 } else if (*scan == '!') {
853 0 0 } else if (*scan == '#') /* comment rest of line */
858 320 16 while (*scan && !git__isspace(*scan) && *scan != '=') {
272 48 while (*scan && !git__isspace(*scan) && *scan != '=') {
272 0 while (*scan && !git__isspace(*scan) && *scan != '=') {
863 0 64 if (scan == name_start) {
867 0 0 while (*scan && !git__isspace(*scan)) scan++;
0 0 while (*scan && !git__isspace(*scan)) scan++;
873 0 64 GIT_ERROR_CHECK_ALLOC(assign->name);
876 0 64 if (*scan == '=') {
877 0 0 for (value_start = ++scan; *scan && !git__isspace(*scan); ++scan);
0 0 for (value_start = ++scan; *scan && !git__isspace(*scan); ++scan);
880 0 0 if (scan > value_start) {
882 0 0 GIT_ERROR_CHECK_ALLOC(assign->value);
887 64 0 if (repo != NULL && assign->value == git_attr__true) {
0 64 if (repo != NULL && assign->value == git_attr__true) {
891 0 0 if (macro != NULL) {
895 0 0 git_vector_foreach(¯o->assigns, i, massign) {
900 0 0 if (error < 0 && error != GIT_EEXISTS) {
0 0 if (error < 0 && error != GIT_EEXISTS) {
910 0 64 if (error < 0 && error != GIT_EEXISTS)
0 0 if (error < 0 && error != GIT_EEXISTS)
917 0 16 if (assign != NULL)
922 0 16 return (assigns->length == 0) ? GIT_ENOTFOUND : 0;
930 1787 60 if (!rule)
933 16 44 if (!(rule->match.flags & GIT_ATTR_FNMATCH_IGNORE)) {
934 64 16 git_vector_foreach(&rule->assigns, i, assign)
935 64 0 GIT_REFCOUNT_DEC(assign, git_attr_assignment__free);
64 0 GIT_REFCOUNT_DEC(assign, git_attr_assignment__free);
952 0 355 assert(repo);
962 0 355 if (!session)