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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
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)