diff options
| author | Vicent Marti <tanoku@gmail.com> | 2011-02-09 19:49:02 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-02-09 19:49:38 +0200 |
| commit | d4b5a4e23a5d6bece88cebb2a53de68eddb4ca68 (patch) | |
| tree | e881257e9f5ef0a9c94f0ba6974faa8fae0cbe87 /tests | |
| parent | 5a800efc42b5c58d06e0335348d75bde82af6ef7 (diff) | |
| download | libgit2-d4b5a4e23a5d6bece88cebb2a53de68eddb4ca68.tar.gz | |
Internal changes on the backend system
The priority value for different backends has been removed from the
public `git_odb_backend` struct. We handle that internally. The priority
value is specified on the `git_odb_add_alternate`.
This is convenient because it allows us to poll a backend twice with
different priorities without having to instantiate it twice.
We also differentiate between main backends and alternates; alternates have
lower priority and cannot be written to.
These changes come with some unit tests to make sure that the backend
sorting is consistent.
The libgit2 version has been bumped to 0.4.0.
This commit changes the external API:
CHANGED:
struct git_odb_backend
No longer has a `priority` attribute; priority for the backend
in managed internally by the library.
git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority)
Now takes an additional priority parameter, the priority that
will be given to the backend.
ADDED:
git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority)
Add a backend as an alternate. Alternate backends have always
lower priority than main backends, and writing is disabled on
them.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/t11-sqlite.c | 2 | ||||
| -rw-r--r-- | tests/t12-repo.c | 100 | ||||
| -rw-r--r-- | tests/test_main.c | 2 |
3 files changed, 103 insertions, 1 deletions
diff --git a/tests/t11-sqlite.c b/tests/t11-sqlite.c index bc75f5668..9b8cc6bf8 100644 --- a/tests/t11-sqlite.c +++ b/tests/t11-sqlite.c @@ -51,7 +51,7 @@ static git_odb *open_sqlite_odb(void) if (git_odb_backend_sqlite(&sqlite, ":memory") < GIT_SUCCESS) return NULL; - if (git_odb_add_backend(odb, sqlite) < GIT_SUCCESS) + if (git_odb_add_backend(odb, sqlite, 0) < GIT_SUCCESS) return NULL; return odb; diff --git a/tests/t12-repo.c b/tests/t12-repo.c new file mode 100644 index 000000000..2916f3c86 --- /dev/null +++ b/tests/t12-repo.c @@ -0,0 +1,100 @@ +/* + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, + * as published by the Free Software Foundation. + * + * In addition to the permissions in the GNU General Public License, + * the authors give you unlimited permission to link the compiled + * version of this file into combinations with other programs, + * and to distribute those combinations without any restriction + * coming from the use of this file. (The General Public License + * restrictions do apply in other respects; for example, they cover + * modification of the file, and distribution when not linked into + * a combined executable.) + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include "test_lib.h" +#include "test_helpers.h" + +#include "odb.h" +#include "git2/odb_backend.h" + +typedef struct { + git_odb_backend base; + int position; +} fake_backend; + +git_odb_backend *new_backend(int position) +{ + fake_backend *b; + + b = git__malloc(sizeof(fake_backend)); + if (b == NULL) + return NULL; + + memset(b, 0x0, sizeof(fake_backend)); + b->position = position; + return (git_odb_backend *)b; +} + +int test_backend_sorting(git_odb *odb) +{ + unsigned int i; + + for (i = 0; i < odb->backends.length; ++i) { + fake_backend *internal = *((fake_backend **)git_vector_get(&odb->backends, i)); + + if (internal == NULL) + return GIT_ERROR; + + if (internal->position != (int)i) + return GIT_ERROR; + } + + return GIT_SUCCESS; +} + +BEGIN_TEST("odb", backend_sorting) + git_odb *odb; + must_pass(git_odb_new(&odb)); + must_pass(git_odb_add_backend(odb, new_backend(0), 5)); + must_pass(git_odb_add_backend(odb, new_backend(2), 3)); + must_pass(git_odb_add_backend(odb, new_backend(1), 4)); + must_pass(git_odb_add_backend(odb, new_backend(3), 1)); + must_pass(test_backend_sorting(odb)); + git_odb_close(odb); +END_TEST + +BEGIN_TEST("odb", backend_alternates_sorting) + git_odb *odb; + must_pass(git_odb_new(&odb)); + must_pass(git_odb_add_backend(odb, new_backend(0), 5)); + must_pass(git_odb_add_backend(odb, new_backend(2), 3)); + must_pass(git_odb_add_backend(odb, new_backend(1), 4)); + must_pass(git_odb_add_backend(odb, new_backend(3), 1)); + must_pass(git_odb_add_alternate(odb, new_backend(4), 5)); + must_pass(git_odb_add_alternate(odb, new_backend(6), 3)); + must_pass(git_odb_add_alternate(odb, new_backend(5), 4)); + must_pass(git_odb_add_alternate(odb, new_backend(7), 1)); + must_pass(test_backend_sorting(odb)); + git_odb_close(odb); +END_TEST + +git_testsuite *libgit2_suite_repository(void) +{ + git_testsuite *suite = git_testsuite_new("Repository"); + + ADD_TEST(suite, "odb", backend_sorting); + ADD_TEST(suite, "odb", backend_alternates_sorting); + + return suite; +} diff --git a/tests/test_main.c b/tests/test_main.c index 191cd39a4..01e7d5123 100644 --- a/tests/test_main.c +++ b/tests/test_main.c @@ -41,6 +41,7 @@ extern git_testsuite *libgit2_suite_tag(void); extern git_testsuite *libgit2_suite_tree(void); extern git_testsuite *libgit2_suite_refs(void); extern git_testsuite *libgit2_suite_sqlite(void); +extern git_testsuite *libgit2_suite_repository(void); typedef git_testsuite *(*libgit2_suite)(void); @@ -57,6 +58,7 @@ static libgit2_suite suite_methods[]= { libgit2_suite_tree, libgit2_suite_refs, libgit2_suite_sqlite, + libgit2_suite_repository, }; #define GIT_SUITE_COUNT (ARRAY_SIZE(suite_methods)) |
