Merge branch 'jt/get-reference-with-commit-graph'
authorJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:10 +0000 (14:26 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:10 +0000 (14:26 -0800)
Micro-optimize the code that prepares commit objects to be walked
by "git rev-list" when the commit-graph is available.

* jt/get-reference-with-commit-graph:
revision: use commit graph in get_reference()

revision.c
index 119947ced0ba74cd20a007daf43f61386a393a6a..8f886fe8c644bfce221ddd2be94db7f05b5451e7 100644 (file)
@@ -213,7 +213,20 @@ static struct object *get_reference(struct rev_info *revs, const char *name,
 {
        struct object *object;
 
-       object = parse_object(revs->repo, oid);
+       /*
+        * If the repository has commit graphs, repo_parse_commit() avoids
+        * reading the object buffer, so use it whenever possible.
+        */
+       if (oid_object_info(revs->repo, oid, NULL) == OBJ_COMMIT) {
+               struct commit *c = lookup_commit(revs->repo, oid);
+               if (!repo_parse_commit(revs->repo, c))
+                       object = (struct object *) c;
+               else
+                       object = NULL;
+       } else {
+               object = parse_object(revs->repo, oid);
+       }
+
        if (!object) {
                if (revs->ignore_missing)
                        return object;