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

[PATCH v2 1/2] read-cache: skip index SHA verification

From
Ggit@jeffhostetler.com <git@jeffhostetler.com>
Date
Mar 27, 2017, 21:09 UTC
Message-ID
<1490648979-49580-2-git-send-email-git@jeffhostetler.com>
In-Reply-To
<1490648979-49580-1-git-send-email-git@jeffhostetler.com>
From: Jeff Hostetler <jeffhost@microsoft.com>
Teach git to skip verification of the index SHA 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.

I added a global "skip_verify_index" variable to control this and allow it to be tested.

I did not create a config setting for this because of chicken-n-egg problems with the loading the config and the index.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
 cache.h      | 5 +++++
 read-cache.c | 6 ++++++
 2 files changed, 11 insertions(+)
diff --git a/cache.h b/cache.h
index 80b6372..4e9182f 100644
--- a/cache.h
+++ b/cache.h
@@ -740,6 +740,11 @@ extern int protect_ntfs;
 extern int git_db_env, git_index_env, git_graft_env, git_common_dir_env;
 
 /*
+ * When set, skip verification of the index SHA in read_index().
+ */
+extern int skip_verify_index;
+
+/*
  * Include broken refs in all ref iterations, which will
  * generally choke dangerous operations rather than letting
  * them silently proceed without taking the broken ref into
diff --git a/read-cache.c b/read-cache.c
index 9054369..1ca69c3 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -46,6 +46,8 @@
 struct index_state the_index;
 static const char *alternate_index_output;
 
+int skip_verify_index = 1;
+
 static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
 {
 	istate->cache[nr] = ce;
@@ -1382,6 +1384,10 @@ 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 (skip_verify_index)
+		return 0;
+
 	git_SHA1_Init(&c);
 	git_SHA1_Update(&c, hdr, size - 20);
 	git_SHA1_Final(sha1, &c);
-- 
2.7.4
Previous: git@jeffhostetler.comNext: Jeff King
Message 2 of 10 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 27, 2017
  2. 1/2 read-cache: skip index SHA verificationgit@jeffhostetler.com, Mar 27, 2017
  3. Jeff KingMar 27, 2017
  4. Jonathan NiederMar 27, 2017
  5. Jeff KingMar 27, 2017
  6. Jeff HostetlerMar 28, 2017
  7. Jeff KingMar 28, 2017
  8. 2/2 skip_verify_index: helper testgit@jeffhostetler.com, Mar 27, 2017
  9. Jeff KingMar 27, 2017
  10. Jeff HostetlerMar 28, 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.