summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-09-29 09:07:41 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-10-10 19:43:42 +0200
commit7465e873996c4157b8e10e353b803841c548e2dc (patch)
tree26bb3ece7c75d191b44e62b6047c58697687dac3
parent795d8e932893b9944c6fe72191cb80c2ccdd5d34 (diff)
downloadlibgit2-7465e873996c4157b8e10e353b803841c548e2dc.tar.gz
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.
-rw-r--r--src/tree.c17
1 files changed, 16 insertions, 1 deletions
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)