summaryrefslogtreecommitdiff
path: root/tests/submodule
diff options
context:
space:
mode:
authorBrock Peabody <bpeabody@twosigma.com>2016-11-23 18:32:48 -0500
committerDavid Turner <dturner@twosigma.com>2017-01-20 17:33:56 -0500
commit4d99c4cfc604bb141fd4e1423e934ebd3fb7e2a7 (patch)
tree7fa6287b0ecfb6873dfd74eaf819cff1cf396bc2 /tests/submodule
parentca05857e71f8d11582b1ad82f63c6a61e96fe20e (diff)
downloadlibgit2-4d99c4cfc604bb141fd4e1423e934ebd3fb7e2a7.tar.gz
Allow for caching of submodules.
Added `git_repository_submodule_cache_all` to initialze a cache of submodules on the repository so that operations looking up N submodules are O(N) and not O(N^2). Added a `git_repository_submodule_cache_clear` function to remove the cache. Also optimized the function that loads all submodules as it was itself O(N^2) w.r.t the number of submodules, having to loop through the `.gitmodules` file once per submodule. I changed it to process the `.gitmodules` file once, into a map. Signed-off-by: David Turner <dturner@twosigma.com>
Diffstat (limited to 'tests/submodule')
-rw-r--r--tests/submodule/lookup.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index 148f9273e..e36fc44e0 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -388,3 +388,28 @@ void test_submodule_lookup__renamed(void)
cl_git_pass(git_submodule_foreach(g_repo, sm_lookup_cb, &data));
cl_assert_equal_i(8, data.count);
}
+
+void test_submodule_lookup_cached(void) {
+ git_submodule *sm;
+ git_submodule *sm2;
+ /* See that the simple tests still pass. */
+
+ git_repository_submodule_cache_all(g_repo);
+ test_submodule_lookup__simple_lookup();
+ git_repository_submodule_cache_clear(g_repo);
+ test_submodule_lookup__simple_lookup();
+
+ /* Check that subsequent calls return different objects when cached. */
+ git_repository_submodule_cache_all(g_repo);
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_git_pass(git_submodule_lookup(&sm2, g_repo, "sm_unchanged"));
+ cl_assert_equal_p(sm, sm2);
+ git_submodule_free(sm2);
+
+ /* and that we get new objects again after clearing the cache. */
+ git_repository_submodule_cache_clear(g_repo);
+ cl_git_pass(git_submodule_lookup(&sm2, g_repo, "sm_unchanged"));
+ cl_assert(sm != sm2);
+ git_submodule_free(sm);
+ git_submodule_free(sm2);
+}