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

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-hac...@bennee.com>
Signed-off-by: Thomas Rast <tr...@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);

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to