Branch Coverage

deps/libgit2/src/libgit2/index.c
Criterion Covered Total %
branch 577 1228 46.9


line true false branch
130 0 173 if (ignore_case)
138 0 217 if (ignore_case)
146 0 43 if (ignore_case)
164 2802 331 if (cmp)
166 176 155 if (len1 < len2)
168 39 116 if (len1 > len2)
171 112 4 if (srch_key->stage != GIT_INDEX_STAGE_ANY)
190 0 0 if (cmp)
192 0 0 if (len1 < len2)
194 0 0 if (len1 > len2)
197 0 0 if (srch_key->stage != GIT_INDEX_STAGE_ANY)
225 118 121 if (diff == 0)
239 0 0 if (diff == 0)
250 0 0 if (name_a->ancestor && !name_b->ancestor)
0 0 if (name_a->ancestor && !name_b->ancestor)
253 0 0 if (!name_a->ancestor && name_b->ancestor)
0 0 if (!name_a->ancestor && name_b->ancestor)
256 0 0 if (name_a->ancestor)
259 0 0 if (!name_a->ours || !name_b->ours)
0 0 if (!name_a->ours || !name_b->ours)
327 0 228 if (!entry)
336 1 279 if (S_ISLNK(mode))
339 279 0 if (S_ISDIR(mode) || (mode & S_IFMT) == (S_IFLNK | S_IFDIR))
0 279 if (S_ISDIR(mode) || (mode & S_IFMT) == (S_IFLNK | S_IFDIR))
342 1 278 return S_IFREG | GIT_PERMS_CANONICAL(mode);
348 0 50 if (index->no_symlinks && S_ISREG(mode) &&
0 0 if (index->no_symlinks && S_ISREG(mode) &&
0 0 if (index->no_symlinks && S_ISREG(mode) &&
349 0 0 existing && S_ISLNK(existing->mode))
352 0 50 if (index->distrust_filemode && S_ISREG(mode))
0 0 if (index->distrust_filemode && S_ISREG(mode))
353 0 0 return (existing && S_ISREG(existing->mode)) ?
354 0 0 existing->mode : git_index__create_mode(0666);
365 1517 220 srch_key.pathlen = !path_len ? strlen(path) : path_len;
384 0 6 if (ignore_case) {
396 0 6 git_vector_set_cmp(&index->entries,
400 0 6 git_vector_set_cmp(&index->reuc, ignore_case ? reuc_icmp : reuc_cmp);
409 0 47 GIT_ASSERT_ARG(index_out);
412 0 47 GIT_ERROR_CHECK_ALLOC(index);
414 0 47 if (git_pool_init(&index->tree_pool, 1) < 0)
417 16 31 if (index_path != NULL) {
419 0 16 if (!index->index_file_path)
423 10 6 if (git_fs_path_exists(index->index_file_path) == true)
428 47 0 git_idxmap_new(&index->entries_map) < 0 ||
429 47 0 git_vector_init(&index->names, 8, conflict_name_cmp) < 0 ||
430 47 0 git_vector_init(&index->reuc, 8, reuc_cmp) < 0 ||
440 16 31 if (index_path != NULL && (error = git_index_read(index, true)) < 0)
0 16 if (index_path != NULL && (error = git_index_read(index, true)) < 0)
464 0 47 if (git_atomic32_get(&index->readers))
482 109 806 if (index == NULL)
485 47 759 GIT_REFCOUNT_DEC(index, index_free);
47 0 GIT_REFCOUNT_DEC(index, index_free);
494 71 0 if (readers > 0 || !index->deleted.length)
65 6 if (readers > 0 || !index->deleted.length)
497 6 6 for (i = 0; i < index->deleted.length; ++i) {
511 167 0 if (entry != NULL) {
518 167 0 if (!error) {
519 6 161 if (git_atomic32_get(&index->readers) > 0) {
535 0 71 GIT_ASSERT_ARG(index);
542 211 0 while (!error && index->entries.length > 0)
140 71 while (!error && index->entries.length > 0)
545 0 71 if (error)
550 71 0 if ((error = git_index_name_clear(index)) < 0 ||
71 0 if ((error = git_index_name_clear(index)) < 0 ||
570 0 16 GIT_ASSERT_ARG(index);
574 16 0 if (caps == GIT_INDEX_CAPABILITY_FROM_OWNER) {
578 0 16 if (!repo)
582 16 0 if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_IGNORECASE))
584 16 0 if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_FILEMODE))
586 16 0 if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_SYMLINKS))
595 0 16 if (old_ignore_case != index->ignore_case) {
605 0 1 (index->distrust_filemode ? GIT_INDEX_CAPABILITY_NO_FILEMODE : 0) |
606 0 1 (index->no_symlinks ? GIT_INDEX_CAPABILITY_NO_SYMLINKS : 0));
626 0 135 if ((fd = p_open(index->index_file_path, O_RDONLY)) < 0)
629 0 135 if (p_lseek(fd, (0 - (ssize_t)checksum_size), SEEK_END) < 0) {
638 0 135 if (bytes_read < (ssize_t)checksum_size)
650 0 152 if (!index->index_file_path)
656 17 135 if (!index->on_disk) {
657 6 11 if (force && (error = git_index_clear(index)) < 0)
0 6 if (force && (error = git_index_clear(index)) < 0)
664 135 0 if ((updated = git_futils_filestamp_check(&stamp, index->index_file_path) < 0) ||
0 135 if ((updated = git_futils_filestamp_check(&stamp, index->index_file_path) < 0) ||
673 125 10 if (!updated && !force)
124 1 if (!updated && !force)
677 0 11 if (error < 0)
685 11 0 if (!error)
688 11 0 if (!error) {
699 0 91 if (git_index__enforce_unsaved_safety && index->dirty) {
0 0 if (git_index__enforce_unsaved_safety && index->dirty) {
711 0 111 if (S_ISGITLINK(entry->mode))
732 0 83 if (!INDEX_OWNER(index))
736 0 83 if (!git_repository_workdir(INDEX_OWNER(index)))
740 171 83 git_vector_foreach(&index->entries, i, entry) {
746 65 18 if (paths.length == 0)
752 0 18 if ((error = git_diff_index_to_workdir(&diff, INDEX_OWNER(index), index, &diff_opts)) < 0)
755 0 18 git_vector_foreach(&diff->deltas, i, delta) {
761 0 0 if (entry) {
775 0 3 GIT_ASSERT_ARG(index);
782 0 1 GIT_ASSERT_ARG(index);
784 1 0 if (version < INDEX_VERSION_NUMBER_LB ||
0 1 if (version < INDEX_VERSION_NUMBER_LB ||
802 83 0 if ((error = git_indexwriter_init(&writer, index)) == 0 &&
83 0 if ((error = git_indexwriter_init(&writer, index)) == 0 &&
813 0 3 GIT_ASSERT_ARG_WITH_RETVAL(index, NULL);
821 0 38 GIT_ASSERT_ARG(oid);
822 0 38 GIT_ASSERT_ARG(index);
826 0 38 if (repo == NULL)
836 0 18 GIT_ASSERT_ARG(oid);
837 0 18 GIT_ASSERT_ARG(index);
838 0 18 GIT_ASSERT_ARG(repo);
845 0 270 GIT_ASSERT_ARG(index);
853 0 419 GIT_ASSERT_ARG_WITH_RETVAL(index, NULL);
865 0 182 GIT_ASSERT_ARG_WITH_RETVAL(index, NULL);
870 0 182 if (index->ignore_case)
875 23 159 if (!value) {
894 0 0 entry->mode = (!trust_mode && S_ISREG(st->st_mode)) ?
895 0 91 git_index__create_mode(0666) : git_index__create_mode(st->st_mode);
907 200 0 if (path_length < GIT_INDEX_ENTRY_NAMEMASK)
935 52 176 if (from_workdir)
937 52 176 if (st)
940 0 228 if (!git_path_is_valid(repo, path, mode, path_valid_flags)) {
945 0 228 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(struct entry_internal), pathlen);
0 228 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(struct entry_internal), pathlen);
946 0 228 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
0 228 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
948 0 228 GIT_ERROR_CHECK_ALLOC(entry);
970 0 52 if (INDEX_OWNER(index) == NULL)
981 0 52 if (git_repository__ensure_not_bare(repo, "create blob from file") < 0)
984 0 52 if (git_repository_workdir_path(&path, repo, rel_path) < 0)
990 0 52 if (error < 0)
993 0 52 if (index_entry_create(&entry, INDEX_OWNER(index), rel_path, &st, true) < 0)
1000 2 50 if (error < 0) {
1019 0 10 if (GIT_ADD_SIZET_OVERFLOW(&alloclen, structlen, pathlen) ||
0 10 if (GIT_ADD_SIZET_OVERFLOW(&alloclen, structlen, pathlen) ||
1024 0 10 if (!entry)
1042 0 10 GIT_ASSERT_ARG(reuc_out);
1043 0 10 GIT_ASSERT_ARG(path);
1046 0 10 GIT_ERROR_CHECK_ALLOC(reuc);
1048 10 0 if ((reuc->mode[0] = ancestor_mode) > 0) {
1049 0 10 GIT_ASSERT(ancestor_oid);
1053 8 2 if ((reuc->mode[1] = our_mode) > 0) {
1054 0 8 GIT_ASSERT(our_oid);
1058 6 4 if ((reuc->mode[2] = their_mode) > 0) {
1059 0 6 GIT_ASSERT(their_oid);
1080 0 165 if (index_entry_create(out, INDEX_OWNER(index), src->path, NULL, false) < 0)
1102 0 2 if (index_entry_create(out, INDEX_OWNER(index), src->path, NULL, false) < 0)
1116 109 18 while (pos < index->entries.length) {
1119 105 4 if (len >= p->pathlen)
1121 3 1 if (memcmp(name, p->path, len))
1123 0 1 if (GIT_INDEX_ENTRY_STAGE(&p->entry) != stage)
1125 1 0 if (p->path[len] != '/')
1127 0 0 if (!ok_to_replace)
1130 0 0 if (index_remove_entry(index, --pos) < 0)
1151 13 834 if (*--slash == '/')
1153 124 710 if (slash <= entry->path)
1158 0 13 if (!index_find(&pos, index, name, len, stage)) {
1159 0 0 if (!ok_to_replace)
1162 0 0 if (index_remove_entry(index, pos) < 0)
1172 7 6 for (; pos < index->entries.length; ++pos) {
1175 7 0 if (p->pathlen <= len ||
2 5 if (p->pathlen <= len ||
1176 2 0 p->path[len] != '/' ||
1180 2 0 if (GIT_INDEX_ENTRY_STAGE(&p->entry) == stage)
1210 50 0 if (!index->ignore_case)
1214 0 0 if (existing) {
1220 0 0 if (strchr(entry->path, '/') == NULL)
1223 0 0 if ((search = git__strdup(entry->path)) == NULL)
1229 0 0 while (!best && (sep = strrchr(search, '/'))) {
0 0 while (!best && (sep = strrchr(search, '/'))) {
1237 0 0 while ((match = git_vector_get(&index->entries, pos))) {
1238 0 0 if (GIT_INDEX_ENTRY_STAGE(match) != 0) {
1240 0 0 } else if (strncmp(search, match->path, search_len) == 0) {
1245 0 0 } else if (strncasecmp(search, match->path, search_len) == 0) {
1250 0 0 if (!best) {
1264 0 0 if (best)
1294 57 69 if (error == 0) {
1305 43 26 if (GIT_INDEX_ENTRY_STAGE(entry) == 0) {
1306 19 26 for (; pos < index->entries.length; pos++) {
1308 0 19 index->ignore_case ? git__strcasecmp : git__strcmp;
1312 15 4 if (strcomp(entry->path, e->path) != 0)
1315 2 2 if (GIT_INDEX_ENTRY_STAGE(e) == GIT_INDEX_STAGE_ANCESTOR) {
1351 0 126 GIT_ASSERT_ARG(index);
1352 0 126 GIT_ASSERT_ARG(entry_ptr);
1373 76 50 git_index__create_mode(entry->mode) :
1377 50 76 if (!trust_path && (error = canonicalize_directory_path(index, entry, best)) < 0)
0 50 if (!trust_path && (error = canonicalize_directory_path(index, entry, best)) < 0)
1381 69 57 if (!trust_id && INDEX_OWNER(index) &&
43 26 if (!trust_id && INDEX_OWNER(index) &&
43 0 if (!trust_id && INDEX_OWNER(index) &&
1384 0 43 if (!git_object__is_valid(INDEX_OWNER(index), &entry->id,
1392 0 126 if ((error = check_file_directory_collision(index, entry, position, replace)) < 0)
1399 57 69 if (existing) {
1400 57 0 if (replace) {
1403 30 27 if (trust_path)
1415 69 0 if ((error = git_vector_insert_sorted(&index->entries, entry, index_no_dups)) < 0 ||
69 0 if ((error = git_vector_insert_sorted(&index->entries, entry, index_no_dups)) < 0 ||
1423 0 126 if (error < 0) {
1438 61 2 if ((ret = git_index_conflict_get(&conflict_entries[0],
1442 2 0 ancestor_mode = conflict_entries[0] == NULL ? 0 : conflict_entries[0]->mode;
1443 2 0 our_mode = conflict_entries[1] == NULL ? 0 : conflict_entries[1]->mode;
1444 2 0 their_mode = conflict_entries[2] == NULL ? 0 : conflict_entries[2]->mode;
1446 2 0 ancestor_oid = conflict_entries[0] == NULL ? NULL : &conflict_entries[0]->id;
1447 2 0 our_oid = conflict_entries[1] == NULL ? NULL : &conflict_entries[1]->id;
1448 2 0 their_oid = conflict_entries[2] == NULL ? NULL : &conflict_entries[2]->id;
1450 2 0 if ((ret = git_index_reuc_add(index, path, ancestor_mode, ancestor_oid,
1459 3 1 return (filemode == GIT_FILEMODE_BLOB ||
1460 4 74 filemode == GIT_FILEMODE_BLOB_EXECUTABLE ||
1 2 filemode == GIT_FILEMODE_BLOB_EXECUTABLE ||
1466 0 69 return (is_file_or_link(filemode) || filemode == GIT_FILEMODE_COMMIT);
0 0 return (is_file_or_link(filemode) || filemode == GIT_FILEMODE_COMMIT);
1477 0 9 GIT_ASSERT_ARG(index);
1478 9 0 GIT_ASSERT_ARG(source_entry && source_entry->path);
0 9 GIT_ASSERT_ARG(source_entry && source_entry->path);
1480 0 9 if (INDEX_OWNER(index) == NULL)
1485 2 7 if (!is_file_or_link(source_entry->mode)) {
1490 0 7 if (len > UINT32_MAX) {
1495 0 7 if (index_entry_dup(&entry, index, source_entry) < 0)
1499 0 7 if (error < 0) {
1507 0 7 if ((error = index_insert(index, &entry, 1, true, true, true)) < 0)
1511 7 0 if ((error = index_conflict_to_reuc(index, entry->path)) < 0 && error != GIT_ENOTFOUND)
0 7 if ((error = index_conflict_to_reuc(index, entry->path)) < 0 && error != GIT_ENOTFOUND)
1528 0 0 if ((error = git_repository_workdir_path(&abspath, repo, path)) < 0)
1531 0 0 if ((error = p_stat(abspath.ptr, &st)) < 0) {
1536 0 0 if (index_entry_create(&entry, INDEX_OWNER(index), path, &st, true) < 0)
1541 0 0 if ((error = git_repository_open(&sub, abspath.ptr)) < 0)
1544 0 0 if ((error = git_repository_head(&head, sub)) < 0)
1563 0 52 GIT_ASSERT_ARG(index);
1564 0 52 GIT_ASSERT_ARG(path);
1566 50 2 if ((ret = index_entry_init(&entry, index, path)) == 0)
1570 2 50 if (ret < 0 && ret != GIT_EDIRECTORY)
2 0 if (ret < 0 && ret != GIT_EDIRECTORY)
1573 0 50 if (ret == GIT_EDIRECTORY) {
1580 0 0 if (ret == GIT_ENOTFOUND)
1589 0 0 if (ret == GIT_EEXISTS) {
1590 0 0 if ((ret = add_repo_as_submodule(&entry, index, path)) < 0)
1593 0 0 if ((ret = index_insert(index, &entry, 1, false, false, true)) < 0)
1595 0 0 } else if (ret < 0) {
1605 48 2 if ((ret = index_conflict_to_reuc(index, path)) < 0 && ret != GIT_ENOTFOUND)
0 48 if ((ret = index_conflict_to_reuc(index, path)) < 0 && ret != GIT_ENOTFOUND)
1616 0 6 GIT_ASSERT_ARG(index);
1617 0 6 GIT_ASSERT_ARG(path);
1619 0 6 if (((ret = git_index_remove(index, path, 0)) < 0 &&
0 0 if (((ret = git_index_remove(index, path, 0)) < 0 &&
1620 6 0 ret != GIT_ENOTFOUND) ||
1621 0 6 ((ret = index_conflict_to_reuc(index, path)) < 0 &&
1625 6 0 if (ret == GIT_ENOTFOUND)
1637 0 28 GIT_ASSERT_ARG(index);
1639 3 25 if (!source_entries->length)
1647 63 25 git_vector_foreach(source_entries, i, source_entry) {
1650 0 63 if ((error = index_entry_dup(&entry, index, source_entry)) < 0)
1657 0 63 if ((error = git_vector_insert(&index->entries, entry)) < 0)
1660 0 63 if ((error = index_map_set(index->entries_map, entry, index->ignore_case)) < 0)
1666 25 0 if (!error)
1678 0 52 GIT_ASSERT_ARG(index);
1679 52 0 GIT_ASSERT_ARG(source_entry && source_entry->path);
0 52 GIT_ASSERT_ARG(source_entry && source_entry->path);
1681 0 52 if (!valid_filemode(source_entry->mode)) {
1686 52 0 if ((ret = index_entry_dup(&entry, index, source_entry)) < 0 ||
0 52 if ((ret = index_entry_dup(&entry, index, source_entry)) < 0 ||
1705 35 15 if (index_find(&position, index, path, 0, stage) < 0) {
1723 1 0 if (!(error = git_str_sets(&pfx, dir)) &&
1 0 if (!(error = git_str_sets(&pfx, dir)) &&
1727 1 0 while (!error) {
1729 1 0 if (!entry || git__prefixcmp(entry->path, pfx.ptr) != 0)
0 1 if (!entry || git__prefixcmp(entry->path, pfx.ptr) != 0)
1732 0 0 if (GIT_INDEX_ENTRY_STAGE(entry) != stage) {
1755 0 0 if (!entry || git__prefixcmp(entry->path, prefix) != 0)
0 0 if (!entry || git__prefixcmp(entry->path, prefix) != 0)
1758 0 0 if (!error && at_pos)
0 0 if (!error && at_pos)
1767 0 1332 GIT_ASSERT_ARG(index);
1768 0 1332 GIT_ASSERT_ARG(path);
1776 0 71 GIT_ASSERT_ARG(index);
1777 0 71 GIT_ASSERT_ARG(path);
1779 7 64 if (git_vector_bsearch2(
1788 28 49 for (; pos > 0; --pos) {
1791 15 13 if (index->entries_cmp_path(prev->path, path) != 0)
1795 64 0 if (at_pos)
1810 0 6 GIT_ASSERT_ARG(index);
1812 6 0 if ((ancestor_entry &&
6 0 if ((ancestor_entry &&
1813 5 1 (ret = index_entry_dup(&entries[0], index, ancestor_entry)) < 0) ||
1814 5 0 (our_entry &&
1815 6 0 (ret = index_entry_dup(&entries[1], index, our_entry)) < 0) ||
1816 6 0 (their_entry &&
1821 18 6 for (i = 0; i < 3; i++) {
1822 17 1 if (entries[i] && !valid_filemode(entries[i]->mode)) {
0 17 if (entries[i] && !valid_filemode(entries[i]->mode)) {
1831 18 6 for (i = 0; i < 3; i++) {
1832 1 17 if (entries[i] == NULL)
1835 17 0 if ((ret = git_index_remove(index, entries[i]->path, 0)) != 0) {
1836 0 17 if (ret != GIT_ENOTFOUND)
1845 18 6 for (i = 0; i < 3; i++) {
1846 1 17 if (entries[i] == NULL)
1852 0 17 if ((ret = index_insert(index, &entries[i], 1, true, true, false)) < 0)
1861 0 0 for (i = 0; i < 3; i++) {
1862 0 0 if (entries[i] != NULL)
1881 0 62 GIT_ASSERT_ARG(ancestor_out);
1882 0 62 GIT_ASSERT_ARG(our_out);
1883 0 62 GIT_ASSERT_ARG(their_out);
1884 0 62 GIT_ASSERT_ARG(index);
1890 108 32 for (count = git_index_entrycount(index); n < count; ++n) {
1893 46 62 if (path && index->entries_cmp_path(conflict_entry->path, path) != 0)
30 16 if (path && index->entries_cmp_path(conflict_entry->path, path) != 0)
1930 0 64 GIT_ASSERT_ARG(ancestor_out);
1931 0 64 GIT_ASSERT_ARG(our_out);
1932 0 64 GIT_ASSERT_ARG(their_out);
1933 0 64 GIT_ASSERT_ARG(index);
1934 0 64 GIT_ASSERT_ARG(path);
1940 6 58 if (git_index_find(&pos, index, path) < 0)
1943 0 58 if ((len = index_conflict__get_byindex(
1946 55 3 else if (len == 0)
1958 5 1 if (path != NULL && git_index_find(&pos, index, path) < 0)
0 5 if (path != NULL && git_index_find(&pos, index, path) < 0)
1961 16 5 while ((conflict_entry = git_vector_get(&index->entries, pos)) != NULL) {
1967 3 12 if (GIT_INDEX_ENTRY_STAGE(conflict_entry) == 0) {
1972 0 12 if ((error = index_remove_entry(index, pos)) < 0)
1981 0 5 GIT_ASSERT_ARG(index);
1982 0 5 GIT_ASSERT_ARG(path);
1988 0 1 GIT_ASSERT_ARG(index);
1997 0 123 GIT_ASSERT_ARG(index);
1999 291 115 git_vector_foreach(&index->entries, i, entry) {
2000 8 283 if (GIT_INDEX_ENTRY_STAGE(entry) > 0)
2014 0 0 GIT_ASSERT_ARG(iterator_out);
2015 0 0 GIT_ASSERT_ARG(index);
2018 0 0 GIT_ERROR_CHECK_ALLOC(it);
2020 0 0 if ((error = git_index_snapshot_new(&it->snap, index)) < 0) {
2035 0 0 GIT_ASSERT_ARG(out);
2036 0 0 GIT_ASSERT_ARG(it);
2038 0 0 if (it->cur >= git_vector_length(&it->snap))
2047 0 0 if (it == NULL)
2060 0 69 GIT_ASSERT_ARG(iterator_out);
2061 0 69 GIT_ASSERT_ARG(index);
2064 0 69 GIT_ERROR_CHECK_ALLOC(it);
2081 0 73 GIT_ASSERT_ARG(ancestor_out);
2082 0 73 GIT_ASSERT_ARG(our_out);
2083 0 73 GIT_ASSERT_ARG(their_out);
2084 0 73 GIT_ASSERT_ARG(iterator);
2090 144 69 while (iterator->cur < iterator->index->entries.length) {
2093 4 140 if (git_index_entry_is_conflict(entry)) {
2094 0 4 if ((len = index_conflict__get_byindex(
2114 0 69 if (iterator == NULL)
2122 0 17 GIT_ASSERT_ARG(index);
2129 0 0 GIT_ASSERT_ARG_WITH_RETVAL(index, NULL);
2137 0 0 if (!ne)
2150 0 0 GIT_ASSERT_ARG((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
0 0 GIT_ASSERT_ARG((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
0 0 GIT_ASSERT_ARG((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
0 0 GIT_ASSERT_ARG((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
0 0 GIT_ASSERT_ARG((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
0 0 GIT_ASSERT_ARG((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
2153 0 0 GIT_ERROR_CHECK_ALLOC(conflict_name);
2155 0 0 if ((ancestor && !(conflict_name->ancestor = git__strdup(ancestor))) ||
0 0 if ((ancestor && !(conflict_name->ancestor = git__strdup(ancestor))) ||
0 0 if ((ancestor && !(conflict_name->ancestor = git__strdup(ancestor))) ||
2156 0 0 (ours && !(conflict_name->ours = git__strdup(ours))) ||
0 0 (ours && !(conflict_name->ours = git__strdup(ours))) ||
2173 0 123 GIT_ASSERT_ARG(index);
2175 0 123 git_vector_foreach(&index->names, i, conflict_name)
2187 0 0 GIT_ASSERT_ARG(index);
2204 0 10 GIT_ASSERT_ARG(index);
2205 10 0 GIT_ASSERT_ARG(reuc && reuc->path != NULL);
0 10 GIT_ASSERT_ARG(reuc && reuc->path != NULL);
2206 0 10 GIT_ASSERT(git_vector_is_sorted(&index->reuc));
2211 6 4 return res == GIT_EEXISTS ? 0 : res;
2222 0 10 GIT_ASSERT_ARG(index);
2223 0 10 GIT_ASSERT_ARG(path);
2225 10 0 if ((error = index_entry_reuc_init(&reuc, path, ancestor_mode,
2226 0 10 ancestor_oid, our_mode, our_oid, their_mode, their_oid)) < 0 ||
2243 0 6 GIT_ASSERT_ARG_WITH_RETVAL(index, NULL);
2244 0 6 GIT_ASSERT_ARG_WITH_RETVAL(path, NULL);
2246 2 4 if (!index->reuc.length)
2249 0 4 GIT_ASSERT_WITH_RETVAL(git_vector_is_sorted(&index->reuc), NULL);
2251 0 4 if (git_index_reuc_find(&pos, index, path) < 0)
2260 0 0 GIT_ASSERT_ARG_WITH_RETVAL(index, NULL);
2261 0 0 GIT_ASSERT_WITH_RETVAL(git_vector_is_sorted(&index->reuc), NULL);
2271 0 0 GIT_ASSERT_ARG(index);
2272 0 0 GIT_ASSERT(git_vector_is_sorted(&index->reuc));
2277 0 0 if (!error)
2288 0 123 GIT_ASSERT_ARG(index);
2290 6 123 for (i = 0; i < index->reuc.length; ++i)
2317 0 0 while (size) {
2321 0 0 if (size <= len)
2325 0 0 GIT_ERROR_CHECK_ALLOC(lost);
2331 0 0 for (i = 0; i < 3; i++) {
2334 0 0 if (git__strntol64(&tmp, buffer, size, &endptr, 8) < 0 ||
0 0 if (git__strntol64(&tmp, buffer, size, &endptr, 8) < 0 ||
2335 0 0 !endptr || endptr == buffer || *endptr ||
0 0 !endptr || endptr == buffer || *endptr ||
0 0 !endptr || endptr == buffer || *endptr ||
2336 0 0 tmp < 0 || tmp > UINT32_MAX) {
2344 0 0 if (size <= len) {
2354 0 0 for (i = 0; i < 3; i++) {
2355 0 0 if (!lost->mode[i])
2357 0 0 if (size < 20) {
2368 0 0 if (git_vector_insert(&index->reuc, lost) < 0)
2405 0 0 while (size) {
2407 0 0 GIT_ERROR_CHECK_ALLOC(conflict_name);
2409 0 0 read_conflict_name(conflict_name->ancestor);
0 0 read_conflict_name(conflict_name->ancestor);
0 0 read_conflict_name(conflict_name->ancestor);
2410 0 0 read_conflict_name(conflict_name->ours);
0 0 read_conflict_name(conflict_name->ours);
0 0 read_conflict_name(conflict_name->ours);
2411 0 0 read_conflict_name(conflict_name->theirs);
0 0 read_conflict_name(conflict_name->theirs);
0 0 read_conflict_name(conflict_name->theirs);
2413 0 0 if (git_vector_insert(&index->names, conflict_name) < 0)
2436 0 232 if (varint_len) {
2437 0 0 if (flags & GIT_INDEX_ENTRY_EXTENDED)
2443 0 232 if (flags & GIT_INDEX_ENTRY_EXTENDED)
2467 0 26 if (checksum_size + minimal_entry_size > buffer_size)
2485 0 26 if (git_oid_fromraw(&entry.id, source.oid) < 0)
2488 0 26 if (entry.flags & GIT_INDEX_ENTRY_EXTENDED) {
2502 26 0 if (!compressed) {
2507 0 26 if (path_length == 0xFFF) {
2511 0 0 if (path_end == NULL)
2526 0 0 if (varint_len == 0 || last_len < strip_len)
0 0 if (varint_len == 0 || last_len < strip_len)
2532 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&path_len, prefix_len, suffix_len);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&path_len, prefix_len, suffix_len);
2533 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&path_len, path_len, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&path_len, path_len, 1);
2535 0 0 if (path_len > GIT_PATH_MAX)
2539 0 0 GIT_ERROR_CHECK_ALLOC(tmp_path);
2547 0 26 if (entry_size == 0)
2550 0 26 if (checksum_size + entry_size > buffer_size)
2553 0 26 if (index_entry_dup(out, index, &entry) < 0) {
2568 0 11 if (dest->signature != INDEX_HEADER_SIG)
2572 11 0 if (dest->version < INDEX_VERSION_NUMBER_LB ||
0 11 if (dest->version < INDEX_VERSION_NUMBER_LB ||
2592 11 0 if (dest.extension_size > total_size ||
11 0 if (dest.extension_size > total_size ||
2593 0 11 buffer_size < total_size ||
2600 11 0 if (dest.signature[0] >= 'A' && dest.signature[0] <= 'Z') {
11 0 if (dest.signature[0] >= 'A' && dest.signature[0] <= 'Z') {
2602 11 0 if (memcmp(dest.signature, INDEX_EXT_TREECACHE_SIG, 4) == 0) {
2603 0 11 if (git_tree_cache_read(&index->tree, buffer + 8, dest.extension_size, &index->tree_pool) < 0)
2605 0 0 } else if (memcmp(dest.signature, INDEX_EXT_UNMERGED_SIG, 4) == 0) {
2606 0 0 if (read_reuc(index, buffer + 8, dest.extension_size) < 0)
2608 0 0 } else if (memcmp(dest.signature, INDEX_EXT_CONFLICT_NAME_SIG, 4) == 0) {
2609 0 0 if (read_conflict_names(index, buffer + 8, dest.extension_size) < 0)
2644 0 11 if (buffer_size < INDEX_HEADER_SIZE + checksum_size)
2652 0 11 if ((error = read_header(&header, buffer)) < 0)
2656 0 11 if (index->version >= INDEX_VERSION_NUMBER_COMP)
2659 0 11 seek_forward(INDEX_HEADER_SIZE);
2661 0 11 GIT_ASSERT(!index->entries.length);
2663 0 11 if ((error = index_map_resize(index->entries_map, header.entry_count, index->ignore_case)) < 0)
2667 26 11 for (i = 0; i < header.entry_count && buffer_size > checksum_size; ++i) {
26 0 for (i = 0; i < header.entry_count && buffer_size > checksum_size; ++i) {
2671 0 26 if ((error = read_entry(&entry, &entry_size, index, buffer, buffer_size, last)) < 0) {
2676 0 26 if ((error = git_vector_insert(&index->entries, entry)) < 0) {
2681 0 26 if ((error = index_map_set(index->entries_map, entry, index->ignore_case)) < 0) {
2687 0 26 if (index->version >= INDEX_VERSION_NUMBER_COMP)
2690 0 26 seek_forward(entry_size);
2693 0 11 if (i != header.entry_count) {
2699 11 11 while (buffer_size > checksum_size) {
2702 0 11 if ((error = read_extension(&extension_size, index, buffer, buffer_size)) < 0) {
2706 0 11 seek_forward(extension_size);
2709 0 11 if (buffer_size != checksum_size) {
2716 0 11 if (memcmp(checksum, buffer, checksum_size) != 0) {
2729 11 0 git_vector_set_sorted(&index->entries, !index->ignore_case);
2744 206 97 git_vector_foreach(&index->entries, i, entry) {
2746 0 206 if (entry->flags_extended & GIT_INDEX_ENTRY_EXTENDED_FLAGS) {
2767 0 206 if (last) {
2770 0 0 while (*path_start == *last_c) {
2771 0 0 if (!*path_start || !*last_c)
0 0 if (!*path_start || !*last_c)
2783 0 206 if (git_filebuf_reserve(file, &mem, disk_size) < 0)
2811 0 206 if (entry->flags & GIT_INDEX_ENTRY_EXTENDED) {
2827 0 206 if (last) {
2830 0 0 GIT_ASSERT(varint_len > 0);
2839 0 0 GIT_ASSERT(disk_size == path_len + 1);
2846 0 206 GIT_ASSERT(disk_size > path_len);
2864 0 97 if (index->ignore_case) {
2865 0 0 if ((error = git_vector_dup(&case_sorted, &index->entries, git_index_entry_cmp)) < 0)
2874 0 97 if (index->version >= INDEX_VERSION_NUMBER_COMP)
2877 206 97 git_vector_foreach(entries, i, entry) {
2878 0 206 if ((error = write_disk_entry(file, entry, last)) < 0)
2880 0 206 if (index->version >= INDEX_VERSION_NUMBER_COMP)
2905 0 0 if (conflict_name->ancestor == NULL)
2910 0 0 if (error != 0)
2913 0 0 if (conflict_name->ours == NULL)
2918 0 0 if (error != 0)
2921 0 0 if (conflict_name->theirs == NULL)
2939 0 0 git_vector_foreach(out, i, conflict_name) {
2940 0 0 if ((error = create_name_extension_data(&name_buf, conflict_name)) < 0)
2961 0 5 if ((error = git_str_put(reuc_buf, reuc->path, strlen(reuc->path) + 1)) < 0)
2964 15 5 for (i = 0; i < 3; i++) {
2965 15 0 if ((error = git_str_printf(reuc_buf, "%o", reuc->mode[i])) < 0 ||
0 15 if ((error = git_str_printf(reuc_buf, "%o", reuc->mode[i])) < 0 ||
2970 15 5 for (i = 0; i < 3; i++) {
2971 15 0 if (reuc->mode[i] && (error = git_str_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_RAWSZ)) < 0)
0 15 if (reuc->mode[i] && (error = git_str_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_RAWSZ)) < 0)
2987 5 5 git_vector_foreach(out, i, reuc) {
2988 0 5 if ((error = create_reuc_extension_data(&reuc_buf, reuc)) < 0)
3010 0 92 if (index->tree == NULL)
3013 0 92 if ((error = git_tree_cache_write(&buf, index->tree)) < 0)
3032 212 99 git_vector_foreach(&index->entries, i, entry)
3046 0 97 GIT_ASSERT_ARG(index);
3047 0 97 GIT_ASSERT_ARG(file);
3051 97 0 if (index->version <= INDEX_VERSION_NUMBER_EXT) {
3053 0 97 index_version_number = is_extended ? INDEX_VERSION_NUMBER_EXT : INDEX_VERSION_NUMBER_LB;
3062 0 97 if (git_filebuf_write(file, &header, sizeof(struct index_header)) < 0)
3065 0 97 if (write_entries(index, file) < 0)
3069 92 5 if (index->tree != NULL && write_tree_extension(index, file) < 0)
0 92 if (index->tree != NULL && write_tree_extension(index, file) < 0)
3073 0 97 if (index->names.length > 0 && write_name_extension(index, file) < 0)
0 0 if (index->names.length > 0 && write_name_extension(index, file) < 0)
3077 5 92 if (index->reuc.length > 0 && write_reuc_extension(index, file) < 0)
0 5 if (index->reuc.length > 0 && write_reuc_extension(index, file) < 0)
3084 0 97 if (git_filebuf_write(file, checksum, *checksum_size) < 0)
3119 4 9 if (git_tree_entry__is_tree(tentry))
3122 0 9 if (git_str_joinpath(&path, root, tentry->filename) < 0)
3125 0 9 if (index_entry_create(&entry, INDEX_OWNER(data->index), path.ptr, NULL, false) < 0)
3134 9 0 &pos, data->old_entries, data->entry_cmp, path.ptr, 0, 0) &&
3135 9 0 (old_entry = git_vector_get(data->old_entries, pos)) != NULL &&
3136 9 0 entry->mode == old_entry->mode &&
3146 0 9 if (git_vector_insert(data->new_entries, entry) < 0) {
3163 0 5 if (git_idxmap_new(&entries_map) < 0)
3178 0 5 if ((error = git_tree_walk(tree, GIT_TREEWALK_POST, read_tree_cb, &data)) < 0)
3181 0 5 if ((error = index_map_resize(entries_map, entries.length, index->ignore_case)) < 0)
3184 9 5 git_vector_foreach(&entries, i, e) {
3185 0 9 if ((error = index_map_set(entries_map, e, index->ignore_case)) < 0) {
3195 5 0 if ((error = git_index_clear(index)) < 0) {
3207 0 5 if (error < 0)
3230 0 2 GIT_ASSERT((new_iterator->flags & GIT_ITERATOR_DONT_IGNORE_CASE));
3232 2 0 if ((error = git_vector_init(&new_entries, new_length_hint, index->entries._cmp)) < 0 ||
2 0 if ((error = git_vector_init(&new_entries, new_length_hint, index->entries._cmp)) < 0 ||
3233 2 0 (error = git_vector_init(&remove_entries, index->entries.length, NULL)) < 0 ||
3237 2 0 if (new_length_hint && (error = index_map_resize(new_entries_map, new_length_hint,
0 2 if (new_length_hint && (error = index_map_resize(new_entries_map, new_length_hint,
3244 2 0 if ((error = git_iterator_for_index(&index_iterator,
3245 0 2 git_index_owner(index), index, &opts)) < 0 ||
3246 0 0 ((error = git_iterator_current(&old_entry, index_iterator)) < 0 &&
3247 0 2 error != GIT_ITEROVER) ||
3248 0 0 ((error = git_iterator_current(&new_entry, new_iterator)) < 0 &&
3261 6 2 if (old_entry && new_entry)
6 0 if (old_entry && new_entry)
3263 2 0 else if (!old_entry && new_entry)
0 2 else if (!old_entry && new_entry)
3265 0 2 else if (old_entry && !new_entry)
0 0 else if (old_entry && !new_entry)
3270 0 6 if (diff < 0) {
3272 0 6 } else if (diff > 0) {
3278 4 2 if (git_oid_equal(&old_entry->id, &new_entry->id) &&
4 0 if (git_oid_equal(&old_entry->id, &new_entry->id) &&
3287 2 4 if (dup_entry) {
3288 0 2 if ((error = index_entry_dup_nocache(&add_entry, index, dup_entry)) < 0)
3298 2 4 if (dup_entry && !remove_entry && index->tree)
0 2 if (dup_entry && !remove_entry && index->tree)
0 0 if (dup_entry && !remove_entry && index->tree)
3301 6 0 if (add_entry) {
3302 6 0 if ((error = git_vector_insert(&new_entries, add_entry)) == 0)
3307 2 4 if (remove_entry && error >= 0)
2 0 if (remove_entry && error >= 0)
3310 0 6 if (error < 0) {
3315 6 0 if (diff <= 0) {
3316 2 4 if ((error = git_iterator_advance(&old_entry, index_iterator)) < 0 &&
0 2 if ((error = git_iterator_advance(&old_entry, index_iterator)) < 0 &&
3321 6 0 if (diff >= 0) {
3322 2 4 if ((error = git_iterator_advance(&new_entry, new_iterator)) < 0 &&
0 2 if ((error = git_iterator_advance(&new_entry, new_iterator)) < 0 &&
3328 2 0 if ((error = git_index_name_clear(index)) < 0 ||
2 0 if ((error = git_index_name_clear(index)) < 0 ||
3335 2 2 git_vector_foreach(&remove_entries, i, entry) {
3336 2 0 if (index->tree)
3366 2 0 if ((error = git_iterator_for_index(&new_iterator,
3402 0 4 GIT_ASSERT_ARG(index);
3405 0 4 if ((error = git_repository__ensure_not_bare(repo, "index add all")) < 0)
3408 0 4 if ((error = git_pathspec__init(&ps, paths)) < 0)
3412 0 4 if ((flags & GIT_INDEX_ADD_CHECK_PATHSPEC) != 0 &&
0 0 if ((flags & GIT_INDEX_ADD_CHECK_PATHSPEC) != 0 &&
3413 0 0 (flags & GIT_INDEX_ADD_FORCE) == 0 &&
3420 0 4 if (error)
3449 6 6 if (!git_pathspec__match(
3454 6 0 if (data->cb)
3457 1 5 if (error > 0) /* skip this entry */
3459 1 4 if (error < 0) /* actual error */
3463 0 4 if ((delta->new_file.flags & GIT_DIFF_FLAG_EXISTS) == 0)
3488 0 8 GIT_ASSERT_ARG(index);
3489 4 4 GIT_ASSERT_ARG(action == INDEX_ACTION_UPDATE || action == INDEX_ACTION_ADDALL);
0 4 GIT_ASSERT_ARG(action == INDEX_ACTION_UPDATE || action == INDEX_ACTION_ADDALL);
3493 0 8 if (!repo) {
3503 0 8 if ((error = git_pathspec__init(&ps, paths)) < 0)
3507 4 4 if (action == INDEX_ACTION_ADDALL) {
3511 1 3 if (flags == GIT_INDEX_ADD_FORCE)
3515 0 8 if ((error = git_diff_index_to_workdir(&diff, repo, index, &opts)) < 0)
3522 1 7 if (error) /* make sure error is set if callback stopped iteration */
3543 0 1 GIT_ASSERT_ARG(index);
3545 0 1 if ((error = git_pathspec__init(&ps, paths)) < 0)
3550 2 0 for (i = 0; !error && i < index->entries.length; ++i) {
1 1 for (i = 0; !error && i < index->entries.length; ++i) {
3554 0 1 if (!git_pathspec__match(
3560 1 0 if (cb && (error = cb(entry->path, match, payload)) != 0) {
0 1 if (cb && (error = cb(entry->path, match, payload)) != 0) {
3561 0 0 if (error > 0) { /* return > 0 means skip this one */
3565 0 0 if (error < 0) /* return < 0 means abort */
3570 0 1 if ((error = git_str_sets(&path, entry->path)) < 0)
3579 0 0 if (error == GIT_ENOTFOUND) {
3584 0 0 if (!error) /* back up foreach if we removed this */
3589 1 0 if (!(error = git_index_remove_bypath(index, path.ptr)))
3614 0 1 if (error) /* make sure error is set if callback stopped iteration */
3627 1 3 if (error) /* make sure error is set if callback stopped iteration */
3644 0 423 if (error < 0)
3676 0 98 if (!index->index_file_path)
3680 0 98 if ((error = git_filebuf_open(
3683 0 0 if (error == GIT_ELOCKED)
3702 15 0 if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
0 15 if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
3718 0 97 if (!writer->should_write)
3724 0 97 if ((error = write_index(checksum, &checksum_size, writer->index, &writer->file)) < 0) {
3729 0 97 if ((error = git_filebuf_commit(&writer->file)) < 0)
3732 0 97 if ((error = git_futils_filestamp_check(