diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2015-11-01 15:58:51 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-11-01 16:13:37 +0100 |
commit | c4f89bec62f378a8a02ba402d6179e3dcf83e7fa (patch) | |
tree | 88f26ecf7333c26e00772b5c0429c9a76639d6f3 | |
parent | 232fd25baf7cff3bf6fa1070bc0442beae346c2b (diff) | |
download | libgit2-c4f89bec62f378a8a02ba402d6179e3dcf83e7fa.tar.gz |
fixup! odb: support registering an ODB by name
-rw-r--r-- | include/git2/odb_backend.h | 17 | ||||
-rw-r--r-- | src/backends.c | 4 | ||||
-rw-r--r-- | src/backends.h | 4 | ||||
-rw-r--r-- | tests/odb/registration.c | 30 |
4 files changed, 35 insertions, 20 deletions
diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h index 8d82fc573..35f5153ec 100644 --- a/include/git2/odb_backend.h +++ b/include/git2/odb_backend.h @@ -130,24 +130,27 @@ struct git_odb_writepack { }; /** - * Constructor for an odb backend which is registered. + * Constructor for an object db which is registered with the repository * - * @param out the pointer in which to store the new backend + * @param out the pointer in which to store the new odb + * @param repo the repository for which the constructor is called * @param payload the payload provided during registration * @return 0 or an error code */ -typedef int (*git_odb_backend_ctor)(git_odb_backend **out, void *payload); +typedef int (*git_odb_ctor)(git_odb **out, git_repository *repo, void *payload); /** - * Register a backend to be used instead of the default if the - * repository is configured to do so. + * Register an object db to be used with extensions. + + * If there is a `extensions.odb` configuration entry matching the + * given name, this constructor will be called instead of the default. * - * @param name the name of the extension + * @param name the name of the object db * @param ctor constructor to call * @param payload data passed to the constructor * @return 0 or an error code */ -GIT_EXTERN(int) git_odb_backend_register(const char *name, git_odb_backend_ctor ctor, void *payload); +GIT_EXTERN(int) git_odb_register(const char *name, git_odb_ctor ctor, void *payload); GIT_END_DECL diff --git a/src/backends.c b/src/backends.c index 0028fc0a3..f21f27183 100644 --- a/src/backends.c +++ b/src/backends.c @@ -4,7 +4,7 @@ static git_vector odb_registrations = GIT_VECTOR_INIT; -git_odb_registration *git_odb_backend__find(const char *name) +git_odb_registration *git_odb_registration__find(const char *name) { size_t i; git_odb_registration *reg; @@ -17,7 +17,7 @@ git_odb_registration *git_odb_backend__find(const char *name) return NULL; } -int git_odb_backend_register(const char *name, git_odb_backend_ctor ctor, void *payload) +int git_odb_register(const char *name, git_odb_ctor ctor, void *payload) { int error; git_odb_registration *reg; diff --git a/src/backends.h b/src/backends.h index 2b88676fe..de869ff64 100644 --- a/src/backends.h +++ b/src/backends.h @@ -12,13 +12,13 @@ typedef struct { char *name; - git_odb_backend_ctor ctor; + git_odb_ctor ctor; void *payload; } git_odb_registration; /** * Find an ODB registration by name */ -git_odb_registration *git_odb_backend__find(const char *name); +git_odb_registration *git_odb_registration__find(const char *name); #endif diff --git a/tests/odb/registration.c b/tests/odb/registration.c index 6573358af..90deb16c7 100644 --- a/tests/odb/registration.c +++ b/tests/odb/registration.c @@ -1,19 +1,26 @@ #include "clar_libgit2.h" +#include "odb.h" #include "backends.h" #include "repository.h" #include "git2/config.h" #include "git2/sys/odb_backend.h" -int payload_target; -int ctor_called; +static int payload_target; +static int ctor_called; +static git_odb *ctor_odb; -int odb_ctor(git_odb_backend **out, void *payload) +int odb_ctor(git_odb **out, git_repository *repo, void *payload) { + git_buf odb_path = GIT_BUF_INIT; + GIT_UNUSED(payload); - *out = NULL; ctor_called = 1; + cl_git_pass(git_buf_joinpath(&odb_path, git_repository_path(repo), GIT_OBJECTS_DIR)); + cl_git_pass(git_odb_open(out, odb_path.ptr)); + ctor_odb = *out; + git_buf_free(&odb_path); return 0; } @@ -21,30 +28,31 @@ void test_odb_registration__register(void) { git_odb_registration *reg; - cl_git_pass(git_odb_backend_register("foo", odb_ctor, &payload_target)); - reg = git_odb_backend__find("foo"); + cl_git_pass(git_odb_register("foo", odb_ctor, &payload_target)); + reg = git_odb_registration__find("foo"); cl_assert(reg); cl_assert_equal_s("foo", reg->name); cl_assert_equal_p(odb_ctor, reg->ctor); cl_assert_equal_p(&payload_target, reg->payload); - reg = git_odb_backend__find("bar"); + reg = git_odb_registration__find("bar"); cl_assert_equal_p(NULL, reg); } void test_odb_registration__use(void) { git_config *cfg; + git_odb *odb; git_repository *repo; - cl_git_pass(git_odb_backend_register("foo", odb_ctor, &payload_target)); + cl_git_pass(git_odb_register("foo", odb_ctor, &payload_target)); cl_git_pass(git_repository_init(&repo, "./v1-odb.git", true)); cl_git_pass(git_repository_config__weakptr(&cfg, repo)); cl_git_pass(git_config_set_int32(cfg, "core.repositoryformatversion", 1)); - cl_git_pass(git_config_set_string(cfg, "extensions.odbbackend", "foo")); + cl_git_pass(git_config_set_string(cfg, "extensions.odb", "foo")); cfg = NULL; git_repository_free(repo); @@ -52,4 +60,8 @@ void test_odb_registration__use(void) ctor_called = 0; cl_git_pass(git_repository_open(&repo, "./v1-odb.git")); cl_assert_equal_i(1, ctor_called); + cl_git_pass(git_repository_odb__weakptr(&odb, repo)); + cl_assert_equal_p(ctor_odb, odb); + + git_repository_free(repo); } |