diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-06-18 19:13:12 +0400 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-06-23 23:50:36 +0400 |
commit | b3b66c57930358467395fc3a5bca87edefd25cf4 (patch) | |
tree | 1ca1c8fd8bf8fd69156c566a83ac12375b427a5e /tests/pack | |
parent | 1589aa0c4d48fb130d8a5db28c45cd3d173cde6d (diff) |
Share packs across repository instances
Opening the same repository multiple times will currently open the same
file multiple times, as well as map the same region of the file multiple
times. This is not necessary, as the packfile data is immutable.
Instead of opening and closing packfiles directly, introduce an
indirection and allocate packfiles globally. This does mean locking on
each packfile open, but we already use this lock for the global mwindow
list so it doesn't introduce a new contention point.
Diffstat (limited to 'tests/pack')
-rw-r--r-- | tests/pack/sharing.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/pack/sharing.c b/tests/pack/sharing.c new file mode 100644 index 000000000..a67d65588 --- /dev/null +++ b/tests/pack/sharing.c @@ -0,0 +1,42 @@ +#include "clar_libgit2.h" +#include <git2.h> +#include "strmap.h" +#include "mwindow.h" +#include "pack.h" + +extern git_strmap *git__pack_cache; + +void test_pack_sharing__open_two_repos(void) +{ + git_repository *repo1, *repo2; + git_object *obj1, *obj2; + git_oid id; + git_strmap_iter pos; + void *data; + int error; + + cl_git_pass(git_repository_open(&repo1, cl_fixture("testrepo.git"))); + cl_git_pass(git_repository_open(&repo2, cl_fixture("testrepo.git"))); + + git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + + cl_git_pass(git_object_lookup(&obj1, repo1, &id, GIT_OBJ_ANY)); + cl_git_pass(git_object_lookup(&obj2, repo2, &id, GIT_OBJ_ANY)); + + pos = 0; + while ((error = git_strmap_next(&data, &pos, git__pack_cache)) == 0) { + struct git_pack_file *pack = (struct git_pack_file *) data; + + cl_assert_equal_i(2, pack->refcount.val); + } + + cl_assert_equal_i(3, git_strmap_num_entries(git__pack_cache)); + + git_object_free(obj1); + git_object_free(obj2); + git_repository_free(repo1); + git_repository_free(repo2); + + /* we don't want to keep the packs open after the repos go away */ + cl_assert_equal_i(0, git_strmap_num_entries(git__pack_cache)); +} |