From: Nguyễn Thái Ngọc Duy Date: Tue, 13 May 2014 11:15:36 GMT Subject: [PATCH 7/8] read-cache: skip verifying trailing SHA-1 on cached index Message-ID: <1399979737-8577-10-git-send-email-pclouds@gmail.com> In-Reply-To: <1399979737-8577-1-git-send-email-pclouds@gmail.com> The daemon is responsible for verifying the index before putting it in the shared memory. No need to redo it again. Signed-off-by: Nguyễn Thái Ngọc Duy --- read-cache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/read-cache.c b/read-cache.c index 4041485..e98521f 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1332,6 +1332,8 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size) hdr_version = ntohl(hdr->hdr_version); if (hdr_version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < hdr_version) return error("bad index version %d", hdr_version); + if (!size) + return 0; git_SHA1_Init(&c); git_SHA1_Update(&c, hdr, size - 20); git_SHA1_Final(sha1, &c); @@ -1511,7 +1513,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) struct stat st; unsigned long src_offset; struct cache_header *hdr; - void *mmap; + void *mmap, *old_mmap; size_t mmap_size; struct strbuf previous_name_buf = STRBUF_INIT, *previous_name; @@ -1543,9 +1545,10 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) } close(fd); + old_mmap = mmap; mmap = try_shm(mmap, &mmap_size); hdr = mmap; - if (verify_hdr(hdr, mmap_size) < 0) + if (verify_hdr(hdr, old_mmap != mmap ? 0 : mmap_size) < 0) goto unmap; hashcpy(istate->sha1, (const unsigned char *)hdr + mmap_size - 20); -- 1.9.1.346.ga2b5940