MCPcopy Create free account
hub / github.com/git/git / verify_one

Function verify_one

cache-tree.c:919–1028  ·  view source on GitHub ↗

* Returns: * 0 - Verification completed. * 1 - Restart verification - a call to ensure_full_index() freed the cache * tree that is being verified and verification needs to be restarted from * the new toplevel cache tree. * -1 - Verification failed. */

Source from the content-addressed store, hash-verified

917 * -1 - Verification failed.
918 */
919static int verify_one(struct repository *r,
920 struct index_state *istate,
921 struct cache_tree *it,
922 struct strbuf *path)
923{
924 int i, pos, len = path->len;
925 struct strbuf tree_buf = STRBUF_INIT;
926 struct object_id new_oid;
927 int ret;
928
929 for (i = 0; i < it->subtree_nr; i++) {
930 strbuf_addf(path, "%s/", it->down[i]->name);
931 ret = verify_one(r, istate, it->down[i]->cache_tree, path);
932 if (ret)
933 goto out;
934
935 strbuf_setlen(path, len);
936 }
937
938 if (it->entry_count < 0 ||
939 /* no verification on tests (t7003) that replace trees */
940 lookup_replace_object(r, &it->oid) != &it->oid) {
941 ret = 0;
942 goto out;
943 }
944
945 if (path->len) {
946 /*
947 * If the index is sparse and the cache tree is not
948 * index_name_pos() may trigger ensure_full_index() which will
949 * free the tree that is being verified.
950 */
951 int is_sparse = istate->sparse_index;
952 pos = index_name_pos(istate, path->buf, path->len);
953 if (is_sparse && !istate->sparse_index) {
954 ret = 1;
955 goto out;
956 }
957
958 if (pos >= 0) {
959 ret = verify_one_sparse(istate, path, pos);
960 goto out;
961 }
962
963 pos = -pos - 1;
964 } else {
965 pos = 0;
966 }
967
968 if (it->entry_count + pos > istate->cache_nr) {
969 ret = error(_("corrupted cache-tree has entries not present in index"));
970 goto out;
971 }
972
973 i = 0;
974 while (i < it->entry_count) {
975 struct cache_entry *ce = istate->cache[pos + i];
976 const char *slash;

Callers 1

cache_tree_verifyFunction · 0.85

Calls 12

strbuf_addfFunction · 0.85
strbuf_setlenFunction · 0.85
lookup_replace_objectFunction · 0.85
index_name_posFunction · 0.85
verify_one_sparseFunction · 0.85
errorFunction · 0.85
find_subtreeFunction · 0.85
strbuf_addFunction · 0.85
hash_object_fileFunction · 0.85
oideqFunction · 0.85
oid_to_hexFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected