From 7465e873996c4157b8e10e353b803841c548e2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 29 Sep 2014 09:07:41 +0200 Subject: index: fill the tree cache on write-tree An obvious place to fill the tree cache is on write-tree, as we're guaranteed to be able to fill in the whole tree cache. The way this commit does this is not the most efficient, as we read the root tree from the odb instead of filling in the cache as we go along, but it fills the cache such that successive operations (and persisting the index to disk) will be able to take advantage of the cache, and it reuses the code we already have for filling the cache. Filling in the cache as we create the trees would require some reallocation of the children vector, which is currently not possible with out pool implementation. A different data structure would likely allow us to perform this operation at a later date. --- src/tree.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/tree.c b/src/tree.c index adc6fe5e4..6b06dfd77 100644 --- a/src/tree.c +++ b/src/tree.c @@ -579,6 +579,7 @@ int git_tree__write_index( git_oid *oid, git_index *index, git_repository *repo) { int ret; + git_tree *tree; bool old_ignore_case = false; assert(oid && index && repo); @@ -609,7 +610,21 @@ int git_tree__write_index( if (old_ignore_case) git_index__set_ignore_case(index, true); - return ret < 0 ? ret : 0; + index->tree = NULL; + + if (ret < 0) + return ret; + + git_pool_clear(&index->tree_pool); + + if ((ret = git_tree_lookup(&tree, repo, oid)) < 0) + return ret; + + /* Read the tree cache into the index */ + ret = git_tree_cache_read_tree(&index->tree, tree, &index->tree_pool); + git_tree_free(tree); + + return ret; } int git_treebuilder_create(git_treebuilder **builder_p, const git_tree *source) -- cgit v1.2.1