diff options
author | Patrick Steinhardt <ps@pks.im> | 2018-08-10 13:03:33 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2018-09-28 11:14:13 +0200 |
commit | b944e13782370844823fcdc712fefcde3bb3fe73 (patch) | |
tree | c683c316553c2ef40661f6119913d9b51de9e2cd | |
parent | 1aeff5d7c97eac81965d09b0fac8e89ddb6909be (diff) | |
download | libgit2-b944e13782370844823fcdc712fefcde3bb3fe73.tar.gz |
config: rename "config_file.h" to "config_backend.h"
The header "config_file.h" has a list of inline-functions to access the
contents of a config backend without directly messing with the struct's
function pointers. While all these functions are called
"git_config_file_*", they are in fact completely backend-agnostic and
don't care whether it is a file or not. Rename all the function to
instead be backend-agnostic versions called "git_config_backend_*" and
rename the header to match.
-rw-r--r-- | src/config.c | 4 | ||||
-rw-r--r-- | src/config.h | 13 | ||||
-rw-r--r-- | src/config_backend.h (renamed from src/config_file.h) | 38 | ||||
-rw-r--r-- | src/config_file.c | 5 | ||||
-rw-r--r-- | src/submodule.c | 26 | ||||
-rw-r--r-- | tests/config/readonly.c | 12 | ||||
-rw-r--r-- | tests/config/write.c | 1 |
7 files changed, 44 insertions, 55 deletions
diff --git a/src/config.c b/src/config.c index ebff6a280..8d2e12f98 100644 --- a/src/config.c +++ b/src/config.c @@ -12,7 +12,7 @@ #include "git2/sys/config.h" #include "vector.h" #include "buf_text.h" -#include "config_file.h" +#include "config_backend.h" #include "transaction.h" #if GIT_WIN32 # include <windows.h> @@ -114,7 +114,7 @@ int git_config_add_file_ondisk( return -1; } - if (git_config_file__ondisk(&file, path) < 0) + if (git_config_backend_from_file(&file, path) < 0) return -1; if ((res = git_config_add_backend(cfg, file, level, repo, force)) < 0) { diff --git a/src/config.h b/src/config.h index ec33c4f73..f5855113f 100644 --- a/src/config.h +++ b/src/config.h @@ -34,19 +34,6 @@ extern int git_config_rename_section( const char *old_section_name, /* eg "branch.dummy" */ const char *new_section_name); /* NULL to drop the old section */ -/** - * Create a configuration file backend for ondisk files - * - * These are the normal `.gitconfig` files that Core Git - * processes. Note that you first have to add this file to a - * configuration object before you can query it for configuration - * variables. - * - * @param out the new backend - * @param path where the config file is located - */ -extern int git_config_file__ondisk(git_config_backend **out, const char *path); - extern int git_config__normalize_name(const char *in, char **out); /* internal only: does not normalize key and sets out to NULL if not found */ diff --git a/src/config_file.h b/src/config_backend.h index 6a0984ec2..ea2beafc4 100644 --- a/src/config_file.h +++ b/src/config_backend.h @@ -12,36 +12,49 @@ #include "git2/sys/config.h" #include "git2/config.h" -GIT_INLINE(int) git_config_file_open(git_config_backend *cfg, unsigned int level, const git_repository *repo) +/** + * Create a configuration file backend for ondisk files + * + * These are the normal `.gitconfig` files that Core Git + * processes. Note that you first have to add this file to a + * configuration object before you can query it for configuration + * variables. + * + * @param out the new backend + * @param path where the config file is located + */ +extern int git_config_backend_from_file(git_config_backend **out, const char *path); + +GIT_INLINE(int) git_config_backend_open(git_config_backend *cfg, unsigned int level, const git_repository *repo) { return cfg->open(cfg, level, repo); } -GIT_INLINE(void) git_config_file_free(git_config_backend *cfg) +GIT_INLINE(void) git_config_backend_free(git_config_backend *cfg) { if (cfg) cfg->free(cfg); } -GIT_INLINE(int) git_config_file_get_string( +GIT_INLINE(int) git_config_backend_get_string( git_config_entry **out, git_config_backend *cfg, const char *name) { return cfg->get(cfg, name, out); } -GIT_INLINE(int) git_config_file_set_string( +GIT_INLINE(int) git_config_backend_set_string( git_config_backend *cfg, const char *name, const char *value) { return cfg->set(cfg, name, value); } -GIT_INLINE(int) git_config_file_delete( +GIT_INLINE(int) git_config_backend_delete( git_config_backend *cfg, const char *name) { return cfg->del(cfg, name); } -GIT_INLINE(int) git_config_file_foreach( +GIT_INLINE(int) git_config_backend_foreach( git_config_backend *cfg, int (*fn)(const git_config_entry *entry, void *data), void *data) @@ -49,21 +62,12 @@ GIT_INLINE(int) git_config_file_foreach( return git_config_backend_foreach_match(cfg, NULL, fn, data); } -GIT_INLINE(int) git_config_file_foreach_match( - git_config_backend *cfg, - const char *regexp, - int (*fn)(const git_config_entry *entry, void *data), - void *data) -{ - return git_config_backend_foreach_match(cfg, regexp, fn, data); -} - -GIT_INLINE(int) git_config_file_lock(git_config_backend *cfg) +GIT_INLINE(int) git_config_backend_lock(git_config_backend *cfg) { return cfg->lock(cfg); } -GIT_INLINE(int) git_config_file_unlock(git_config_backend *cfg, int success) +GIT_INLINE(int) git_config_backend_unlock(git_config_backend *cfg, int success) { return cfg->unlock(cfg, success); } diff --git a/src/config_file.c b/src/config_file.c index fb88818b5..2eab04a22 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -5,9 +5,8 @@ * a Linking Exception. For full terms see the included COPYING file. */ -#include "config_file.h" - #include "config.h" + #include "filebuf.h" #include "sysdir.h" #include "buffer.h" @@ -676,7 +675,7 @@ static int config_unlock(git_config_backend *_cfg, int success) return error; } -int git_config_file__ondisk(git_config_backend **out, const char *path) +int git_config_backend_from_file(git_config_backend **out, const char *path) { diskfile_backend *backend; diff --git a/src/submodule.c b/src/submodule.c index c7fd50c77..9231f08b1 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -15,7 +15,7 @@ #include "buf_text.h" #include "vector.h" #include "posix.h" -#include "config_file.h" +#include "config_backend.h" #include "config.h" #include "repository.h" #include "tree.h" @@ -335,9 +335,9 @@ int git_submodule_lookup( mods = open_gitmodules(repo, GITMODULES_EXISTING); if (mods) - error = git_config_file_foreach_match(mods, pattern, find_by_path, &data); + error = git_config_backend_foreach_match(mods, pattern, find_by_path, &data); - git_config_file_free(mods); + git_config_backend_free(mods); if (error < 0) { git_submodule_free(sm); @@ -794,11 +794,11 @@ int git_submodule_add_setup( } if ((error = git_buf_printf(&name, "submodule.%s.path", path)) < 0 || - (error = git_config_file_set_string(mods, name.ptr, path)) < 0) + (error = git_config_backend_set_string(mods, name.ptr, path)) < 0) goto cleanup; if ((error = submodule_config_key_trunc_puts(&name, "url")) < 0 || - (error = git_config_file_set_string(mods, name.ptr, url)) < 0) + (error = git_config_backend_set_string(mods, name.ptr, url)) < 0) goto cleanup; git_buf_clear(&name); @@ -836,7 +836,7 @@ cleanup: if (out != NULL) *out = sm; - git_config_file_free(mods); + git_config_backend_free(mods); git_repository_free(subrepo); git_buf_dispose(&real_url); git_buf_dispose(&name); @@ -1035,14 +1035,14 @@ static int write_var(git_repository *repo, const char *name, const char *var, co goto cleanup; if (val) - error = git_config_file_set_string(mods, key.ptr, val); + error = git_config_backend_set_string(mods, key.ptr, val); else - error = git_config_file_delete(mods, key.ptr); + error = git_config_backend_delete(mods, key.ptr); git_buf_dispose(&key); cleanup: - git_config_file_free(mods); + git_config_backend_free(mods); return error; } @@ -2072,12 +2072,12 @@ static git_config_backend *open_gitmodules( return NULL; if (okay_to_create || git_path_isfile(path.ptr)) { - /* git_config_file__ondisk should only fail if OOM */ - if (git_config_file__ondisk(&mods, path.ptr) < 0) + /* git_config_backend_from_file should only fail if OOM */ + if (git_config_backend_from_file(&mods, path.ptr) < 0) mods = NULL; /* open should only fail here if the file is malformed */ - else if (git_config_file_open(mods, GIT_CONFIG_LEVEL_LOCAL, repo) < 0) { - git_config_file_free(mods); + else if (git_config_backend_open(mods, GIT_CONFIG_LEVEL_LOCAL, repo) < 0) { + git_config_backend_free(mods); mods = NULL; } } diff --git a/tests/config/readonly.c b/tests/config/readonly.c index a424922c1..5d544b8cb 100644 --- a/tests/config/readonly.c +++ b/tests/config/readonly.c @@ -1,5 +1,5 @@ #include "clar_libgit2.h" -#include "config_file.h" +#include "config_backend.h" #include "config.h" #include "path.h" @@ -20,7 +20,7 @@ void test_config_readonly__writing_to_readonly_fails(void) { git_config_backend *backend; - cl_git_pass(git_config_file__ondisk(&backend, "global")); + cl_git_pass(git_config_backend_from_file(&backend, "global")); backend->readonly = 1; cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, NULL, 0)); @@ -32,11 +32,11 @@ void test_config_readonly__writing_to_cfg_with_rw_precedence_succeeds(void) { git_config_backend *backend; - cl_git_pass(git_config_file__ondisk(&backend, "global")); + cl_git_pass(git_config_backend_from_file(&backend, "global")); backend->readonly = 1; cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, NULL, 0)); - cl_git_pass(git_config_file__ondisk(&backend, "local")); + cl_git_pass(git_config_backend_from_file(&backend, "local")); cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_LOCAL, NULL, 0)); cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz")); @@ -50,11 +50,11 @@ void test_config_readonly__writing_to_cfg_with_ro_precedence_succeeds(void) { git_config_backend *backend; - cl_git_pass(git_config_file__ondisk(&backend, "local")); + cl_git_pass(git_config_backend_from_file(&backend, "local")); backend->readonly = 1; cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_LOCAL, NULL, 0)); - cl_git_pass(git_config_file__ondisk(&backend, "global")); + cl_git_pass(git_config_backend_from_file(&backend, "global")); cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, NULL, 0)); cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz")); diff --git a/tests/config/write.c b/tests/config/write.c index 521dcb0ae..bd0f5b277 100644 --- a/tests/config/write.c +++ b/tests/config/write.c @@ -2,7 +2,6 @@ #include "buffer.h" #include "fileops.h" #include "git2/sys/config.h" -#include "config_file.h" #include "config.h" void test_config_write__initialize(void) |