Skip to content

Commit 09b2e40

Browse files
committed
Merge branch 'jt/get-reference-with-commit-graph'
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()
2 parents 073312b + ec0c579 commit 09b2e40

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

revision.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,20 @@ static struct object *get_reference(struct rev_info *revs, const char *name,
213213
{
214214
struct object *object;
215215

216-
object = parse_object(revs->repo, oid);
216+
/*
217+
* If the repository has commit graphs, repo_parse_commit() avoids
218+
* reading the object buffer, so use it whenever possible.
219+
*/
220+
if (oid_object_info(revs->repo, oid, NULL) == OBJ_COMMIT) {
221+
struct commit *c = lookup_commit(revs->repo, oid);
222+
if (!repo_parse_commit(revs->repo, c))
223+
object = (struct object *) c;
224+
else
225+
object = NULL;
226+
} else {
227+
object = parse_object(revs->repo, oid);
228+
}
229+
217230
if (!object) {
218231
if (revs->ignore_missing)
219232
return object;

0 commit comments

Comments
 (0)