Commit b944e137 by Patrick Steinhardt

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.
parent 1aeff5d7
......@@ -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) {
......
......@@ -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 */
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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;
}
}
......
#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"));
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment