Commit b944e13782370844823fcdc712fefcde3bb3fe73

Patrick Steinhardt 2018-08-10T13:03:33

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.

diff --git a/src/config.c b/src/config.c
index ebff6a2..8d2e12f 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 ec33c4f..f585511 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_backend.h b/src/config_backend.h
new file mode 100644
index 0000000..ea2beaf
--- /dev/null
+++ b/src/config_backend.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_config_file_h__
+#define INCLUDE_config_file_h__
+
+#include "common.h"
+
+#include "git2/sys/config.h"
+#include "git2/config.h"
+
+/**
+ * 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_backend_free(git_config_backend *cfg)
+{
+	if (cfg)
+		cfg->free(cfg);
+}
+
+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_backend_set_string(
+	git_config_backend *cfg, const char *name, const char *value)
+{
+	return cfg->set(cfg, name, value);
+}
+
+GIT_INLINE(int) git_config_backend_delete(
+	git_config_backend *cfg, const char *name)
+{
+	return cfg->del(cfg, name);
+}
+
+GIT_INLINE(int) git_config_backend_foreach(
+	git_config_backend *cfg,
+	int (*fn)(const git_config_entry *entry, void *data),
+	void *data)
+{
+	return git_config_backend_foreach_match(cfg, NULL, fn, data);
+}
+
+GIT_INLINE(int) git_config_backend_lock(git_config_backend *cfg)
+{
+	return cfg->lock(cfg);
+}
+
+GIT_INLINE(int) git_config_backend_unlock(git_config_backend *cfg, int success)
+{
+	return cfg->unlock(cfg, success);
+}
+
+#endif
diff --git a/src/config_file.c b/src/config_file.c
index fb88818..2eab04a 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/config_file.h b/src/config_file.h
deleted file mode 100644
index 6a0984e..0000000
--- a/src/config_file.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#ifndef INCLUDE_config_file_h__
-#define INCLUDE_config_file_h__
-
-#include "common.h"
-
-#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)
-{
-	return cfg->open(cfg, level, repo);
-}
-
-GIT_INLINE(void) git_config_file_free(git_config_backend *cfg)
-{
-	if (cfg)
-		cfg->free(cfg);
-}
-
-GIT_INLINE(int) git_config_file_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_config_backend *cfg, const char *name, const char *value)
-{
-	return cfg->set(cfg, name, value);
-}
-
-GIT_INLINE(int) git_config_file_delete(
-	git_config_backend *cfg, const char *name)
-{
-	return cfg->del(cfg, name);
-}
-
-GIT_INLINE(int) git_config_file_foreach(
-	git_config_backend *cfg,
-	int (*fn)(const git_config_entry *entry, void *data),
-	void *data)
-{
-	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)
-{
-	return cfg->lock(cfg);
-}
-
-GIT_INLINE(int) git_config_file_unlock(git_config_backend *cfg, int success)
-{
-	return cfg->unlock(cfg, success);
-}
-
-#endif
diff --git a/src/submodule.c b/src/submodule.c
index c7fd50c..9231f08 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 a424922..5d544b8 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 521dcb0..bd0f5b2 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)