Commit e8eb494afad8556bf5105f01c316b49e68ba6842

Stefan Sperling 2018-09-16T19:18:01

check caches first in got_object_open_as_{tree,commit}()

diff --git a/lib/object.c b/lib/object.c
index a72d11d..5d6b4ff 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -278,7 +278,11 @@ got_object_open_as_commit(struct got_commit_object **commit,
 	const struct got_error *err;
 	struct got_object *obj;
 
-	*commit = NULL;
+	*commit = got_repo_get_cached_commit(repo, id);
+	if (*commit != NULL) {
+		(*commit)->refcnt++;
+		return NULL;
+	}
 
 	err = got_object_open(&obj, repo, id);
 	if (err)
@@ -405,7 +409,11 @@ got_object_open_as_tree(struct got_tree_object **tree,
 	const struct got_error *err;
 	struct got_object *obj;
 
-	*tree = NULL;
+	*tree = got_repo_get_cached_tree(repo, id);
+	if (*tree != NULL) {
+		(*tree)->refcnt++;
+		return NULL;
+	}
 
 	err = got_object_open(&obj, repo, id);
 	if (err)