Branch Coverage

deps/libgit2/src/refs.c
Criterion Covered Total %
branch 272 496 54.8


line true false branch
43 0 1314 if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) &&
1314 0 if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) &&
44 1314 0 !GIT_ADD_SIZET_OVERFLOW(&reflen, reflen, 1) &&
56 538 0 assert(name && target);
0 538 assert(name && target);
59 0 538 if (!ref)
64 0 538 if ((ref->target.symbolic = git__strdup(target)) == NULL) {
79 776 0 assert(name && oid);
0 776 assert(name && oid);
82 0 776 if (!ref)
88 0 776 if (peel != NULL)
100 1 0 assert(ptr_to_ref && name);
0 1 assert(ptr_to_ref && name);
104 0 1 if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) &&
1 0 if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) &&
105 1 0 !GIT_ADD_SIZET_OVERFLOW(&reflen, reflen, 1) &&
116 0 0 if (source->type == GIT_REFERENCE_SYMBOLIC)
121 0 0 GIT_ERROR_CHECK_ALLOC(*dest);
131 407 1308 if (reference == NULL)
134 536 772 if (reference->type == GIT_REFERENCE_SYMBOLIC)
137 1180 128 if (reference->db)
138 0 1180 GIT_REFCOUNT_DEC(reference->db, git_refdb__free);
0 0 GIT_REFCOUNT_DEC(reference->db, git_refdb__free);
148 0 6 if (!strcmp(ref->name, "HEAD")) {
153 4 2 if (ref->type == GIT_REFERENCE_DIRECT)
166 0 0 if ((error = git_repository_refdb__weakptr(&db, repo)) < 0)
184 50 155 if ((error = git_reference_lookup_resolved(&ref, repo, name, -1)) < 0)
201 1290 0 if (!git_repository__configmap_lookup(&precompose, repo, GIT_CONFIGMAP_PRECOMPOSE) &&
0 1290 if (!git_repository__configmap_lookup(&precompose, repo, GIT_CONFIGMAP_PRECOMPOSE) &&
205 0 1290 if (!validate)
223 1167 0 assert(ref_out && repo && name);
1167 0 assert(ref_out && repo && name);
0 1167 assert(ref_out && repo && name);
227 0 1167 if (max_nesting > MAX_NESTING_LEVEL)
229 557 610 else if (max_nesting < 0)
234 10 1157 if ((error = reference_normalize_for_repo(scan_name, repo, name, true)) < 0)
237 0 1157 if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0)
240 1674 558 for (nesting = max_nesting;
241 1230 444 nesting >= 0 && scan_type == GIT_REFERENCE_SYMBOLIC;
244 73 1157 if (nesting != max_nesting) {
249 155 1075 if ((error = git_refdb_lookup(&ref, refdb, scan_name)) < 0)
255 400 602 if (scan_type != GIT_REFERENCE_DIRECT && max_nesting != 0) {
0 400 if (scan_type != GIT_REFERENCE_DIRECT && max_nesting != 0) {
275 0 19 if ((error = git_futils_readbuffer(&reference, path)) < 0)
279 19 0 if (git__strncmp(reference.ptr, GIT_SYMREF, strlen(GIT_SYMREF)) == 0) {
284 0 19 if ((*out = git_reference__alloc_symbolic(name, reference.ptr)) == NULL) {
289 0 0 if ((error = git_reference_lookup(out, repo, reference.ptr)) < 0)
317 28 1 if (*refname)
324 107 12 for (i = 0; formatters[i] && (fallbackmode || i == 0); i++) {
106 1 for (i = 0; formatters[i] && (fallbackmode || i == 0); i++) {
1 0 for (i = 0; formatters[i] && (fallbackmode || i == 0); i++) {
328 0 107 if ((error = git_buf_printf(&refnamebuf, formatters[i], git_buf_cstr(&name))) < 0)
331 16 91 if (!git_reference_is_valid_name(git_buf_cstr(&refnamebuf))) {
339 17 74 if (!error) {
345 0 74 if (error != GIT_ENOTFOUND)
350 12 17 if (error && !foundvalid) {
0 12 if (error && !foundvalid) {
356 12 17 if (error == GIT_ENOTFOUND)
369 0 626 assert(ref);
375 0 209 assert(ref);
381 0 339 assert(ref);
387 0 393 assert(ref);
389 0 393 if (ref->type != GIT_REFERENCE_DIRECT)
397 0 0 assert(ref);
399 0 0 if (ref->type != GIT_REFERENCE_DIRECT || git_oid_is_zero(&ref->peel))
0 0 if (ref->type != GIT_REFERENCE_DIRECT || git_oid_is_zero(&ref->peel))
407 0 353 assert(ref);
409 0 353 if (ref->type != GIT_REFERENCE_SYMBOLIC)
432 99 0 assert(repo && name);
0 99 assert(repo && name);
433 76 23 assert(symbolic || signature);
0 76 assert(symbolic || signature);
435 97 2 if (ref_out)
439 0 99 if (error < 0)
443 0 99 if (error < 0)
446 76 23 if (oid != NULL) {
447 0 76 assert(symbolic == NULL);
449 0 76 if (!git_object__is_valid(repo, oid, GIT_OBJECT_ANY)) {
462 0 23 if (error < 0)
468 0 99 GIT_ERROR_CHECK_ALLOC(ref);
470 2 97 if ((error = git_refdb_write(refdb, ref, force, signature, log_message, old_id, old_target)) < 0) {
475 2 95 if (ref_out == NULL)
485 0 69 if (repo->ident_name && repo->ident_email)
0 0 if (repo->ident_name && repo->ident_email)
497 69 0 if(((error = configured_ident(&who, repo)) < 0) &&
7 62 if(((error = configured_ident(&who, repo)) < 0) &&
498 0 7 ((error = git_signature_default(&who, repo)) < 0) &&
519 0 41 assert(id);
521 0 41 if ((error = git_reference__log_signature(&who, repo)) < 0)
554 0 23 assert(target);
556 0 23 if ((error = git_reference__log_signature(&who, repo)) < 0)
579 27 0 if (ref->type == GIT_REFERENCE_DIRECT)
595 1 0 assert(out && ref && id);
1 0 assert(out && ref && id);
0 1 assert(out && ref && id);
599 0 1 if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0)
607 0 0 if (ref->type == GIT_REFERENCE_SYMBOLIC)
622 0 0 assert(out && ref && target);
0 0 assert(out && ref && target);
0 0 assert(out && ref && target);
624 0 0 if ((error = ensure_is_an_updatable_symbolic_reference(ref)) < 0)
643 0 1 if ((error = git_reference__read_head(&head, repo, path)) < 0) {
648 0 1 if ((gitdir = git_path_dirname(path)) == NULL) {
653 1 0 if (git_reference_type(head) != GIT_REFERENCE_SYMBOLIC ||
1 0 if (git_reference_type(head) != GIT_REFERENCE_SYMBOLIC ||
660 0 0 if ((error = git_repository_create_head(gitdir, data->new_name)) < 0) {
680 1 0 assert(ref && new_name && signature);
1 0 assert(ref && new_name && signature);
0 1 assert(ref && new_name && signature);
684 0 1 if ((error = reference_normalize_for_repo(
689 0 1 if ((error = git_branch_is_head(ref)) < 0)
694 0 1 if ((error = git_refdb_rename(out, ref->db, ref->name, normalized, force, signature, message)) < 0)
698 0 1 if (should_head_be_updated) {
722 1 0 assert(out && ref);
0 1 assert(out && ref);
724 0 1 if ((error = git_reference__log_signature(&who, ref->db->repo)) < 0)
757 0 0 if ((error = git_reference_iterator_new(&iter, repo)) < 0)
760 0 0 while (!(error = git_reference_next(&ref, iter))) {
761 0 0 if ((error = callback(ref, payload)) != 0) {
767 0 0 if (error == GIT_ITEROVER)
783 0 23 if ((error = git_reference_iterator_new(&iter, repo)) < 0)
786 115 22 while (!(error = git_reference_next_name(&refname, iter))) {
787 1 114 if ((error = callback(refname, payload)) != 0) {
793 22 1 if (error == GIT_ITEROVER)
810 0 0 if ((error = git_reference_iterator_glob_new(&iter, repo, glob)) < 0)
813 0 0 while (!(error = git_reference_next_name(&refname, iter))) {
814 0 0 if ((error = callback(refname, payload)) != 0) {
820 0 0 if (error == GIT_ITEROVER)
831 0 29 if (git_repository_refdb__weakptr(&refdb, repo) < 0)
842 0 3 if (git_repository_refdb__weakptr(&refdb, repo) < 0)
860 0 32 if (iter == NULL)
869 0 2 GIT_ERROR_CHECK_ALLOC(name);
879 4 0 assert(array && repo);
0 4 assert(array && repo);
884 0 4 if (git_vector_init(&ref_list, 8, NULL) < 0)
887 0 4 if (git_reference_foreach_name(
900 0 18787 if ((unsigned) ch <= ' ')
903 0 18787 switch (ch) {
923 0 3328 if (*current == '.')
927 20629 1486 if (*current == '\0' || *current == '/')
18787 1842 if (*current == '\0' || *current == '/')
930 0 18787 if (!is_valid_ref_char(*current))
933 36 18751 if (prev == '.' && *current == '.')
0 36 if (prev == '.' && *current == '.')
936 0 18787 if (prev == '@' && *current == '{')
0 0 if (prev == '@' && *current == '{')
939 26 18761 if (*current == '*') {
940 0 26 if (!may_contain_glob)
951 1581 1747 if (segment_len >= lock_len &&
0 1581 if (segment_len >= lock_len &&
963 1486 0 assert(name && len > 0);
0 1486 assert(name && len > 0);
965 3136 550 for (i = 0; i < len; i++)
968 3135 1 if ((c < 'A' || c > 'Z') && c != '_')
935 2200 if ((c < 'A' || c > 'Z') && c != '_')
936 0 if ((c < 'A' || c > 'Z') && c != '_')
972 550 0 if (*name == '_' || name[len - 1] == '_')
0 550 if (*name == '_' || name[len - 1] == '_')
994 0 1486 assert(name);
999 1486 0 if (validate && *current == '/')
0 1486 if (validate && *current == '/')
1002 1291 195 if (normalize)
1015 0 1486 if (!validate) {
1018 0 0 error = git_buf_oom(buf) ? -1 : 0;
1026 0 3328 if (segment_len < 0)
1029 3328 0 if (segment_len > 0) {
1034 26 3302 if (memchr(current, '*', segment_len))
1037 2740 588 if (normalize) {
1041 1449 1291 git_buf_truncate(buf,
1044 0 2740 if (git_buf_oom(buf)) {
1054 0 3328 if (segment_len == 0 && !normalize)
0 0 if (segment_len == 0 && !normalize)
1057 1486 1842 if (current[segment_len] == '\0')
1064 0 1486 if (segment_len == 0 && segments_count == 0)
0 0 if (segment_len == 0 && segments_count == 0)
1068 0 1486 if (current[segment_len - 1] == '.')
1072 0 1486 if (current[segment_len - 1] == '/')
1075 576 910 if ((segments_count == 1 ) && !(flags & GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL))
0 576 if ((segments_count == 1 ) && !(flags & GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL))
1078 576 910 if ((segments_count == 1 ) &&
576 0 if ((segments_count == 1 ) &&
1079 26 550 !(flags & GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND) &&
1080 0 26 !(is_all_caps_and_underscore(name, (size_t)segment_len) ||
1081 0 0 ((flags & GIT_REFERENCE_FORMAT_REFSPEC_PATTERN) && !strcmp("*", name))))
1084 910 550 if ((segments_count > 1)
1085 0 910 && (is_all_caps_and_underscore(name, strchr(name, '/') - name)))
1091 26 1460 if (error == GIT_EINVALIDSPEC)
1096 26 1460 if (error && normalize)
10 16 if (error && normalize)
1115 10 1280 if ((error = git_reference__normalize_name(&buf, name, flags)) < 0)
1118 0 1280 if (git_buf_len(&buf) > buffer_size - 1) {
1142 0 0 assert(ref1 && ref2);
0 0 assert(ref1 && ref2);
1148 0 0 if (type1 != type2)
1149 0 0 return (type1 == GIT_REFERENCE_SYMBOLIC) ? -1 : 1;
1151 0 0 if (type1 == GIT_REFERENCE_SYMBOLIC)
1166 0 13 if (nesting > MAX_NESTING_LEVEL) {
1172 4 9 if ((error = git_reference_lookup(&ref, repo, ref_name)) < 0) {
1177 5 4 if (git_reference_type(ref) == GIT_REFERENCE_DIRECT) {
1182 3 1 if (error == GIT_ENOTFOUND && !*out)
3 0 if (error == GIT_ENOTFOUND && !*out)
1208 2 7 if (!sig && (error = git_reference__log_signature(&who, repo)) < 0)
0 2 if (!sig && (error = git_reference__log_signature(&who, repo)) < 0)
1211 7 2 to_use = sig ? sig : who;
1215 4 5 if (error == GIT_ENOTFOUND && ref) {
3 1 if (error == GIT_ENOTFOUND && ref) {
1216 0 3 assert(git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC);
1220 1 5 } else if (error == GIT_ENOTFOUND) {
1224 5 0 } else if (error == 0) {
1225 0 5 assert(git_reference_type(ref) == GIT_REFERENCE_DIRECT);
1240 1 32 if (count >= 2)
1242 4 28 else if (count == 0)
1261 33 0 if ((error = git_commit_lookup(&commit, repo, id)) < 0 ||
33 0 if ((error = git_commit_lookup(&commit, repo, id)) < 0 ||
1262 33 0 (error = git_buf_printf(&reflog_msg, "%s%s: %s",
1270 26 7 if (ref) {
1271 0 26 if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0)
1293 0 0 assert(repo && refname);
0 0 assert(repo && refname);
1295 0 0 if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0)
1306 6 0 assert(repo && refname);
0 6 assert(repo && refname);
1308 0 6 if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0)
1321 0 65 assert(ref);
1332 0 7 assert(ref);
1343 0 7 assert(ref);
1354 0 7 assert(ref);
1376 0 210 assert(ref);
1378 200 10 if (ref->type == GIT_REFERENCE_DIRECT) {
1381 0 10 if ((error = git_reference_resolve(&allocated, ref)) < 0)
1393 210 0 if (target_type != GIT_OBJECT_TAG && !git_oid_is_zero(&resolved->peel)) {
0 210 if (target_type != GIT_OBJECT_TAG && !git_oid_is_zero(&resolved->peel)) {
1401 0 210 if (error < 0) {
1406 0 210 if (target_type == GIT_OBJECT_ANY && git_object_type(target) != GIT_OBJECT_TAG)
0 0 if (target_type == GIT_OBJECT_ANY && git_object_type(target) != GIT_OBJECT_TAG)
1420 16 179 if (git_reference__normalize_name(NULL, refname, flags) < 0) {
1435 41 1 if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR))
1437 0 1 else if (!git__prefixcmp(name, GIT_REFS_TAGS_DIR))
1439 0 1 else if (!git__prefixcmp(name, GIT_REFS_REMOTES_DIR))
1441 1 0 else if (!git__prefixcmp(name, GIT_REFS_DIR))
1457 5 0 assert(unborn && ref && repo);
5 0 assert(unborn && ref && repo);
0 5 assert(unborn && ref && repo);
1459 0 5 if (ref->type == GIT_REFERENCE_DIRECT) {
1467 0 5 if (error != 0 && error != GIT_ENOTFOUND)
0 0 if (error != 0 && error != GIT_ENOTFOUND)
1469 0 5 else if (error == GIT_ENOTFOUND && git__strcmp(ref->name, GIT_HEAD_FILE) == 0)
0 0 else if (error == GIT_ENOTFOUND && git__strcmp(ref->name, GIT_HEAD_FILE) == 0)