Branch Coverage

deps/libgit2/src/index.c
Criterion Covered Total %
branch 575 1222 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 2594 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 1377 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);
416 16 31 if (index_path != NULL) {
418 0 16 if (!index->index_file_path)
422 10 6 if (git_path_exists(index->index_file_path) == true)
427 47 0 git_idxmap_new(&index->entries_map) < 0 ||
428 47 0 git_vector_init(&index->names, 8, conflict_name_cmp) < 0 ||
429 47 0 git_vector_init(&index->reuc, 8, reuc_cmp) < 0 ||
439 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)
463 0 47 assert(!git_atomic_get(&index->readers));
480 109 814 if (index == NULL)
483 47 767 GIT_REFCOUNT_DEC(index, index_free);
47 0 GIT_REFCOUNT_DEC(index, index_free);
492 71 0 if (readers > 0 || !index->deleted.length)
65 6 if (readers > 0 || !index->deleted.length)
495 6 6 for (i = 0; i < index->deleted.length; ++i) {
509 167 0 if (entry != NULL) {
516 167 0 if (!error) {
517 6 161 if (git_atomic_get(&index->readers) > 0) {
533 0 71 assert(index);
540 211 0 while (!error && index->entries.length > 0)
140 71 while (!error && index->entries.length > 0)
543 0 71 if (error)
548 71 0 if ((error = git_index_name_clear(index)) < 0 ||
71 0 if ((error = git_index_name_clear(index)) < 0 ||
568 0 16 assert(index);
572 16 0 if (caps == GIT_INDEX_CAPABILITY_FROM_OWNER) {
576 0 16 if (!repo)
580 16 0 if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_IGNORECASE))
582 16 0 if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_FILEMODE))
584 16 0 if (!git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_SYMLINKS))
593 0 16 if (old_ignore_case != index->ignore_case) {
603 0 1 (index->distrust_filemode ? GIT_INDEX_CAPABILITY_NO_FILEMODE : 0) |
604 0 1 (index->no_symlinks ? GIT_INDEX_CAPABILITY_NO_SYMLINKS : 0));
621 0 135 if ((fd = p_open(index->index_file_path, O_RDONLY)) < 0)
624 0 135 if (p_lseek(fd, -20, SEEK_END) < 0) {
633 0 135 if (bytes_read < 0)
645 0 152 if (!index->index_file_path)
651 17 135 if (!index->on_disk) {
652 6 11 if (force && (error = git_index_clear(index)) < 0)
0 6 if (force && (error = git_index_clear(index)) < 0)
659 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) ||
668 125 10 if (!updated && !force)
124 1 if (!updated && !force)
672 0 11 if (error < 0)
680 11 0 if (!error)
683 11 0 if (!error) {
694 0 89 if (git_index__enforce_unsaved_safety && index->dirty) {
0 0 if (git_index__enforce_unsaved_safety && index->dirty) {
707 0 0 if (git_index_read(index, false) < 0)
716 0 111 if (S_ISGITLINK(entry->mode))
737 0 83 if (!INDEX_OWNER(index))
741 0 83 if (!git_repository_workdir(INDEX_OWNER(index)))
745 171 83 git_vector_foreach(&index->entries, i, entry) {
751 61 22 if (paths.length == 0)
757 0 22 if ((error = git_diff_index_to_workdir(&diff, INDEX_OWNER(index), index, &diff_opts)) < 0)
760 0 22 git_vector_foreach(&diff->deltas, i, delta) {
766 0 0 if (entry) {
780 0 3 assert(index);
787 0 1 assert(index);
789 1 0 if (version < INDEX_VERSION_NUMBER_LB ||
0 1 if (version < INDEX_VERSION_NUMBER_LB ||
807 83 0 if ((error = git_indexwriter_init(&writer, index)) == 0 &&
83 0 if ((error = git_indexwriter_init(&writer, index)) == 0 &&
818 0 3 assert(index);
826 38 0 assert(oid && index);
0 38 assert(oid && index);
830 0 38 if (repo == NULL)
840 18 0 assert(oid && index && repo);
18 0 assert(oid && index && repo);
0 18 assert(oid && index && repo);
846 0 270 assert(index);
853 0 419 assert(index);
864 0 170 assert(index);
869 0 170 if (index->ignore_case)
874 23 147 if (!value) {
893 0 0 entry->mode = (!trust_mode && S_ISREG(st->st_mode)) ?
894 0 91 git_index__create_mode(0666) : git_index__create_mode(st->st_mode);
906 200 0 if (path_length < GIT_INDEX_ENTRY_NAMEMASK)
934 52 176 if (from_workdir)
936 52 176 if (st)
939 0 228 if (!git_path_isvalid(repo, path, mode, path_valid_flags)) {
944 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);
945 0 228 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
0 228 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 1);
947 0 228 GIT_ERROR_CHECK_ALLOC(entry);
969 0 52 if (INDEX_OWNER(index) == NULL)
980 0 52 if (git_repository__ensure_not_bare(repo, "create blob from file") < 0)
983 0 52 if (git_buf_joinpath(&path, git_repository_workdir(repo), rel_path) < 0)
989 0 52 if (error < 0)
992 0 52 if (index_entry_create(&entry, INDEX_OWNER(index), rel_path, &st, true) < 0)
999 2 50 if (error < 0) {
1018 0 10 if (GIT_ADD_SIZET_OVERFLOW(&alloclen, structlen, pathlen) ||
0 10 if (GIT_ADD_SIZET_OVERFLOW(&alloclen, structlen, pathlen) ||
1023 0 10 if (!entry)
1041 10 0 assert(reuc_out && path);
0 10 assert(reuc_out && path);
1044 0 10 GIT_ERROR_CHECK_ALLOC(reuc);
1046 10 0 if ((reuc->mode[0] = ancestor_mode) > 0) {
1047 0 10 assert(ancestor_oid);
1051 8 2 if ((reuc->mode[1] = our_mode) > 0) {
1052 0 8 assert(our_oid);
1056 6 4 if ((reuc->mode[2] = their_mode) > 0) {
1057 0 6 assert(their_oid);
1078 0 165 if (index_entry_create(out, INDEX_OWNER(index), src->path, NULL, false) < 0)
1100 0 2 if (index_entry_create(out, INDEX_OWNER(index), src->path, NULL, false) < 0)
1114 109 18 while (pos < index->entries.length) {
1117 105 4 if (len >= p->pathlen)
1119 3 1 if (memcmp(name, p->path, len))
1121 0 1 if (GIT_INDEX_ENTRY_STAGE(&p->entry) != stage)
1123 1 0 if (p->path[len] != '/')
1125 0 0 if (!ok_to_replace)
1128 0 0 if (index_remove_entry(index, --pos) < 0)
1149 13 834 if (*--slash == '/')
1151 124 710 if (slash <= entry->path)
1156 0 13 if (!index_find(&pos, index, name, len, stage)) {
1157 0 0 if (!ok_to_replace)
1160 0 0 if (index_remove_entry(index, pos) < 0)
1170 7 6 for (; pos < index->entries.length; ++pos) {
1173 7 0 if (p->pathlen <= len ||
2 5 if (p->pathlen <= len ||
1174 2 0 p->path[len] != '/' ||
1178 2 0 if (GIT_INDEX_ENTRY_STAGE(&p->entry) == stage)
1208 50 0 if (!index->ignore_case)
1212 0 0 if (existing) {
1218 0 0 if (strchr(entry->path, '/') == NULL)
1221 0 0 if ((search = git__strdup(entry->path)) == NULL)
1227 0 0 while (!best && (sep = strrchr(search, '/'))) {
0 0 while (!best && (sep = strrchr(search, '/'))) {
1235 0 0 while ((match = git_vector_get(&index->entries, pos))) {
1236 0 0 if (GIT_INDEX_ENTRY_STAGE(match) != 0) {
1238 0 0 } else if (strncmp(search, match->path, search_len) == 0) {
1243 0 0 } else if (strncasecmp(search, match->path, search_len) == 0) {
1248 0 0 if (!best) {
1262 0 0 if (best)
1292 57 69 if (error == 0) {
1303 43 26 if (GIT_INDEX_ENTRY_STAGE(entry) == 0) {
1304 19 26 for (; pos < index->entries.length; pos++) {
1306 0 19 index->ignore_case ? git__strcasecmp : git__strcmp;
1310 15 4 if (strcomp(entry->path, e->path) != 0)
1313 2 2 if (GIT_INDEX_ENTRY_STAGE(e) == GIT_INDEX_STAGE_ANCESTOR) {
1349 126 0 assert(index && entry_ptr);
0 126 assert(index && entry_ptr);
1370 76 50 git_index__create_mode(entry->mode) :
1374 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)
1378 69 57 if (!trust_id && INDEX_OWNER(index) &&
43 26 if (!trust_id && INDEX_OWNER(index) &&
43 0 if (!trust_id && INDEX_OWNER(index) &&
1381 0 43 if (!git_object__is_valid(INDEX_OWNER(index), &entry->id,
1389 0 126 if ((error = check_file_directory_collision(index, entry, position, replace)) < 0)
1396 57 69 if (existing) {
1397 57 0 if (replace) {
1400 30 27 if (trust_path)
1412 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 ||
1420 0 126 if (error < 0) {
1435 61 2 if ((ret = git_index_conflict_get(&conflict_entries[0],
1439 2 0 ancestor_mode = conflict_entries[0] == NULL ? 0 : conflict_entries[0]->mode;
1440 2 0 our_mode = conflict_entries[1] == NULL ? 0 : conflict_entries[1]->mode;
1441 2 0 their_mode = conflict_entries[2] == NULL ? 0 : conflict_entries[2]->mode;
1443 2 0 ancestor_oid = conflict_entries[0] == NULL ? NULL : &conflict_entries[0]->id;
1444 2 0 our_oid = conflict_entries[1] == NULL ? NULL : &conflict_entries[1]->id;
1445 2 0 their_oid = conflict_entries[2] == NULL ? NULL : &conflict_entries[2]->id;
1447 2 0 if ((ret = git_index_reuc_add(index, path, ancestor_mode, ancestor_oid,
1456 3 1 return (filemode == GIT_FILEMODE_BLOB ||
1457 4 74 filemode == GIT_FILEMODE_BLOB_EXECUTABLE ||
1 2 filemode == GIT_FILEMODE_BLOB_EXECUTABLE ||
1463 0 69 return (is_file_or_link(filemode) || filemode == GIT_FILEMODE_COMMIT);
0 0 return (is_file_or_link(filemode) || filemode == GIT_FILEMODE_COMMIT);
1474 9 0 assert(index && source_entry->path);
0 9 assert(index && source_entry->path);
1476 0 9 if (INDEX_OWNER(index) == NULL)
1481 2 7 if (!is_file_or_link(source_entry->mode)) {
1486 0 7 if (len > UINT32_MAX) {
1491 0 7 if (index_entry_dup(&entry, index, source_entry) < 0)
1495 0 7 if (error < 0) {
1503 0 7 if ((error = index_insert(index, &entry, 1, true, true, true)) < 0)
1507 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)
1524 0 0 if ((error = git_buf_joinpath(&abspath, git_repository_workdir(repo), path)) < 0)
1527 0 0 if ((error = p_stat(abspath.ptr, &st)) < 0) {
1532 0 0 if (index_entry_create(&entry, INDEX_OWNER(index), path, &st, true) < 0)
1537 0 0 if ((error = git_repository_open(&sub, abspath.ptr)) < 0)
1540 0 0 if ((error = git_repository_head(&head, sub)) < 0)
1559 52 0 assert(index && path);
0 52 assert(index && path);
1561 50 2 if ((ret = index_entry_init(&entry, index, path)) == 0)
1565 2 50 if (ret < 0 && ret != GIT_EDIRECTORY)
2 0 if (ret < 0 && ret != GIT_EDIRECTORY)
1568 0 50 if (ret == GIT_EDIRECTORY) {
1575 0 0 if (ret == GIT_ENOTFOUND)
1584 0 0 if (ret == GIT_EEXISTS) {
1585 0 0 if ((ret = add_repo_as_submodule(&entry, index, path)) < 0)
1588 0 0 if ((ret = index_insert(index, &entry, 1, false, false, true)) < 0)
1590 0 0 } else if (ret < 0) {
1600 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)
1611 6 0 assert(index && path);
0 6 assert(index && path);
1613 0 6 if (((ret = git_index_remove(index, path, 0)) < 0 &&
0 0 if (((ret = git_index_remove(index, path, 0)) < 0 &&
1614 6 0 ret != GIT_ENOTFOUND) ||
1615 0 6 ((ret = index_conflict_to_reuc(index, path)) < 0 &&
1619 6 0 if (ret == GIT_ENOTFOUND)
1631 0 28 assert(index);
1633 3 25 if (!source_entries->length)
1641 63 25 git_vector_foreach(source_entries, i, source_entry) {
1644 0 63 if ((error = index_entry_dup(&entry, index, source_entry)) < 0)
1651 0 63 if ((error = git_vector_insert(&index->entries, entry)) < 0)
1654 0 63 if ((error = index_map_set(index->entries_map, entry, index->ignore_case)) < 0)
1660 25 0 if (!error)
1672 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);
1674 0 52 if (!valid_filemode(source_entry->mode)) {
1679 52 0 if ((ret = index_entry_dup(&entry, index, source_entry)) < 0 ||
0 52 if ((ret = index_entry_dup(&entry, index, source_entry)) < 0 ||
1698 35 15 if (index_find(&position, index, path, 0, stage) < 0) {
1716 1 0 if (!(error = git_buf_sets(&pfx, dir)) &&
1 0 if (!(error = git_buf_sets(&pfx, dir)) &&
1720 1 0 while (!error) {
1722 1 0 if (!entry || git__prefixcmp(entry->path, pfx.ptr) != 0)
0 1 if (!entry || git__prefixcmp(entry->path, pfx.ptr) != 0)
1725 0 0 if (GIT_INDEX_ENTRY_STAGE(entry) != stage) {
1748 0 0 if (!entry || git__prefixcmp(entry->path, prefix) != 0)
0 0 if (!entry || git__prefixcmp(entry->path, prefix) != 0)
1751 0 0 if (!error && at_pos)
0 0 if (!error && at_pos)
1760 1192 0 assert(index && path);
0 1192 assert(index && path);
1768 71 0 assert(index && path);
0 71 assert(index && path);
1770 7 64 if (git_vector_bsearch2(
1779 28 49 for (; pos > 0; --pos) {
1782 15 13 if (index->entries_cmp_path(prev->path, path) != 0)
1786 64 0 if (at_pos)
1801 0 6 assert (index);
1803 6 0 if ((ancestor_entry &&
6 0 if ((ancestor_entry &&
1804 5 1 (ret = index_entry_dup(&entries[0], index, ancestor_entry)) < 0) ||
1805 5 0 (our_entry &&
1806 6 0 (ret = index_entry_dup(&entries[1], index, our_entry)) < 0) ||
1807 6 0 (their_entry &&
1812 18 6 for (i = 0; i < 3; i++) {
1813 17 1 if (entries[i] && !valid_filemode(entries[i]->mode)) {
0 17 if (entries[i] && !valid_filemode(entries[i]->mode)) {
1822 18 6 for (i = 0; i < 3; i++) {
1823 1 17 if (entries[i] == NULL)
1826 17 0 if ((ret = git_index_remove(index, entries[i]->path, 0)) != 0) {
1827 0 17 if (ret != GIT_ENOTFOUND)
1836 18 6 for (i = 0; i < 3; i++) {
1837 1 17 if (entries[i] == NULL)
1843 0 17 if ((ret = index_insert(index, &entries[i], 1, true, true, false)) < 0)
1852 0 0 for (i = 0; i < 3; i++) {
1853 0 0 if (entries[i] != NULL)
1872 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);
1878 108 32 for (count = git_index_entrycount(index); n < count; ++n) {
1881 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)
1918 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);
1924 6 58 if (git_index_find(&pos, index, path) < 0)
1927 0 58 if ((len = index_conflict__get_byindex(
1930 55 3 else if (len == 0)
1942 5 1 if (path != NULL && git_index_find(&pos, index, path) < 0)
0 5 if (path != NULL && git_index_find(&pos, index, path) < 0)
1945 16 5 while ((conflict_entry = git_vector_get(&index->entries, pos)) != NULL) {
1951 3 12 if (GIT_INDEX_ENTRY_STAGE(conflict_entry) == 0) {
1956 0 12 if ((error = index_remove_entry(index, pos)) < 0)
1965 5 0 assert(index && path);
0 5 assert(index && path);
1971 0 1 assert(index);
1980 0 121 assert(index);
1982 291 113 git_vector_foreach(&index->entries, i, entry) {
1983 8 283 if (GIT_INDEX_ENTRY_STAGE(entry) > 0)
1997 0 0 assert(iterator_out && index);
0 0 assert(iterator_out && index);
2000 0 0 GIT_ERROR_CHECK_ALLOC(it);
2002 0 0 if ((error = git_index_snapshot_new(&it->snap, index)) < 0) {
2017 0 0 assert(out && it);
0 0 assert(out && it);
2019 0 0 if (it->cur >= git_vector_length(&it->snap))
2028 0 0 if (it == NULL)
2041 69 0 assert(iterator_out && index);
0 69 assert(iterator_out && index);
2044 0 69 GIT_ERROR_CHECK_ALLOC(it);
2061 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);
2067 144 69 while (iterator->cur < iterator->index->entries.length) {
2070 4 140 if (git_index_entry_is_conflict(entry)) {
2071 0 4 if ((len = index_conflict__get_byindex(
2091 0 69 if (iterator == NULL)
2099 0 17 assert(index);
2106 0 0 assert(index);
2114 0 0 if (!ne)
2127 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));
2130 0 0 GIT_ERROR_CHECK_ALLOC(conflict_name);
2132 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))) ||
2133 0 0 (ours && !(conflict_name->ours = git__strdup(ours))) ||
0 0 (ours && !(conflict_name->ours = git__strdup(ours))) ||
2150 0 123 assert(index);
2152 0 123 git_vector_foreach(&index->names, i, conflict_name)
2164 0 0 assert(index);
2181 10 0 assert(index && reuc && reuc->path != NULL);
10 0 assert(index && reuc && reuc->path != NULL);
0 10 assert(index && reuc && reuc->path != NULL);
2182 0 10 assert(git_vector_is_sorted(&index->reuc));
2187 6 4 return res == GIT_EEXISTS ? 0 : res;
2198 10 0 assert(index && path);
0 10 assert(index && path);
2200 10 0 if ((error = index_entry_reuc_init(&reuc, path, ancestor_mode,
2201 0 10 ancestor_oid, our_mode, our_oid, their_mode, their_oid)) < 0 ||
2217 6 0 assert(index && path);
0 6 assert(index && path);
2219 2 4 if (!index->reuc.length)
2222 0 4 assert(git_vector_is_sorted(&index->reuc));
2224 0 4 if (git_index_reuc_find(&pos, index, path) < 0)
2233 0 0 assert(index);
2234 0 0 assert(git_vector_is_sorted(&index->reuc));
2244 0 0 assert(git_vector_is_sorted(&index->reuc));
2249 0 0 if (!error)
2260 0 123 assert(index);
2262 6 123 for (i = 0; i < index->reuc.length; ++i)
2289 0 0 while (size) {
2293 0 0 if (size <= len)
2297 0 0 GIT_ERROR_CHECK_ALLOC(lost);
2303 0 0 for (i = 0; i < 3; i++) {
2306 0 0 if (git__strntol64(&tmp, buffer, size, &endptr, 8) < 0 ||
0 0 if (git__strntol64(&tmp, buffer, size, &endptr, 8) < 0 ||
2307 0 0 !endptr || endptr == buffer || *endptr ||
0 0 !endptr || endptr == buffer || *endptr ||
0 0 !endptr || endptr == buffer || *endptr ||
2308 0 0 tmp < 0 || tmp > UINT32_MAX) {
2316 0 0 if (size <= len) {
2326 0 0 for (i = 0; i < 3; i++) {
2327 0 0 if (!lost->mode[i])
2329 0 0 if (size < 20) {
2340 0 0 if (git_vector_insert(&index->reuc, lost) < 0)
2377 0 0 while (size) {
2379 0 0 GIT_ERROR_CHECK_ALLOC(conflict_name);
2381 0 0 read_conflict_name(conflict_name->ancestor);
0 0 read_conflict_name(conflict_name->ancestor);
0 0 read_conflict_name(conflict_name->ancestor);
2382 0 0 read_conflict_name(conflict_name->ours);
0 0 read_conflict_name(conflict_name->ours);
0 0 read_conflict_name(conflict_name->ours);
2383 0 0 read_conflict_name(conflict_name->theirs);
0 0 read_conflict_name(conflict_name->theirs);
0 0 read_conflict_name(conflict_name->theirs);
2385 0 0 if (git_vector_insert(&index->names, conflict_name) < 0)
2408 0 232 if (varint_len) {
2409 0 0 if (flags & GIT_INDEX_ENTRY_EXTENDED)
2415 0 232 if (flags & GIT_INDEX_ENTRY_EXTENDED)
2438 0 26 if (INDEX_FOOTER_SIZE + minimal_entry_size > buffer_size)
2457 0 26 if (entry.flags & GIT_INDEX_ENTRY_EXTENDED) {
2471 26 0 if (!compressed) {
2476 0 26 if (path_length == 0xFFF) {
2480 0 0 if (path_end == NULL)
2495 0 0 if (varint_len == 0 || last_len < strip_len)
0 0 if (varint_len == 0 || last_len < strip_len)
2501 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);
2502 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&path_len, path_len, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&path_len, path_len, 1);
2504 0 0 if (path_len > GIT_PATH_MAX)
2508 0 0 GIT_ERROR_CHECK_ALLOC(tmp_path);
2516 0 26 if (entry_size == 0)
2519 0 26 if (INDEX_FOOTER_SIZE + entry_size > buffer_size)
2522 0 26 if (index_entry_dup(out, index, &entry) < 0) {
2537 0 11 if (dest->signature != INDEX_HEADER_SIG)
2541 11 0 if (dest->version < INDEX_VERSION_NUMBER_LB ||
0 11 if (dest->version < INDEX_VERSION_NUMBER_LB ||
2560 11 0 if (dest.extension_size > total_size ||
11 0 if (dest.extension_size > total_size ||
2561 0 11 buffer_size < total_size ||
2568 11 0 if (dest.signature[0] >= 'A' && dest.signature[0] <= 'Z') {
11 0 if (dest.signature[0] >= 'A' && dest.signature[0] <= 'Z') {
2570 11 0 if (memcmp(dest.signature, INDEX_EXT_TREECACHE_SIG, 4) == 0) {
2571 0 11 if (git_tree_cache_read(&index->tree, buffer + 8, dest.extension_size, &index->tree_pool) < 0)
2573 0 0 } else if (memcmp(dest.signature, INDEX_EXT_UNMERGED_SIG, 4) == 0) {
2574 0 0 if (read_reuc(index, buffer + 8, dest.extension_size) < 0)
2576 0 0 } else if (memcmp(dest.signature, INDEX_EXT_CONFLICT_NAME_SIG, 4) == 0) {
2577 0 0 if (read_conflict_names(index, buffer + 8, dest.extension_size) < 0)
2611 0 11 if (buffer_size < INDEX_HEADER_SIZE + INDEX_FOOTER_SIZE)
2619 0 11 if ((error = read_header(&header, buffer)) < 0)
2623 0 11 if (index->version >= INDEX_VERSION_NUMBER_COMP)
2626 0 11 seek_forward(INDEX_HEADER_SIZE);
2628 0 11 assert(!index->entries.length);
2630 0 11 if ((error = index_map_resize(index->entries_map, header.entry_count, index->ignore_case)) < 0)
2634 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) {
2638 0 26 if ((error = read_entry(&entry, &entry_size, index, buffer, buffer_size, last)) < 0) {
2643 0 26 if ((error = git_vector_insert(&index->entries, entry)) < 0) {
2648 0 26 if ((error = index_map_set(index->entries_map, entry, index->ignore_case)) < 0) {
2654 0 26 if (index->version >= INDEX_VERSION_NUMBER_COMP)
2657 0 26 seek_forward(entry_size);
2660 0 11 if (i != header.entry_count) {
2666 11 11 while (buffer_size > INDEX_FOOTER_SIZE) {
2669 0 11 if ((error = read_extension(&extension_size, index, buffer, buffer_size)) < 0) {
2673 0 11 seek_forward(extension_size);
2676 0 11 if (buffer_size != INDEX_FOOTER_SIZE) {
2685 0 11 if (git_oid__cmp(&checksum_calculated, &checksum_expected) != 0) {
2698 11 0 git_vector_set_sorted(&index->entries, !index->ignore_case);
2713 206 97 git_vector_foreach(&index->entries, i, entry) {
2715 0 206 if (entry->flags_extended & GIT_INDEX_ENTRY_EXTENDED_FLAGS) {
2736 0 206 if (last) {
2739 0 0 while (*path_start == *last_c) {
2740 0 0 if (!*path_start || !*last_c)
0 0 if (!*path_start || !*last_c)
2752 0 206 if (git_filebuf_reserve(file, &mem, disk_size) < 0)
2782 0 206 if (entry->flags & GIT_INDEX_ENTRY_EXTENDED) {
2796 0 206 if (last) {
2799 0 0 assert(varint_len > 0);
2807 0 0 assert(disk_size == path_len + 1);
2814 0 206 assert(disk_size > path_len);
2832 0 97 if (index->ignore_case) {
2840 0 97 if (index->version >= INDEX_VERSION_NUMBER_COMP)
2843 206 97 git_vector_foreach(entries, i, entry) {
2844 0 206 if ((error = write_disk_entry(file, entry, last)) < 0)
2846 0 206 if (index->version >= INDEX_VERSION_NUMBER_COMP)
2850 0 97 if (index->ignore_case)
2872 0 0 if (conflict_name->ancestor == NULL)
2877 0 0 if (error != 0)
2880 0 0 if (conflict_name->ours == NULL)
2885 0 0 if (error != 0)
2888 0 0 if (conflict_name->theirs == NULL)
2906 0 0 git_vector_foreach(out, i, conflict_name) {
2907 0 0 if ((error = create_name_extension_data(&name_buf, conflict_name)) < 0)
2928 0 5 if ((error = git_buf_put(reuc_buf, reuc->path, strlen(reuc->path) + 1)) < 0)
2931 15 5 for (i = 0; i < 3; i++) {
2932 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 ||
2937 15 5 for (i = 0; i < 3; i++) {
2938 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)
2954 5 5 git_vector_foreach(out, i, reuc) {
2955 0 5 if ((error = create_reuc_extension_data(&reuc_buf, reuc)) < 0)
2977 0 92 if (index->tree == NULL)
2980 0 92 if ((error = git_tree_cache_write(&buf, index->tree)) < 0)
2999 212 99 git_vector_foreach(&index->entries, i, entry)
3010 97 0 assert(index && file);
0 97 assert(index && file);
3012 97 0 if (index->version <= INDEX_VERSION_NUMBER_EXT) {
3014 0 97 index_version_number = is_extended ? INDEX_VERSION_NUMBER_EXT : INDEX_VERSION_NUMBER_LB;
3023 0 97 if (git_filebuf_write(file, &header, sizeof(struct index_header)) < 0)
3026 0 97 if (write_entries(index, file) < 0)
3030 92 5 if (index->tree != NULL && write_tree_extension(index, file) < 0)
0 92 if (index->tree != NULL && write_tree_extension(index, file) < 0)
3034 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)
3038 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)
3046 0 97 if (git_filebuf_write(file, hash_final.id, GIT_OID_RAWSZ) < 0)
3081 4 9 if (git_tree_entry__is_tree(tentry))
3084 0 9 if (git_buf_joinpath(&path, root, tentry->filename) < 0)
3087 0 9 if (index_entry_create(&entry, INDEX_OWNER(data->index), path.ptr, NULL, false) < 0)
3096 9 0 &pos, data->old_entries, data->entry_cmp, path.ptr, 0, 0) &&
3097 9 0 (old_entry = git_vector_get(data->old_entries, pos)) != NULL &&
3098 9 0 entry->mode == old_entry->mode &&
3108 0 9 if (git_vector_insert(data->new_entries, entry) < 0) {
3125 0 5 if (git_idxmap_new(&entries_map) < 0)
3140 0 5 if ((error = git_tree_walk(tree, GIT_TREEWALK_POST, read_tree_cb, &data)) < 0)
3143 0 5 if ((error = index_map_resize(entries_map, entries.length, index->ignore_case)) < 0)
3146 9 5 git_vector_foreach(&entries, i, e) {
3147 0 9 if ((error = index_map_set(entries_map, e, index->ignore_case)) < 0) {
3157 5 0 if ((error = git_index_clear(index)) < 0) {
3169 0 5 if (error < 0)
3192 0 2 assert((new_iterator->flags & GIT_ITERATOR_DONT_IGNORE_CASE));
3194 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 ||
3195 2 0 (error = git_vector_init(&remove_entries, index->entries.length, NULL)) < 0 ||
3199 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,
3206 2 0 if ((error = git_iterator_for_index(&index_iterator,
3207 0 2 git_index_owner(index), index, &opts)) < 0 ||
3208 0 0 ((error = git_iterator_current(&old_entry, index_iterator)) < 0 &&
3209 0 2 error != GIT_ITEROVER) ||
3210 0 0 ((error = git_iterator_current(&new_entry, new_iterator)) < 0 &&
3223 6 2 if (old_entry && new_entry)
6 0 if (old_entry && new_entry)
3225 2 0 else if (!old_entry && new_entry)
0 2 else if (!old_entry && new_entry)
3227 0 2 else if (old_entry && !new_entry)
0 0 else if (old_entry && !new_entry)
3232 0 6 if (diff < 0) {
3234 0 6 } else if (diff > 0) {
3240 4 2 if (git_oid_equal(&old_entry->id, &new_entry->id) &&
4 0 if (git_oid_equal(&old_entry->id, &new_entry->id) &&
3249 2 4 if (dup_entry) {
3250 0 2 if ((error = index_entry_dup_nocache(&add_entry, index, dup_entry)) < 0)
3260 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)
3263 6 0 if (add_entry) {
3264 6 0 if ((error = git_vector_insert(&new_entries, add_entry)) == 0)
3269 2 4 if (remove_entry && error >= 0)
2 0 if (remove_entry && error >= 0)
3272 0 6 if (error < 0) {
3277 6 0 if (diff <= 0) {
3278 2 4 if ((error = git_iterator_advance(&old_entry, index_iterator)) < 0 &&
0 2 if ((error = git_iterator_advance(&old_entry, index_iterator)) < 0 &&
3283 6 0 if (diff >= 0) {
3284 2 4 if ((error = git_iterator_advance(&new_entry, new_iterator)) < 0 &&
0 2 if ((error = git_iterator_advance(&new_entry, new_iterator)) < 0 &&
3290 2 0 if ((error = git_index_name_clear(index)) < 0 ||
2 0 if ((error = git_index_name_clear(index)) < 0 ||
3297 2 2 git_vector_foreach(&remove_entries, i, entry) {
3298 2 0 if (index->tree)
3328 2 0 if ((error = git_iterator_for_index(&new_iterator,
3364 0 4 assert(index);
3367 0 4 if ((error = git_repository__ensure_not_bare(repo, "index add all")) < 0)
3370 0 4 if ((error = git_pathspec__init(&ps, paths)) < 0)
3374 0 4 if ((flags & GIT_INDEX_ADD_CHECK_PATHSPEC) != 0 &&
0 0 if ((flags & GIT_INDEX_ADD_CHECK_PATHSPEC) != 0 &&
3375 0 0 (flags & GIT_INDEX_ADD_FORCE) == 0 &&
3382 0 4 if (error)
3411 6 6 if (!git_pathspec__match(
3416 6 0 if (data->cb)
3419 1 5 if (error > 0) /* skip this entry */
3421 1 4 if (error < 0) /* actual error */
3425 0 4 if ((delta->new_file.flags & GIT_DIFF_FLAG_EXISTS) == 0)
3450 0 8 assert(index);
3451 4 4 assert(action == INDEX_ACTION_UPDATE || action == INDEX_ACTION_ADDALL);
0 4 assert(action == INDEX_ACTION_UPDATE || action == INDEX_ACTION_ADDALL);
3455 0 8 if (!repo) {
3465 0 8 if ((error = git_pathspec__init(&ps, paths)) < 0)
3469 4 4 if (action == INDEX_ACTION_ADDALL) {
3473 1 3 if (flags == GIT_INDEX_ADD_FORCE)
3477 0 8 if ((error = git_diff_index_to_workdir(&diff, repo, index, &opts)) < 0)
3484 1 7 if (error) /* make sure error is set if callback stopped iteration */
3505 0 1 assert(index);
3507 0 1 if ((error = git_pathspec__init(&ps, paths)) < 0)
3512 2 0 for (i = 0; !error && i < index->entries.length; ++i) {
1 1 for (i = 0; !error && i < index->entries.length; ++i) {
3516 0 1 if (!git_pathspec__match(
3522 1 0 if (cb && (error = cb(entry->path, match, payload)) != 0) {
0 1 if (cb && (error = cb(entry->path, match, payload)) != 0) {
3523 0 0 if (error > 0) { /* return > 0 means skip this one */
3527 0 0 if (error < 0) /* return < 0 means abort */
3532 0 1 if ((error = git_buf_sets(&path, entry->path)) < 0)
3541 0 0 if (error == GIT_ENOTFOUND) {
3546 0 0 if (!error) /* back up foreach if we removed this */
3551 1 0 if (!(error = git_index_remove_bypath(index, path.ptr)))
3576 0 1 if (error) /* make sure error is set if callback stopped iteration */
3589 1 3 if (error) /* make sure error is set if callback stopped iteration */
3606 0 431 if (error < 0)
3638 0 98 if (!index->index_file_path)
3642 0 98 if ((error = git_filebuf_open(
3645 0 0 if (error == GIT_ELOCKED)
3664 15 0 if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
0 15 if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
3679 0 97 if (!writer->should_write)
3685 0 97 if ((error = write_index(&checksum, writer->index, &writer->file)) < 0) {
3690 0 97 if ((error = git_filebuf_commit(&writer->file)) < 0)
3693 0 97 if ((error = git_futils_filestamp_check(