Branch Coverage

deps/libgit2/src/index.c
Criterion Covered Total %
branch 576 1224 47.0


line true false branch
130 0 173 if (ignore_case)
138 0 217 if (ignore_case)
146 0 43 if (ignore_case)
164 2898 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 1553 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 assert(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_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 assert(!git_atomic_get(&index->readers));
481 109 814 if (index == NULL)
484 47 767 GIT_REFCOUNT_DEC(index, index_free);
47 0 GIT_REFCOUNT_DEC(index, index_free);
493 71 0 if (readers > 0 || !index->deleted.length)
65 6 if (readers > 0 || !index->deleted.length)
496 6 6 for (i = 0; i < index->deleted.length; ++i) {
510 167 0 if (entry != NULL) {
517 167 0 if (!error) {
518 6 161 if (git_atomic_get(&index->readers) > 0) {
534 0 71 assert(index);
541 211 0 while (!error && index->entries.length > 0)
140 71 while (!error && index->entries.length > 0)
544 0 71 if (error)
549 71 0 if ((error = git_index_name_clear(index)) < 0 ||
71 0 if ((error = git_index_name_clear(index)) < 0 ||
569 0 16 assert(index);
573 16 0 if (caps == GIT_INDEX_CAPABILITY_FROM_OWNER) {
577 0 16 if (!repo)
581 16 0 if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_IGNORECASE))
583 16 0 if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_FILEMODE))
585 16 0 if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_SYMLINKS))
594 0 16 if (old_ignore_case != index->ignore_case) {
604 0 1 (index->distrust_filemode ? GIT_INDEX_CAPABILITY_NO_FILEMODE : 0) |
605 0 1 (index->no_symlinks ? GIT_INDEX_CAPABILITY_NO_SYMLINKS : 0));
622 0 135 if ((fd = p_open(index->index_file_path, O_RDONLY)) < 0)
625 0 135 if (p_lseek(fd, -20, SEEK_END) < 0) {
634 0 135 if (bytes_read < 0)
646 0 152 if (!index->index_file_path)
652 17 135 if (!index->on_disk) {
653 6 11 if (force && (error = git_index_clear(index)) < 0)
0 6 if (force && (error = git_index_clear(index)) < 0)
660 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) ||
669 125 10 if (!updated && !force)
124 1 if (!updated && !force)
673 0 11 if (error < 0)
681 11 0 if (!error)
684 11 0 if (!error) {
695 0 89 if (git_index__enforce_unsaved_safety && index->dirty) {
0 0 if (git_index__enforce_unsaved_safety && index->dirty) {
708 0 0 if (git_index_read(index, false) < 0)
717 0 111 if (S_ISGITLINK(entry->mode))
738 0 83 if (!INDEX_OWNER(index))
742 0 83 if (!git_repository_workdir(INDEX_OWNER(index)))
746 171 83 git_vector_foreach(&index->entries, i, entry) {
752 61 22 if (paths.length == 0)
758 0 22 if ((error = git_diff_index_to_workdir(&diff, INDEX_OWNER(index), index, &diff_opts)) < 0)
761 0 22 git_vector_foreach(&diff->deltas, i, delta) {
767 0 0 if (entry) {
781 0 3 assert(index);
788 0 1 assert(index);
790 1 0 if (version < INDEX_VERSION_NUMBER_LB ||
0 1 if (version < INDEX_VERSION_NUMBER_LB ||
808 83 0 if ((error = git_indexwriter_init(&writer, index)) == 0 &&
83 0 if ((error = git_indexwriter_init(&writer, index)) == 0 &&
819 0 3 assert(index);
827 38 0 assert(oid && index);
0 38 assert(oid && index);
831 0 38 if (repo == NULL)
841 18 0 assert(oid && index && repo);
18 0 assert(oid && index && repo);
0 18 assert(oid && index && repo);
847 0 270 assert(index);
854 0 419 assert(index);
865 0 182 assert(index);
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_isvalid(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_buf_joinpath(&path, git_repository_workdir(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 10 0 assert(reuc_out && path);
0 10 assert(reuc_out && path);
1045 0 10 GIT_ERROR_CHECK_ALLOC(reuc);
1047 10 0 if ((reuc->mode[0] = ancestor_mode) > 0) {
1048 0 10 assert(ancestor_oid);
1052 8 2 if ((reuc->mode[1] = our_mode) > 0) {
1053 0 8 assert(our_oid);
1057 6 4 if ((reuc->mode[2] = their_mode) > 0) {
1058 0 6 assert(their_oid);
1079 0 165 if (index_entry_create(out, INDEX_OWNER(index), src->path, NULL, false) < 0)
1101 0 2 if (index_entry_create(out, INDEX_OWNER(index), src->path, NULL, false) < 0)
1115 109 18 while (pos < index->entries.length) {
1118 105 4 if (len >= p->pathlen)
1120 3 1 if (memcmp(name, p->path, len))
1122 0 1 if (GIT_INDEX_ENTRY_STAGE(&p->entry) != stage)
1124 1 0 if (p->path[len] != '/')
1126 0 0 if (!ok_to_replace)
1129 0 0 if (index_remove_entry(index, --pos) < 0)
1150 13 834 if (*--slash == '/')
1152 124 710 if (slash <= entry->path)
1157 0 13 if (!index_find(&pos, index, name, len, stage)) {
1158 0 0 if (!ok_to_replace)
1161 0 0 if (index_remove_entry(index, pos) < 0)
1171 7 6 for (; pos < index->entries.length; ++pos) {
1174 7 0 if (p->pathlen <= len ||
2 5 if (p->pathlen <= len ||
1175 2 0 p->path[len] != '/' ||
1179 2 0 if (GIT_INDEX_ENTRY_STAGE(&p->entry) == stage)
1209 50 0 if (!index->ignore_case)
1213 0 0 if (existing) {
1219 0 0 if (strchr(entry->path, '/') == NULL)
1222 0 0 if ((search = git__strdup(entry->path)) == NULL)
1228 0 0 while (!best && (sep = strrchr(search, '/'))) {
0 0 while (!best && (sep = strrchr(search, '/'))) {
1236 0 0 while ((match = git_vector_get(&index->entries, pos))) {
1237 0 0 if (GIT_INDEX_ENTRY_STAGE(match) != 0) {
1239 0 0 } else if (strncmp(search, match->path, search_len) == 0) {
1244 0 0 } else if (strncasecmp(search, match->path, search_len) == 0) {
1249 0 0 if (!best) {
1263 0 0 if (best)
1293 57 69 if (error == 0) {
1304 43 26 if (GIT_INDEX_ENTRY_STAGE(entry) == 0) {
1305 19 26 for (; pos < index->entries.length; pos++) {
1307 0 19 index->ignore_case ? git__strcasecmp : git__strcmp;
1311 15 4 if (strcomp(entry->path, e->path) != 0)
1314 2 2 if (GIT_INDEX_ENTRY_STAGE(e) == GIT_INDEX_STAGE_ANCESTOR) {
1350 126 0 assert(index && entry_ptr);
0 126 assert(index && entry_ptr);
1371 76 50 git_index__create_mode(entry->mode) :
1375 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)
1379 69 57 if (!trust_id && INDEX_OWNER(index) &&
43 26 if (!trust_id && INDEX_OWNER(index) &&
43 0 if (!trust_id && INDEX_OWNER(index) &&
1382 0 43 if (!git_object__is_valid(INDEX_OWNER(index), &entry->id,
1390 0 126 if ((error = check_file_directory_collision(index, entry, position, replace)) < 0)
1397 57 69 if (existing) {
1398 57 0 if (replace) {
1401 30 27 if (trust_path)
1413 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 ||
1421 0 126 if (error < 0) {
1436 61 2 if ((ret = git_index_conflict_get(&conflict_entries[0],
1440 2 0 ancestor_mode = conflict_entries[0] == NULL ? 0 : conflict_entries[0]->mode;
1441 2 0 our_mode = conflict_entries[1] == NULL ? 0 : conflict_entries[1]->mode;
1442 2 0 their_mode = conflict_entries[2] == NULL ? 0 : conflict_entries[2]->mode;
1444 2 0 ancestor_oid = conflict_entries[0] == NULL ? NULL : &conflict_entries[0]->id;
1445 2 0 our_oid = conflict_entries[1] == NULL ? NULL : &conflict_entries[1]->id;
1446 2 0 their_oid = conflict_entries[2] == NULL ? NULL : &conflict_entries[2]->id;
1448 2 0 if ((ret = git_index_reuc_add(index, path, ancestor_mode, ancestor_oid,
1457 3 1 return (filemode == GIT_FILEMODE_BLOB ||
1458 4 74 filemode == GIT_FILEMODE_BLOB_EXECUTABLE ||
1 2 filemode == GIT_FILEMODE_BLOB_EXECUTABLE ||
1464 0 69 return (is_file_or_link(filemode) || filemode == GIT_FILEMODE_COMMIT);
0 0 return (is_file_or_link(filemode) || filemode == GIT_FILEMODE_COMMIT);
1475 9 0 assert(index && source_entry->path);
0 9 assert(index && source_entry->path);
1477 0 9 if (INDEX_OWNER(index) == NULL)
1482 2 7 if (!is_file_or_link(source_entry->mode)) {
1487 0 7 if (len > UINT32_MAX) {
1492 0 7 if (index_entry_dup(&entry, index, source_entry) < 0)
1496 0 7 if (error < 0) {
1504 0 7 if ((error = index_insert(index, &entry, 1, true, true, true)) < 0)
1508 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)
1525 0 0 if ((error = git_buf_joinpath(&abspath, git_repository_workdir(repo), path)) < 0)
1528 0 0 if ((error = p_stat(abspath.ptr, &st)) < 0) {
1533 0 0 if (index_entry_create(&entry, INDEX_OWNER(index), path, &st, true) < 0)
1538 0 0 if ((error = git_repository_open(&sub, abspath.ptr)) < 0)
1541 0 0 if ((error = git_repository_head(&head, sub)) < 0)
1560 52 0 assert(index && path);
0 52 assert(index && path);
1562 50 2 if ((ret = index_entry_init(&entry, index, path)) == 0)
1566 2 50 if (ret < 0 && ret != GIT_EDIRECTORY)
2 0 if (ret < 0 && ret != GIT_EDIRECTORY)
1569 0 50 if (ret == GIT_EDIRECTORY) {
1576 0 0 if (ret == GIT_ENOTFOUND)
1585 0 0 if (ret == GIT_EEXISTS) {
1586 0 0 if ((ret = add_repo_as_submodule(&entry, index, path)) < 0)
1589 0 0 if ((ret = index_insert(index, &entry, 1, false, false, true)) < 0)
1591 0 0 } else if (ret < 0) {
1601 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)
1612 6 0 assert(index && path);
0 6 assert(index && path);
1614 0 6 if (((ret = git_index_remove(index, path, 0)) < 0 &&
0 0 if (((ret = git_index_remove(index, path, 0)) < 0 &&
1615 6 0 ret != GIT_ENOTFOUND) ||
1616 0 6 ((ret = index_conflict_to_reuc(index, path)) < 0 &&
1620 6 0 if (ret == GIT_ENOTFOUND)
1632 0 28 assert(index);
1634 3 25 if (!source_entries->length)
1642 63 25 git_vector_foreach(source_entries, i, source_entry) {
1645 0 63 if ((error = index_entry_dup(&entry, index, source_entry)) < 0)
1652 0 63 if ((error = git_vector_insert(&index->entries, entry)) < 0)
1655 0 63 if ((error = index_map_set(index->entries_map, entry, index->ignore_case)) < 0)
1661 25 0 if (!error)
1673 52 0 assert(index && source_entry && source_entry->path);
52 0 assert(index && source_entry && source_entry->path);
0 52 assert(index && source_entry && source_entry->path);
1675 0 52 if (!valid_filemode(source_entry->mode)) {
1680 52 0 if ((ret = index_entry_dup(&entry, index, source_entry)) < 0 ||
0 52 if ((ret = index_entry_dup(&entry, index, source_entry)) < 0 ||
1699 35 15 if (index_find(&position, index, path, 0, stage) < 0) {
1717 1 0 if (!(error = git_buf_sets(&pfx, dir)) &&
1 0 if (!(error = git_buf_sets(&pfx, dir)) &&
1721 1 0 while (!error) {
1723 1 0 if (!entry || git__prefixcmp(entry->path, pfx.ptr) != 0)
0 1 if (!entry || git__prefixcmp(entry->path, pfx.ptr) != 0)
1726 0 0 if (GIT_INDEX_ENTRY_STAGE(entry) != stage) {
1749 0 0 if (!entry || git__prefixcmp(entry->path, prefix) != 0)
0 0 if (!entry || git__prefixcmp(entry->path, prefix) != 0)
1752 0 0 if (!error && at_pos)
0 0 if (!error && at_pos)
1761 1368 0 assert(index && path);
0 1368 assert(index && path);
1769 71 0 assert(index && path);
0 71 assert(index && path);
1771 7 64 if (git_vector_bsearch2(
1780 28 49 for (; pos > 0; --pos) {
1783 15 13 if (index->entries_cmp_path(prev->path, path) != 0)
1787 64 0 if (at_pos)
1802 0 6 assert (index);
1804 6 0 if ((ancestor_entry &&
6 0 if ((ancestor_entry &&
1805 5 1 (ret = index_entry_dup(&entries[0], index, ancestor_entry)) < 0) ||
1806 5 0 (our_entry &&
1807 6 0 (ret = index_entry_dup(&entries[1], index, our_entry)) < 0) ||
1808 6 0 (their_entry &&
1813 18 6 for (i = 0; i < 3; i++) {
1814 17 1 if (entries[i] && !valid_filemode(entries[i]->mode)) {
0 17 if (entries[i] && !valid_filemode(entries[i]->mode)) {
1823 18 6 for (i = 0; i < 3; i++) {
1824 1 17 if (entries[i] == NULL)
1827 17 0 if ((ret = git_index_remove(index, entries[i]->path, 0)) != 0) {
1828 0 17 if (ret != GIT_ENOTFOUND)
1837 18 6 for (i = 0; i < 3; i++) {
1838 1 17 if (entries[i] == NULL)
1844 0 17 if ((ret = index_insert(index, &entries[i], 1, true, true, false)) < 0)
1853 0 0 for (i = 0; i < 3; i++) {
1854 0 0 if (entries[i] != NULL)
1873 62 0 assert(ancestor_out && our_out && their_out && index);
62 0 assert(ancestor_out && our_out && their_out && index);
62 0 assert(ancestor_out && our_out && their_out && index);
0 62 assert(ancestor_out && our_out && their_out && index);
1879 108 32 for (count = git_index_entrycount(index); n < count; ++n) {
1882 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)
1919 64 0 assert(ancestor_out && our_out && their_out && index && path);
64 0 assert(ancestor_out && our_out && their_out && index && path);
64 0 assert(ancestor_out && our_out && their_out && index && path);
64 0 assert(ancestor_out && our_out && their_out && index && path);
0 64 assert(ancestor_out && our_out && their_out && index && path);
1925 6 58 if (git_index_find(&pos, index, path) < 0)
1928 0 58 if ((len = index_conflict__get_byindex(
1931 55 3 else if (len == 0)
1943 5 1 if (path != NULL && git_index_find(&pos, index, path) < 0)
0 5 if (path != NULL && git_index_find(&pos, index, path) < 0)
1946 16 5 while ((conflict_entry = git_vector_get(&index->entries, pos)) != NULL) {
1952 3 12 if (GIT_INDEX_ENTRY_STAGE(conflict_entry) == 0) {
1957 0 12 if ((error = index_remove_entry(index, pos)) < 0)
1966 5 0 assert(index && path);
0 5 assert(index && path);
1972 0 1 assert(index);
1981 0 121 assert(index);
1983 291 113 git_vector_foreach(&index->entries, i, entry) {
1984 8 283 if (GIT_INDEX_ENTRY_STAGE(entry) > 0)
1998 0 0 assert(iterator_out && index);
0 0 assert(iterator_out && index);
2001 0 0 GIT_ERROR_CHECK_ALLOC(it);
2003 0 0 if ((error = git_index_snapshot_new(&it->snap, index)) < 0) {
2018 0 0 assert(out && it);
0 0 assert(out && it);
2020 0 0 if (it->cur >= git_vector_length(&it->snap))
2029 0 0 if (it == NULL)
2042 69 0 assert(iterator_out && index);
0 69 assert(iterator_out && index);
2045 0 69 GIT_ERROR_CHECK_ALLOC(it);
2062 73 0 assert(ancestor_out && our_out && their_out && iterator);
73 0 assert(ancestor_out && our_out && their_out && iterator);
73 0 assert(ancestor_out && our_out && their_out && iterator);
0 73 assert(ancestor_out && our_out && their_out && iterator);
2068 144 69 while (iterator->cur < iterator->index->entries.length) {
2071 4 140 if (git_index_entry_is_conflict(entry)) {
2072 0 4 if ((len = index_conflict__get_byindex(
2092 0 69 if (iterator == NULL)
2100 0 17 assert(index);
2107 0 0 assert(index);
2115 0 0 if (!ne)
2128 0 0 assert((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
0 0 assert((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
0 0 assert((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
0 0 assert((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
0 0 assert((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
0 0 assert((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
2131 0 0 GIT_ERROR_CHECK_ALLOC(conflict_name);
2133 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))) ||
2134 0 0 (ours && !(conflict_name->ours = git__strdup(ours))) ||
0 0 (ours && !(conflict_name->ours = git__strdup(ours))) ||
2151 0 123 assert(index);
2153 0 123 git_vector_foreach(&index->names, i, conflict_name)
2165 0 0 assert(index);
2182 10 0 assert(index && reuc && reuc->path != NULL);
10 0 assert(index && reuc && reuc->path != NULL);
0 10 assert(index && reuc && reuc->path != NULL);
2183 0 10 assert(git_vector_is_sorted(&index->reuc));
2188 6 4 return res == GIT_EEXISTS ? 0 : res;
2199 10 0 assert(index && path);
0 10 assert(index && path);
2201 10 0 if ((error = index_entry_reuc_init(&reuc, path, ancestor_mode,
2202 0 10 ancestor_oid, our_mode, our_oid, their_mode, their_oid)) < 0 ||
2218 6 0 assert(index && path);
0 6 assert(index && path);
2220 2 4 if (!index->reuc.length)
2223 0 4 assert(git_vector_is_sorted(&index->reuc));
2225 0 4 if (git_index_reuc_find(&pos, index, path) < 0)
2234 0 0 assert(index);
2235 0 0 assert(git_vector_is_sorted(&index->reuc));
2245 0 0 assert(git_vector_is_sorted(&index->reuc));
2250 0 0 if (!error)
2261 0 123 assert(index);
2263 6 123 for (i = 0; i < index->reuc.length; ++i)
2290 0 0 while (size) {
2294 0 0 if (size <= len)
2298 0 0 GIT_ERROR_CHECK_ALLOC(lost);
2304 0 0 for (i = 0; i < 3; i++) {
2307 0 0 if (git__strntol64(&tmp, buffer, size, &endptr, 8) < 0 ||
0 0 if (git__strntol64(&tmp, buffer, size, &endptr, 8) < 0 ||
2308 0 0 !endptr || endptr == buffer || *endptr ||
0 0 !endptr || endptr == buffer || *endptr ||
0 0 !endptr || endptr == buffer || *endptr ||
2309 0 0 tmp < 0 || tmp > UINT32_MAX) {
2317 0 0 if (size <= len) {
2327 0 0 for (i = 0; i < 3; i++) {
2328 0 0 if (!lost->mode[i])
2330 0 0 if (size < 20) {
2341 0 0 if (git_vector_insert(&index->reuc, lost) < 0)
2378 0 0 while (size) {
2380 0 0 GIT_ERROR_CHECK_ALLOC(conflict_name);
2382 0 0 read_conflict_name(conflict_name->ancestor);
0 0 read_conflict_name(conflict_name->ancestor);
0 0 read_conflict_name(conflict_name->ancestor);
2383 0 0 read_conflict_name(conflict_name->ours);
0 0 read_conflict_name(conflict_name->ours);
0 0 read_conflict_name(conflict_name->ours);
2384 0 0 read_conflict_name(conflict_name->theirs);
0 0 read_conflict_name(conflict_name->theirs);
0 0 read_conflict_name(conflict_name->theirs);
2386 0 0 if (git_vector_insert(&index->names, conflict_name) < 0)
2409 0 232 if (varint_len) {
2410 0 0 if (flags & GIT_INDEX_ENTRY_EXTENDED)
2416 0 232 if (flags & GIT_INDEX_ENTRY_EXTENDED)
2439 0 26 if (INDEX_FOOTER_SIZE + minimal_entry_size > buffer_size)
2458 0 26 if (entry.flags & GIT_INDEX_ENTRY_EXTENDED) {
2472 26 0 if (!compressed) {
2477 0 26 if (path_length == 0xFFF) {
2481 0 0 if (path_end == NULL)
2496 0 0 if (varint_len == 0 || last_len < strip_len)
0 0 if (varint_len == 0 || last_len < strip_len)
2502 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);
2503 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&path_len, path_len, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&path_len, path_len, 1);
2505 0 0 if (path_len > GIT_PATH_MAX)
2509 0 0 GIT_ERROR_CHECK_ALLOC(tmp_path);
2517 0 26 if (entry_size == 0)
2520 0 26 if (INDEX_FOOTER_SIZE + entry_size > buffer_size)
2523 0 26 if (index_entry_dup(out, index, &entry) < 0) {
2538 0 11 if (dest->signature != INDEX_HEADER_SIG)
2542 11 0 if (dest->version < INDEX_VERSION_NUMBER_LB ||
0 11 if (dest->version < INDEX_VERSION_NUMBER_LB ||
2561 11 0 if (dest.extension_size > total_size ||
11 0 if (dest.extension_size > total_size ||
2562 0 11 buffer_size < total_size ||
2569 11 0 if (dest.signature[0] >= 'A' && dest.signature[0] <= 'Z') {
11 0 if (dest.signature[0] >= 'A' && dest.signature[0] <= 'Z') {
2571 11 0 if (memcmp(dest.signature, INDEX_EXT_TREECACHE_SIG, 4) == 0) {
2572 0 11 if (git_tree_cache_read(&index->tree, buffer + 8, dest.extension_size, &index->tree_pool) < 0)
2574 0 0 } else if (memcmp(dest.signature, INDEX_EXT_UNMERGED_SIG, 4) == 0) {
2575 0 0 if (read_reuc(index, buffer + 8, dest.extension_size) < 0)
2577 0 0 } else if (memcmp(dest.signature, INDEX_EXT_CONFLICT_NAME_SIG, 4) == 0) {
2578 0 0 if (read_conflict_names(index, buffer + 8, dest.extension_size) < 0)
2612 0 11 if (buffer_size < INDEX_HEADER_SIZE + INDEX_FOOTER_SIZE)
2620 0 11 if ((error = read_header(&header, buffer)) < 0)
2624 0 11 if (index->version >= INDEX_VERSION_NUMBER_COMP)
2627 0 11 seek_forward(INDEX_HEADER_SIZE);
2629 0 11 assert(!index->entries.length);
2631 0 11 if ((error = index_map_resize(index->entries_map, header.entry_count, index->ignore_case)) < 0)
2635 26 11 for (i = 0; i < header.entry_count && buffer_size > INDEX_FOOTER_SIZE; ++i) {
26 0 for (i = 0; i < header.entry_count && buffer_size > INDEX_FOOTER_SIZE; ++i) {
2639 0 26 if ((error = read_entry(&entry, &entry_size, index, buffer, buffer_size, last)) < 0) {
2644 0 26 if ((error = git_vector_insert(&index->entries, entry)) < 0) {
2649 0 26 if ((error = index_map_set(index->entries_map, entry, index->ignore_case)) < 0) {
2655 0 26 if (index->version >= INDEX_VERSION_NUMBER_COMP)
2658 0 26 seek_forward(entry_size);
2661 0 11 if (i != header.entry_count) {
2667 11 11 while (buffer_size > INDEX_FOOTER_SIZE) {
2670 0 11 if ((error = read_extension(&extension_size, index, buffer, buffer_size)) < 0) {
2674 0 11 seek_forward(extension_size);
2677 0 11 if (buffer_size != INDEX_FOOTER_SIZE) {
2686 0 11 if (git_oid__cmp(&checksum_calculated, &checksum_expected) != 0) {
2699 11 0 git_vector_set_sorted(&index->entries, !index->ignore_case);
2714 206 97 git_vector_foreach(&index->entries, i, entry) {
2716 0 206 if (entry->flags_extended & GIT_INDEX_ENTRY_EXTENDED_FLAGS) {
2737 0 206 if (last) {
2740 0 0 while (*path_start == *last_c) {
2741 0 0 if (!*path_start || !*last_c)
0 0 if (!*path_start || !*last_c)
2753 0 206 if (git_filebuf_reserve(file, &mem, disk_size) < 0)
2783 0 206 if (entry->flags & GIT_INDEX_ENTRY_EXTENDED) {
2799 0 206 if (last) {
2802 0 0 assert(varint_len > 0);
2810 0 0 assert(disk_size == path_len + 1);
2817 0 206 assert(disk_size > path_len);
2835 0 97 if (index->ignore_case) {
2843 0 97 if (index->version >= INDEX_VERSION_NUMBER_COMP)
2846 206 97 git_vector_foreach(entries, i, entry) {
2847 0 206 if ((error = write_disk_entry(file, entry, last)) < 0)
2849 0 206 if (index->version >= INDEX_VERSION_NUMBER_COMP)
2853 0 97 if (index->ignore_case)
2875 0 0 if (conflict_name->ancestor == NULL)
2880 0 0 if (error != 0)
2883 0 0 if (conflict_name->ours == NULL)
2888 0 0 if (error != 0)
2891 0 0 if (conflict_name->theirs == NULL)
2909 0 0 git_vector_foreach(out, i, conflict_name) {
2910 0 0 if ((error = create_name_extension_data(&name_buf, conflict_name)) < 0)
2931 0 5 if ((error = git_buf_put(reuc_buf, reuc->path, strlen(reuc->path) + 1)) < 0)
2934 15 5 for (i = 0; i < 3; i++) {
2935 15 0 if ((error = git_buf_printf(reuc_buf, "%o", reuc->mode[i])) < 0 ||
0 15 if ((error = git_buf_printf(reuc_buf, "%o", reuc->mode[i])) < 0 ||
2940 15 5 for (i = 0; i < 3; i++) {
2941 15 0 if (reuc->mode[i] && (error = git_buf_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_RAWSZ)) < 0)
0 15 if (reuc->mode[i] && (error = git_buf_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_RAWSZ)) < 0)
2957 5 5 git_vector_foreach(out, i, reuc) {
2958 0 5 if ((error = create_reuc_extension_data(&reuc_buf, reuc)) < 0)
2980 0 92 if (index->tree == NULL)
2983 0 92 if ((error = git_tree_cache_write(&buf, index->tree)) < 0)
3002 212 99 git_vector_foreach(&index->entries, i, entry)
3013 97 0 assert(index && file);
0 97 assert(index && file);
3015 97 0 if (index->version <= INDEX_VERSION_NUMBER_EXT) {
3017 0 97 index_version_number = is_extended ? INDEX_VERSION_NUMBER_EXT : INDEX_VERSION_NUMBER_LB;
3026 0 97 if (git_filebuf_write(file, &header, sizeof(struct index_header)) < 0)
3029 0 97 if (write_entries(index, file) < 0)
3033 92 5 if (index->tree != NULL && write_tree_extension(index, file) < 0)
0 92 if (index->tree != NULL && write_tree_extension(index, file) < 0)
3037 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)
3041 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)
3049 0 97 if (git_filebuf_write(file, hash_final.id, GIT_OID_RAWSZ) < 0)
3084 4 9 if (git_tree_entry__is_tree(tentry))
3087 0 9 if (git_buf_joinpath(&path, root, tentry->filename) < 0)
3090 0 9 if (index_entry_create(&entry, INDEX_OWNER(data->index), path.ptr, NULL, false) < 0)
3099 9 0 &pos, data->old_entries, data->entry_cmp, path.ptr, 0, 0) &&
3100 9 0 (old_entry = git_vector_get(data->old_entries, pos)) != NULL &&
3101 9 0 entry->mode == old_entry->mode &&
3111 0 9 if (git_vector_insert(data->new_entries, entry) < 0) {
3128 0 5 if (git_idxmap_new(&entries_map) < 0)
3143 0 5 if ((error = git_tree_walk(tree, GIT_TREEWALK_POST, read_tree_cb, &data)) < 0)
3146 0 5 if ((error = index_map_resize(entries_map, entries.length, index->ignore_case)) < 0)
3149 9 5 git_vector_foreach(&entries, i, e) {
3150 0 9 if ((error = index_map_set(entries_map, e, index->ignore_case)) < 0) {
3160 5 0 if ((error = git_index_clear(index)) < 0) {
3172 0 5 if (error < 0)
3195 0 2 assert((new_iterator->flags & GIT_ITERATOR_DONT_IGNORE_CASE));
3197 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 ||
3198 2 0 (error = git_vector_init(&remove_entries, index->entries.length, NULL)) < 0 ||
3202 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,
3209 2 0 if ((error = git_iterator_for_index(&index_iterator,
3210 0 2 git_index_owner(index), index, &opts)) < 0 ||
3211 0 0 ((error = git_iterator_current(&old_entry, index_iterator)) < 0 &&
3212 0 2 error != GIT_ITEROVER) ||
3213 0 0 ((error = git_iterator_current(&new_entry, new_iterator)) < 0 &&
3226 6 2 if (old_entry && new_entry)
6 0 if (old_entry && new_entry)
3228 2 0 else if (!old_entry && new_entry)
0 2 else if (!old_entry && new_entry)
3230 0 2 else if (old_entry && !new_entry)
0 0 else if (old_entry && !new_entry)
3235 0 6 if (diff < 0) {
3237 0 6 } else if (diff > 0) {
3243 4 2 if (git_oid_equal(&old_entry->id, &new_entry->id) &&
4 0 if (git_oid_equal(&old_entry->id, &new_entry->id) &&
3252 2 4 if (dup_entry) {
3253 0 2 if ((error = index_entry_dup_nocache(&add_entry, index, dup_entry)) < 0)
3263 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)
3266 6 0 if (add_entry) {
3267 6 0 if ((error = git_vector_insert(&new_entries, add_entry)) == 0)
3272 2 4 if (remove_entry && error >= 0)
2 0 if (remove_entry && error >= 0)
3275 0 6 if (error < 0) {
3280 6 0 if (diff <= 0) {
3281 2 4 if ((error = git_iterator_advance(&old_entry, index_iterator)) < 0 &&
0 2 if ((error = git_iterator_advance(&old_entry, index_iterator)) < 0 &&
3286 6 0 if (diff >= 0) {
3287 2 4 if ((error = git_iterator_advance(&new_entry, new_iterator)) < 0 &&
0 2 if ((error = git_iterator_advance(&new_entry, new_iterator)) < 0 &&
3293 2 0 if ((error = git_index_name_clear(index)) < 0 ||
2 0 if ((error = git_index_name_clear(index)) < 0 ||
3300 2 2 git_vector_foreach(&remove_entries, i, entry) {
3301 2 0 if (index->tree)
3331 2 0 if ((error = git_iterator_for_index(&new_iterator,
3367 0 4 assert(index);
3370 0 4 if ((error = git_repository__ensure_not_bare(repo, "index add all")) < 0)
3373 0 4 if ((error = git_pathspec__init(&ps, paths)) < 0)
3377 0 4 if ((flags & GIT_INDEX_ADD_CHECK_PATHSPEC) != 0 &&
0 0 if ((flags & GIT_INDEX_ADD_CHECK_PATHSPEC) != 0 &&
3378 0 0 (flags & GIT_INDEX_ADD_FORCE) == 0 &&
3385 0 4 if (error)
3414 6 6 if (!git_pathspec__match(
3419 6 0 if (data->cb)
3422 1 5 if (error > 0) /* skip this entry */
3424 1 4 if (error < 0) /* actual error */
3428 0 4 if ((delta->new_file.flags & GIT_DIFF_FLAG_EXISTS) == 0)
3453 0 8 assert(index);
3454 4 4 assert(action == INDEX_ACTION_UPDATE || action == INDEX_ACTION_ADDALL);
0 4 assert(action == INDEX_ACTION_UPDATE || action == INDEX_ACTION_ADDALL);
3458 0 8 if (!repo) {
3468 0 8 if ((error = git_pathspec__init(&ps, paths)) < 0)
3472 4 4 if (action == INDEX_ACTION_ADDALL) {
3476 1 3 if (flags == GIT_INDEX_ADD_FORCE)
3480 0 8 if ((error = git_diff_index_to_workdir(&diff, repo, index, &opts)) < 0)
3487 1 7 if (error) /* make sure error is set if callback stopped iteration */
3508 0 1 assert(index);
3510 0 1 if ((error = git_pathspec__init(&ps, paths)) < 0)
3515 2 0 for (i = 0; !error && i < index->entries.length; ++i) {
1 1 for (i = 0; !error && i < index->entries.length; ++i) {
3519 0 1 if (!git_pathspec__match(
3525 1 0 if (cb && (error = cb(entry->path, match, payload)) != 0) {
0 1 if (cb && (error = cb(entry->path, match, payload)) != 0) {
3526 0 0 if (error > 0) { /* return > 0 means skip this one */
3530 0 0 if (error < 0) /* return < 0 means abort */
3535 0 1 if ((error = git_buf_sets(&path, entry->path)) < 0)
3544 0 0 if (error == GIT_ENOTFOUND) {
3549 0 0 if (!error) /* back up foreach if we removed this */
3554 1 0 if (!(error = git_index_remove_bypath(index, path.ptr)))
3579 0 1 if (error) /* make sure error is set if callback stopped iteration */
3592 1 3 if (error) /* make sure error is set if callback stopped iteration */
3609 0 431 if (error < 0)
3641 0 98 if (!index->index_file_path)
3645 0 98 if ((error = git_filebuf_open(
3648 0 0 if (error == GIT_ELOCKED)
3667 15 0 if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
0 15 if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
3682 0 97 if (!writer->should_write)
3688 0 97 if ((error = write_index(&checksum, writer->index, &writer->file)) < 0) {
3693 0 97 if ((error = git_filebuf_commit(&writer->file)) < 0)
3696 0 97 if ((error = git_futils_filestamp_check(