Skip to content


fixup! read-cache: run verify_hdr() in background thread
Browse files Browse the repository at this point in the history
Since picking up a33fc72 (read-cache: force_verify_index_checksum,
2017-04-14), we do not even check the SHA-1 of the index by default
anymore, therefore we no longer need this workaround.

Noticed by Ben Peart.

This reverts commit 480829f.

Signed-off-by: Johannes Schindelin <>
  • Loading branch information
dscho committed Dec 8, 2017
1 parent 5d5baf9 commit 603511c
Showing 1 changed file with 0 additions and 60 deletions.
60 changes: 0 additions & 60 deletions read-cache.c
Expand Up @@ -20,10 +20,6 @@
#include "split-index.h"
#include "utf8.h"

#include <pthread.h>

/* Mask for the name length in ce_flags in the on-disk index */

#define CE_NAMEMASK (0x0fff)
Expand Down Expand Up @@ -1538,34 +1534,6 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
return 0;

* Require index file to be larger than this threshold before
* we bother using a thread to verify the SHA.
* This value was arbitrarily chosen.
#define VERIFY_HDR_THRESHOLD 10*1024*1024

struct verify_hdr_thread_data
pthread_t thread_id;
struct cache_header *hdr;
size_t size;
int result;

* A thread proc to run the verify_hdr() computation
* in a background thread.
static void *verify_hdr_thread(void *_data)
struct verify_hdr_thread_data *p = _data;
p->result = verify_hdr(p->hdr, (unsigned long)p->size);
return NULL;

static int read_index_extension(struct index_state *istate,
const char *ext, void *data, unsigned long sz)
Expand Down Expand Up @@ -1767,9 +1735,6 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
void *mmap;
size_t mmap_size;
struct strbuf previous_name_buf = STRBUF_INIT, *previous_name;
struct verify_hdr_thread_data verify_hdr_thread_data;

if (istate->initialized)
return istate->cache_nr;
Expand All @@ -1796,23 +1761,8 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)

hdr = mmap;
if (verify_hdr(hdr, mmap_size) < 0)
goto unmap;
if (mmap_size < VERIFY_HDR_THRESHOLD) {
if (verify_hdr(hdr, mmap_size) < 0)
goto unmap;
} else {
verify_hdr_thread_data.hdr = hdr;
verify_hdr_thread_data.size = mmap_size;
verify_hdr_thread_data.result = -1;
if (pthread_create(
&verify_hdr_thread_data.thread_id, NULL,
verify_hdr_thread, &verify_hdr_thread_data))
die_errno("unable to start verify_hdr_thread");

hashcpy(istate->sha1, (const unsigned char *)hdr + mmap_size - 20);
istate->version = ntohl(hdr->hdr_version);
Expand Down Expand Up @@ -1860,16 +1810,6 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
src_offset += 8;
src_offset += extsize;

if (mmap_size >= VERIFY_HDR_THRESHOLD) {
if (pthread_join(verify_hdr_thread_data.thread_id, NULL))
die_errno("unable to join verify_hdr_thread");
if (verify_hdr_thread_data.result < 0)
goto unmap;

munmap(mmap, mmap_size);
return istate->cache_nr;

Expand Down

0 comments on commit 603511c

Please sign in to comment.