]> git.ipfire.org Git - thirdparty/git.git/blobdiff - read-cache.c
read-cache: add index.skipHash config option
[thirdparty/git.git] / read-cache.c
index 46f5e497b142a912ca27a19ad2defb6f50ba4f89..d73a81e41ae6e8dca3bd752bd11b4bf6a108e634 100644 (file)
@@ -1817,6 +1817,8 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
        git_hash_ctx c;
        unsigned char hash[GIT_MAX_RAWSZ];
        int hdr_version;
+       unsigned char *start, *end;
+       struct object_id oid;
 
        if (hdr->hdr_signature != htonl(CACHE_SIGNATURE))
                return error(_("bad signature 0x%08x"), hdr->hdr_signature);
@@ -1827,10 +1829,16 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
        if (!verify_index_checksum)
                return 0;
 
+       end = (unsigned char *)hdr + size;
+       start = end - the_hash_algo->rawsz;
+       oidread(&oid, start);
+       if (oideq(&oid, null_oid()))
+               return 0;
+
        the_hash_algo->init_fn(&c);
        the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);
        the_hash_algo->final_fn(hash, &c);
-       if (!hasheq(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))
+       if (!hasheq(hash, start))
                return error(_("bad index file sha1 signature"));
        return 0;
 }
@@ -2915,9 +2923,12 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
        int ieot_entries = 1;
        struct index_entry_offset_table *ieot = NULL;
        int nr, nr_threads;
+       struct repository *r = istate->repo ? istate->repo : the_repository;
 
        f = hashfd(tempfile->fd, tempfile->filename.buf);
 
+       repo_config_get_bool(r, "index.skiphash", &f->skip_hash);
+
        for (i = removed = extended = 0; i < entries; i++) {
                if (cache[i]->ce_flags & CE_REMOVE)
                        removed++;