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

Function verify_index_from

read-cache.c:2695–2728  ·  view source on GitHub ↗

* This function verifies if index_state has the correct sha1 of the * index file. Don't die if we have any other failure, just return 0. */

Source from the content-addressed store, hash-verified

2693 * index file. Don't die if we have any other failure, just return 0.
2694 */
2695static int verify_index_from(const struct index_state *istate, const char *path)
2696{
2697 int fd;
2698 ssize_t n;
2699 struct stat st;
2700 unsigned char hash[GIT_MAX_RAWSZ];
2701
2702 if (!istate->initialized)
2703 return 0;
2704
2705 fd = open(path, O_RDONLY);
2706 if (fd < 0)
2707 return 0;
2708
2709 if (fstat(fd, &st))
2710 goto out;
2711
2712 if (st.st_size < sizeof(struct cache_header) + the_hash_algo->rawsz)
2713 goto out;
2714
2715 n = pread_in_full(fd, hash, the_hash_algo->rawsz, st.st_size - the_hash_algo->rawsz);
2716 if (n != the_hash_algo->rawsz)
2717 goto out;
2718
2719 if (!hasheq(istate->oid.hash, hash, the_repository->hash_algo))
2720 goto out;
2721
2722 close(fd);
2723 return 1;
2724
2725out:
2726 close(fd);
2727 return 0;
2728}
2729
2730static int repo_verify_index(struct repository *repo)
2731{

Callers 1

repo_verify_indexFunction · 0.85

Calls 2

pread_in_fullFunction · 0.85
hasheqFunction · 0.85

Tested by

no test coverage detected