diff options
| author | Carlos Martín Nieto <cmn@dwim.me> | 2014-09-28 07:00:49 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-10-10 19:43:42 +0200 |
| commit | c2f8b215937ed6f17dce94a4bde26d5c83b42533 (patch) | |
| tree | a8ec9796153969a8b857430fc1c04061026a731a /tests/index | |
| parent | 46bb00673013a7dae1ee81c484ac05c533ed1c4d (diff) | |
| download | libgit2-c2f8b215937ed6f17dce94a4bde26d5c83b42533.tar.gz | |
index: write out the tree cache extension
Keeping the cache around after read-tree is only one part of the
optimisation opportunities. In order to share the cache between program
instances, we need to write the TREE extension to the index.
Do so, taking the opportunity to rename 'entries' to 'entry_count' to
match the name given in the format description. The included test is
rather trivial, but works as a sanity check.
Diffstat (limited to 'tests/index')
| -rw-r--r-- | tests/index/cache.c | 85 |
1 files changed, 79 insertions, 6 deletions
diff --git a/tests/index/cache.c b/tests/index/cache.c index 79b431be7..ba2d51fa2 100644 --- a/tests/index/cache.c +++ b/tests/index/cache.c @@ -16,6 +16,79 @@ void test_index_cache__cleanup(void) g_repo = NULL; } +void test_index_cache__write_extension_at_root(void) +{ + git_index *index; + git_tree *tree; + git_oid id; + const char *tree_id_str = "45dd856fdd4d89b884c340ba0e047752d9b085d6"; + const char *index_file = "index-tree"; + + cl_git_pass(git_index_open(&index, index_file)); + cl_assert(index->tree == NULL); + cl_git_pass(git_oid_fromstr(&id, tree_id_str)); + cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); + cl_git_pass(git_index_read_tree(index, tree)); + git_tree_free(tree); + + cl_assert(index->tree); + cl_git_pass(git_index_write(index)); + git_index_free(index); + + cl_git_pass(git_index_open(&index, index_file)); + cl_assert(index->tree); + + cl_assert_equal_i(0, index->tree->entry_count); + cl_assert_equal_i(0, index->tree->children_count); + + cl_assert(git_oid_equal(&id, &index->tree->oid)); + + cl_git_pass(p_unlink(index_file)); + git_index_free(index); +} + +void test_index_cache__write_extension_invalidated_root(void) +{ + git_index *index; + git_tree *tree; + git_oid id; + const char *tree_id_str = "45dd856fdd4d89b884c340ba0e047752d9b085d6"; + const char *index_file = "index-tree-invalidated"; + git_index_entry entry; + + cl_git_pass(git_index_open(&index, index_file)); + cl_assert(index->tree == NULL); + cl_git_pass(git_oid_fromstr(&id, tree_id_str)); + cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); + cl_git_pass(git_index_read_tree(index, tree)); + git_tree_free(tree); + + cl_assert(index->tree); + + memset(&entry, 0x0, sizeof(git_index_entry)); + git_oid_cpy(&entry.id, &git_index_get_byindex(index, 0)->id); + entry.mode = GIT_FILEMODE_BLOB; + entry.path = "some-new-file.txt"; + + cl_git_pass(git_index_add(index, &entry)); + + cl_assert_equal_i(-1, index->tree->entry_count); + + cl_git_pass(git_index_write(index)); + git_index_free(index); + + cl_git_pass(git_index_open(&index, index_file)); + cl_assert(index->tree); + + cl_assert_equal_i(-1, index->tree->entry_count); + cl_assert_equal_i(0, index->tree->children_count); + + cl_assert(git_oid_cmp(&id, &index->tree->oid)); + + cl_git_pass(p_unlink(index_file)); + git_index_free(index); +} + void test_index_cache__read_tree_no_children(void) { git_index *index; @@ -33,7 +106,7 @@ void test_index_cache__read_tree_no_children(void) cl_assert(index->tree); cl_assert(git_oid_equal(&id, &index->tree->oid)); cl_assert_equal_i(0, index->tree->children_count); - cl_assert_equal_i(0, index->tree->entries); /* 0 is a placeholder here */ + cl_assert_equal_i(0, index->tree->entry_count); /* 0 is a placeholder here */ memset(&entry, 0x0, sizeof(git_index_entry)); entry.path = "new.txt"; @@ -41,7 +114,7 @@ void test_index_cache__read_tree_no_children(void) git_oid_fromstr(&entry.id, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057"); cl_git_pass(git_index_add(index, &entry)); - cl_assert_equal_i(-1, index->tree->entries); + cl_assert_equal_i(-1, index->tree->entry_count); git_index_free(index); } @@ -92,19 +165,19 @@ void test_index_cache__read_tree_children(void) git_oid_fromstr(&entry.id, "45b983be36b73c0788dc9cbcb76cbb80fc7bb058"); cl_git_pass(git_index_add(index, &entry)); - cl_assert_equal_i(-1, index->tree->entries); + cl_assert_equal_i(-1, index->tree->entry_count); cache = git_tree_cache_get(index->tree, "subdir"); cl_assert(cache); - cl_assert_equal_i(-1, cache->entries); + cl_assert_equal_i(-1, cache->entry_count); cache = git_tree_cache_get(index->tree, "subdir/even-deeper"); cl_assert(cache); - cl_assert_equal_i(0, cache->entries); + cl_assert_equal_i(0, cache->entry_count); cache = git_tree_cache_get(index->tree, "subdir2"); cl_assert(cache); - cl_assert_equal_i(0, cache->entries); + cl_assert_equal_i(0, cache->entry_count); git_index_free(index); } |
