Branch Coverage

deps/libgit2/src/config_file.c
Criterion Covered Total %
branch 148 336 44.0


line true false branch
71 0 1970 if ((error = git_mutex_lock(&b->values_mutex)) < 0) {
89 0 130 if (file == NULL)
92 0 130 git_array_foreach(file->includes, i, include) {
0 0 git_array_foreach(file->includes, i, include) {
108 0 134 if ((res = git_config_entries_new(&b->entries)) < 0)
111 66 68 if (!git_path_exists(b->file.path))
120 0 68 if (p_access(b->file.path, R_OK) < 0)
123 68 0 if (res < 0 || (res = config_file_read(b->entries, repo, &b->file, level, 0)) < 0) {
0 68 if (res < 0 || (res = config_file_read(b->entries, repo, &b->file, level, 0)) < 0) {
141 973 942 if (!git_futils_filestamp_check(&file->stamp, file->path))
144 923 19 if ((error = git_futils_readbuffer(&buf, file->path)) < 0)
147 0 19 if ((error = git_hash_buf(&hash, buf.ptr, buf.size)) < 0)
150 19 0 if (!git_oid_equal(&hash, &file->checksum)) {
156 0 973 git_array_foreach(file->includes, i, include) {
0 0 git_array_foreach(file->includes, i, include) {
157 0 0 if ((error = config_file_is_modified(modified, include)) < 0 || *modified)
0 0 if ((error = config_file_is_modified(modified, include)) < 0 || *modified)
175 0 68 if (b->parent.readonly) {
180 0 68 git_array_foreach(b->file.includes, i, include)
0 0 git_array_foreach(b->file.includes, i, include)
184 0 68 if ((error = git_mutex_lock(&b->values_mutex)) < 0) {
205 49 0 if ((error = git_config_entries_new(&entries)) < 0 ||
49 0 if ((error = git_config_entries_new(&entries)) < 0 ||
207 49 0 b->level, 0, buf, buflen)) < 0 ||
223 0 1915 if (cfg->readonly)
226 923 992 if ((error = config_file_is_modified(&modified, &b->file)) < 0 && error != GIT_ENOTFOUND)
0 923 if ((error = config_file_is_modified(&modified, &b->file)) < 0 && error != GIT_ENOTFOUND)
229 1896 19 if (!modified)
232 19 0 if ((error = git_config_entries_new(&entries)) < 0 ||
19 0 if ((error = git_config_entries_new(&entries)) < 0 ||
233 19 0 (error = config_file_read(entries, b->repo, &b->file, b->level, 0)) < 0 ||
241 19 0 return (error == GIT_ENOTFOUND) ? 0 : error;
248 0 130 if (backend == NULL)
265 1032 0 if ((error = config_file_refresh(backend)) < 0 ||
1032 0 if ((error = config_file_refresh(backend)) < 0 ||
266 1032 0 (error = config_file_entries_take(&entries, b)) < 0 ||
291 0 40 if ((error = git_config__normalize_name(name, &key)) < 0)
294 0 40 if ((error = config_file_entries_take(&entries, b)) < 0)
298 36 4 if ((error = git_config_entries_get_unique(&existing, entries, key)) < 0) {
299 0 36 if (error != GIT_ENOTFOUND)
302 0 4 } else if ((!existing->value && !value) ||
0 0 } else if ((!existing->value && !value) ||
4 0 } else if ((!existing->value && !value) ||
303 4 0 (existing->value && value && !strcmp(existing->value, value))) {
1 3 (existing->value && value && !strcmp(existing->value, value))) {
310 39 0 if (value) {
312 0 39 GIT_ERROR_CHECK_ALLOC(esc_value);
315 0 39 if ((error = config_file_write(b, name, key, NULL, esc_value)) < 0)
342 883 0 if (!h->parent.readonly && ((error = config_file_refresh(cfg)) < 0))
0 883 if (!h->parent.readonly && ((error = config_file_refresh(cfg)) < 0))
345 0 883 if ((error = config_file_entries_take(&entries, h)) < 0)
348 814 69 if ((error = (git_config_entries_get(&entry, entries, key))) < 0) {
368 0 5 assert(regexp);
370 0 5 if ((result = git_config__normalize_name(name, &key)) < 0)
373 0 5 if ((result = git_regexp_compile(&preg, regexp, 0)) < 0)
377 0 5 if ((result = config_file_write(b, name, key, &preg, value)) < 0)
395 0 15 if ((error = git_config__normalize_name(name, &key)) < 0)
398 0 15 if ((error = config_file_entries_take(&entries, b)) < 0)
402 10 5 if ((error = git_config_entries_get_unique(&entry, entries, key)) < 0) {
403 10 0 if (error == GIT_ENOTFOUND)
408 0 5 if ((error = config_file_write(b, name, entry->name, NULL, NULL)) < 0)
426 0 0 if ((result = git_config__normalize_name(name, &key)) < 0)
429 0 0 if ((result = config_file_entries_take(&entries, b)) < 0)
432 0 0 if ((result = git_config_entries_get(&entry, entries, key)) < 0) {
433 0 0 if (result == GIT_ENOTFOUND)
438 0 0 if ((result = git_regexp_compile(&preg, regexp, 0)) < 0)
441 0 0 if ((result = config_file_write(b, name, key, &preg, NULL)) < 0)
456 0 0 if ((error = git_filebuf_open(&cfg->locked_buf, cfg->file.path, 0, GIT_CONFIG_FILE_MODE)) < 0)
460 0 0 if (error < 0 && error != GIT_ENOTFOUND) {
0 0 if (error < 0 && error != GIT_ENOTFOUND) {
475 0 0 if (success) {
492 0 134 GIT_ERROR_CHECK_ALLOC(backend);
498 0 134 GIT_ERROR_CHECK_ALLOC(backend->file.path);
521 0 0 if (path[0] == '~' && path[1] == '/')
0 0 if (path[0] == '~' && path[1] == '/')
534 0 43 assert(ptr);
537 0 43 if (!len)
540 0 43 if (git_buf_init(&buf, len) < 0)
543 550 43 while (*ptr != '\0') {
544 0 550 if ((esc = strchr(git_config_escaped, *ptr)) != NULL) {
553 0 43 if (git_buf_oom(&buf))
566 0 0 if (!file)
569 0 0 if ((result = git_path_dirname_r(&path, parse_data->file->path)) < 0)
576 0 0 if (result < 0)
579 0 0 include = git_array_alloc(parse_data->file->includes);
0 0 include = git_array_alloc(parse_data->file->includes);
580 0 0 GIT_ERROR_CHECK_ALLOC(include);
588 0 0 if (result == GIT_ENOTFOUND) {
606 0 0 if (condition[0] == '.' && git_path_is_dirsep(condition[1])) {
0 0 if (condition[0] == '.' && git_path_is_dirsep(condition[1])) {
609 0 0 } else if (condition[0] == '~' && git_path_is_dirsep(condition[1]))
0 0 } else if (condition[0] == '~' && git_path_is_dirsep(condition[1]))
611 0 0 else if (!git_path_is_absolute(condition))
616 0 0 if (git_path_is_dirsep(condition[strlen(condition) - 1]))
619 0 0 if (git_buf_oom(&pattern)) {
624 0 0 if ((error = git_repository_item_path(&gitdir, repo, GIT_REPOSITORY_ITEM_GITDIR)) < 0)
627 0 0 if (git_path_is_dirsep(gitdir.ptr[gitdir.size - 1]))
675 0 0 if ((error = git_buf_joinpath(&buf, git_repository_path(repo), GIT_HEAD_FILE)) < 0 ||
0 0 if ((error = git_buf_joinpath(&buf, git_repository_path(repo), GIT_HEAD_FILE)) < 0 ||
680 0 0 if (git__strncmp(reference.ptr, GIT_SYMREF, strlen(GIT_SYMREF)))
684 0 0 if (git__strncmp(reference.ptr, GIT_REFS_HEADS_DIR, strlen(GIT_REFS_HEADS_DIR)))
692 0 0 if ((error = git_buf_sets(&buf, condition)) < 0)
694 0 0 if (git_path_is_dirsep(condition[strlen(condition) - 1]) &&
0 0 if (git_path_is_dirsep(condition[strlen(condition) - 1]) &&
722 0 0 if (!parse_data->repo || !file)
0 0 if (!parse_data->repo || !file)
728 0 0 for (i = 0; i < ARRAY_SIZE(conditions); i++) {
729 0 0 if (git__prefixcmp(condition, conditions[i].prefix))
732 0 0 if ((error = conditions[i].matches(&matches,
738 0 0 if (matches)
767 1491 0 if (current_section) {
776 10869 1491 for (c = var_name; *c; c++)
779 0 1491 if (git_buf_oom(&buf))
783 0 1491 GIT_ERROR_CHECK_ALLOC(entry);
785 1491 0 entry->value = var_value ? git__strdup(var_value) : NULL;
789 0 1491 if ((result = git_config_entries_append(parse_data->entries, entry)) < 0)
795 0 1491 if (!git__strcmp(entry->name, "include.path"))
817 0 136 if (depth >= MAX_INCLUDE_DEPTH) {
827 136 0 if (!reader.ctx.content || *reader.ctx.content == '\0') {
5 131 if (!reader.ctx.content || *reader.ctx.content == '\0') {
855 0 87 if (p_stat(file->path, &st) < 0) {
860 0 87 if ((error = git_futils_readbuffer(&contents, file->path)) < 0)
864 0 87 if ((error = git_hash_buf(&file->checksum, contents.ptr, contents.size)) < 0)
867 0 87 if ((error = config_file_read_buffer(entries, repo, file, level, depth,
885 12 4 if (dot == NULL) {
891 0 4 GIT_ERROR_CHECK_ALLOC(escaped);
897 0 16 if (git_buf_oom(&buf))
910 44 0 if (value[0] == ' ' || value[0] == '\0')
0 44 if (value[0] == ' ' || value[0] == '\0')
913 632 44 for (ptr = value; *ptr; ++ptr) {
914 632 0 if (*ptr == ';' || *ptr == '#')
0 632 if (*ptr == ';' || *ptr == '#')
918 0 44 if (ptr[-1] == ' ')
941 571 0 if (!result && line_len && line[line_len-1] != '\n')
571 0 if (!result && line_len && line[line_len-1] != '\n')
0 571 if (!result && line_len && line[line_len-1] != '\n')
965 39 5 if (!write_data->preg)
988 7 171 if (write_data->in_section && !write_data->preg && write_data->value)
7 0 if (write_data->in_section && !write_data->preg && write_data->value)
2 5 if (write_data->in_section && !write_data->preg && write_data->value)
996 178 0 if (!result) {
1001 178 0 if (!result)
1026 0 401 if ((error = git_buf_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size)) < 0)
1032 61 340 if (write_data->in_section &&
9 52 if (write_data->in_section &&
1037 9 392 if (has_matched && write_data->preg != NULL)
1 8 if (has_matched && write_data->preg != NULL)
1043 393 8 if (!has_matched)
1049 5 3 if (!write_data->value)
1076 0 49 if ((result = git_buf_put(write_data->buf, write_data->buffered_comment.ptr, write_data->buffered_comment.size)) < 0)
1084 5 44 if ((!write_data->preg || !write_data->preg_replaced) && write_data->value) {
5 0 if ((!write_data->preg || !write_data->preg_replaced) && write_data->value) {
39 10 if ((!write_data->preg || !write_data->preg_replaced) && write_data->value) {
1086 33 6 if (!current_section || strcmp(current_section, write_data->section))
10 23 if (!current_section || strcmp(current_section, write_data->section))
1089 39 0 if (!result)
1111 0 49 if (cfg->locked) {
1112 0 0 error = git_buf_puts(&contents, git_buf_cstr(&cfg->locked_content) == NULL ? "" : git_buf_cstr(&cfg->locked_content));
1114 0 49 if ((error = git_filebuf_open(&file, cfg->file.path, GIT_FILEBUF_HASH_CONTENTS,
1121 1 48 if (error < 0 && error != GIT_ENOTFOUND)
0 1 if (error < 0 && error != GIT_ENOTFOUND)
1124 0 49 if ((git_config_parser_init(&parser, cfg->file.path, contents.ptr, contents.size)) < 0)
1130 0 49 GIT_ERROR_CHECK_ALLOC(section);
1135 0 49 GIT_ERROR_CHECK_ALLOC(orig_section);
1145 0 49 if ((error = git_config_parse(&parser, write_on_section, write_on_variable,
1149 0 49 if (cfg->locked) {
1157 0 49 if ((error = git_filebuf_commit(&file)) < 0)
1160 0 49 if ((error = config_file_refresh_from_buffer(&cfg->parent, buf.ptr, buf.size)) < 0)