Commit 71eb0e7ff2bcf1a1556a8da81f9732706cbe28ef

Stefan Sperling 2018-09-16T19:24:26

eliminate redundant cache search in got_object_open_as_tree()

diff --git a/lib/object.c b/lib/object.c
index ef9404c..b794b8e 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -370,17 +370,20 @@ got_object_qid_alloc(struct got_object_qid **qid, struct got_object_id *id)
 	return NULL;
 }
 
-const struct got_error *
-got_object_tree_open(struct got_tree_object **tree,
-    struct got_repository *repo, struct got_object *obj)
+static const struct got_error *
+open_tree(struct got_tree_object **tree,
+    struct got_repository *repo, struct got_object *obj, int check_cache)
 {
 	const struct got_error *err = NULL;
 
-	*tree = got_repo_get_cached_tree(repo, &obj->id);
-	if (*tree != NULL) {
-		(*tree)->refcnt++;
-		return NULL;
-	}
+	if (check_cache) {
+		*tree = got_repo_get_cached_tree(repo, &obj->id);
+		if (*tree != NULL) {
+			(*tree)->refcnt++;
+			return NULL;
+		}
+	} else
+		*tree = NULL;
 
 	if (obj->type != GOT_OBJ_TYPE_TREE)
 		return got_error(GOT_ERR_OBJ_TYPE);
@@ -433,12 +436,19 @@ got_object_open_as_tree(struct got_tree_object **tree,
 		goto done;
 	}
 
-	err = got_object_tree_open(tree, repo, obj);
+	err = open_tree(tree, repo, obj, 0);
 done:
 	got_object_close(obj);
 	return err;
 }
 
+const struct got_error *
+got_object_tree_open(struct got_tree_object **tree,
+    struct got_repository *repo, struct got_object *obj)
+{
+	return open_tree(tree, repo, obj, 1);
+}
+
 const struct got_tree_entries *
 got_object_tree_get_entries(struct got_tree_object *tree)
 {