git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 1/2] read-cache: core.checksumindex

From
Ggit@jeffhostetler.com <git@jeffhostetler.com>
Date
Mar 28, 2017, 19:07 UTC
Message-ID
<20170328190732.59486-2-git@jeffhostetler.com>
In-Reply-To
<20170328190732.59486-1-git@jeffhostetler.com>
From: Jeff Hostetler <jeffhost@microsoft.com>

Teach git to skip verification of the index SHA in verify_hdr() in read_index().

This is a performance optimization. The index file SHA verification can be considered an ancient relic from the early days of git and only useful for detecting disk corruption. For small repositories, this SHA calculation is not that significant, but for gigantic repositories this calculation adds significant time to every command.

Added "core.checksumindex" to enable/disable the SHA verification.
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
 read-cache.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff --git a/read-cache.c b/read-cache.c
index 9054369..2ab4b74 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1376,12 +1376,24 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
 	git_SHA_CTX c;
 	unsigned char sha1[20];
 	int hdr_version;
+	int do_checksum = 0;
 
 	if (hdr->hdr_signature != htonl(CACHE_SIGNATURE))
 		return error("bad signature");
 	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);
+
+	/*
+	 * Since we run very early in command startup, git_config()
+	 * may not have been called yet and the various "core_*"
+	 * global variables haven't been set.  So look it up
+	 * explicitly.
+	 */
+	git_config_get_bool("core.checksumindex", &do_checksum);
+	if (!do_checksum)
+		return 0;
+
 	git_SHA1_Init(&c);
 	git_SHA1_Update(&c, hdr, size - 20);
 	git_SHA1_Final(sha1, &c);
-- 
2.9.3
Previous: git@jeffhostetler.comNext: git@jeffhostetler.com
Message 2 of 13 in “read-cache: call verify_hdr() in a background thread”
  1. 0/2 read-cache: call verify_hdr() in a background threadgit@jeffhostetler.com, Mar 28, 2017
  2. 1/2 read-cache: core.checksumindexgit@jeffhostetler.com, Mar 28, 2017
  3. 2/2 test-core-checksum-index: core.checksumindex test helpergit@jeffhostetler.com, Mar 28, 2017
  4. Jeff KingMar 28, 2017
  5. Jeff HostetlerMar 28, 2017
  6. Jeff KingMar 28, 2017
  7. Junio C HamanoMar 30, 2017
  8. Jeff KingMar 30, 2017
  9. Junio C HamanoMar 30, 2017
  10. Jeff HostetlerMar 31, 2017
  11. Thomas GummererMar 30, 2017
  12. Jeff KingMar 30, 2017
  13. Jeff HostetlerMar 31, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.