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

[PATCH 2/2] lookup_commit_reference_gently: do not read non-{tag,commit}

From
Thomas Rast <trast@inf.ethz.ch>
Date
May 30, 2013, 20:00 UTC
Message-ID
<5cc40825d5b4fb3382e4c054c49adf5e6b6fe110.1369943791.git.trast@inf.ethz.ch>
In-Reply-To
<2d926e4dbd218b2305f50652c00a5c1d87e81208.1369943791.git.trast@inf.ethz.ch>

lookup_commit_reference_gently unconditionally parses the object given to it. This slows down git-describe a lot if you have a repository with large tagged blobs in it: parse_object() will read the entire blob and verify that its sha1 matches, only to then throw it away.

Speed it up by checking the type with sha1_object_info() prior to unpacking.

The reason that deref_tag() does not need the same fix is a bit subtle: parse_tag_buffer() does not fill the 'tagged' member of the tag struct if the tagged object is a blob.

Reported-by: Alex Bennée <kernel-hacker@bennee.com>
Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
---
 commit.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/commit.c b/commit.c
index 888e02a..00e8d4a 100644
--- a/commit.c
+++ b/commit.c
@@ -31,8 +31,12 @@ static struct commit *check_commit(struct object *obj,
 struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
 					      int quiet)
 {
-	struct object *obj = deref_tag(parse_object(sha1), NULL, 0);
-
+	struct object *obj;
+	int type = sha1_object_info(sha1, NULL);
+	/* If it's neither tag nor commit, parsing the object is wasted effort */
+	if (type != OBJ_TAG && type != OBJ_COMMIT)
+		return NULL;
+	obj = deref_tag(parse_object(sha1), NULL, 0);
 	if (!obj)
 		return NULL;
 	return check_commit(obj, sha1, quiet);
-- 
1.8.3.506.g4fdeee5
Previous: Thomas RastNext: Jeff King
Message 2 of 8 in “sha1_file: silence sha1_loose_object_info”
  1. 1/2 sha1_file: silence sha1_loose_object_infoThomas Rast, May 30, 2013
  2. 2/2 lookup_commit_reference_gently: do not read non-{tag,commit}Thomas Rast, May 30, 2013
  3. Jeff KingMay 30, 2013
  4. Duy NguyenMay 31, 2013
  5. Thomas RastMay 31, 2013
  6. Jeff KingMay 31, 2013
  7. Ramkumar RamachandraMay 31, 2013
  8. Thomas RastMay 31, 2013

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.