config_file: rename function names As with the predecessing commit, this commit renames backend functions of the configuration file backend. This helps to clearly separate functionality and also to be able to see from backtraces which backend is currently in use.
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 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
diff --git a/src/config_file.c b/src/config_file.c
index bf770c9..f4d881f 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -60,9 +60,9 @@ typedef struct {
unsigned int depth;
} config_file_parse_data;
-static int config_read(git_config_entries *entries, const git_repository *repo, config_file *file, git_config_level_t level, int depth);
-static int config_read_buffer(git_config_entries *entries, const git_repository *repo, config_file *file, git_config_level_t level, int depth, const char *buf, size_t buflen);
-static int config_write(config_file_backend *cfg, const char *orig_key, const char *key, const git_regexp *preg, const char *value);
+static int config_file_read(git_config_entries *entries, const git_repository *repo, config_file *file, git_config_level_t level, int depth);
+static int config_file_read_buffer(git_config_entries *entries, const git_repository *repo, config_file *file, git_config_level_t level, int depth, const char *buf, size_t buflen);
+static int config_file_write(config_file_backend *cfg, const char *orig_key, const char *key, const git_regexp *preg, const char *value);
static char *escape_value(const char *ptr);
/**
@@ -70,7 +70,7 @@ static char *escape_value(const char *ptr);
* refcount. This is its own function to make sure we use the mutex to
* avoid the map pointer from changing under us.
*/
-static git_config_entries *diskfile_entries_take(config_file_backend *b)
+static git_config_entries *config_file_entries_take(config_file_backend *b)
{
git_config_entries *entries;
@@ -103,7 +103,7 @@ static void config_file_clear(config_file *file)
git__free(file->path);
}
-static int config_open(git_config_backend *cfg, git_config_level_t level, const git_repository *repo)
+static int config_file_open(git_config_backend *cfg, git_config_level_t level, const git_repository *repo)
{
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
int res;
@@ -117,7 +117,7 @@ static int config_open(git_config_backend *cfg, git_config_level_t level, const
if (!git_path_exists(b->file.path))
return 0;
- if (res < 0 || (res = config_read(b->entries, repo, &b->file, level, 0)) < 0) {
+ if (res < 0 || (res = config_file_read(b->entries, repo, &b->file, level, 0)) < 0) {
git_config_entries_free(b->entries);
b->entries = NULL;
}
@@ -125,7 +125,7 @@ static int config_open(git_config_backend *cfg, git_config_level_t level, const
return res;
}
-static int config_is_modified(int *modified, config_file *file)
+static int config_file_is_modified(int *modified, config_file *file)
{
config_file *include;
git_buf buf = GIT_BUF_INIT;
@@ -151,7 +151,7 @@ static int config_is_modified(int *modified, config_file *file)
check_includes:
git_array_foreach(file->includes, i, include) {
- if ((error = config_is_modified(modified, include)) < 0 || *modified)
+ if ((error = config_file_is_modified(modified, include)) < 0 || *modified)
goto out;
}
@@ -161,7 +161,7 @@ out:
return error;
}
-static int config_set_entries(git_config_backend *cfg, git_config_entries *entries)
+static int config_file_set_entries(git_config_backend *cfg, git_config_entries *entries)
{
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
git_config_entries *old = NULL;
@@ -193,16 +193,16 @@ out:
return error;
}
-static int config_refresh_from_buffer(git_config_backend *cfg, const char *buf, size_t buflen)
+static int config_file_refresh_from_buffer(git_config_backend *cfg, const char *buf, size_t buflen)
{
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
git_config_entries *entries = NULL;
int error;
if ((error = git_config_entries_new(&entries)) < 0 ||
- (error = config_read_buffer(entries, b->repo, &b->file,
- b->level, 0, buf, buflen)) < 0 ||
- (error = config_set_entries(cfg, entries)) < 0)
+ (error = config_file_read_buffer(entries, b->repo, &b->file,
+ b->level, 0, buf, buflen)) < 0 ||
+ (error = config_file_set_entries(cfg, entries)) < 0)
goto out;
entries = NULL;
@@ -211,7 +211,7 @@ out:
return error;
}
-static int config_refresh(git_config_backend *cfg)
+static int config_file_refresh(git_config_backend *cfg)
{
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
git_config_entries *entries = NULL;
@@ -220,15 +220,15 @@ static int config_refresh(git_config_backend *cfg)
if (cfg->readonly)
return 0;
- if ((error = config_is_modified(&modified, &b->file)) < 0 && error != GIT_ENOTFOUND)
+ if ((error = config_file_is_modified(&modified, &b->file)) < 0 && error != GIT_ENOTFOUND)
goto out;
if (!modified)
return 0;
if ((error = git_config_entries_new(&entries)) < 0 ||
- (error = config_read(entries, b->repo, &b->file, b->level, 0)) < 0 ||
- (error = config_set_entries(cfg, entries)) < 0)
+ (error = config_file_read(entries, b->repo, &b->file, b->level, 0)) < 0 ||
+ (error = config_file_set_entries(cfg, entries)) < 0)
goto out;
entries = NULL;
@@ -238,7 +238,7 @@ out:
return (error == GIT_ENOTFOUND) ? 0 : error;
}
-static void backend_free(git_config_backend *_backend)
+static void config_file_free(git_config_backend *_backend)
{
config_file_backend *backend = GIT_CONTAINER_OF(_backend, config_file_backend, parent);
@@ -251,7 +251,7 @@ static void backend_free(git_config_backend *_backend)
git__free(backend);
}
-static int config_iterator_new(
+static int config_file_iterator(
git_config_iterator **iter,
struct git_config_backend *backend)
{
@@ -259,7 +259,7 @@ static int config_iterator_new(
git_config_entries *entries = NULL;
int error;
- if ((error = config_refresh(backend)) < 0 ||
+ if ((error = config_file_refresh(backend)) < 0 ||
(error = git_config_entries_dup(&entries, b->entries)) < 0 ||
(error = git_config_entries_iterator_new(iter, entries)) < 0)
goto out;
@@ -270,7 +270,12 @@ out:
return error;
}
-static int config_set(git_config_backend *cfg, const char *name, const char *value)
+static int config_file_snapshot(git_config_backend **out, git_config_backend *backend)
+{
+ return git_config_backend_snapshot(out, backend);
+}
+
+static int config_file_set(git_config_backend *cfg, const char *name, const char *value)
{
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
git_config_entries *entries;
@@ -281,7 +286,7 @@ static int config_set(git_config_backend *cfg, const char *name, const char *val
if ((error = git_config__normalize_name(name, &key)) < 0)
return error;
- if ((entries = diskfile_entries_take(b)) == NULL)
+ if ((entries = config_file_entries_take(b)) == NULL)
return -1;
/* Check whether we'd be modifying an included or multivar key */
@@ -302,7 +307,7 @@ static int config_set(git_config_backend *cfg, const char *name, const char *val
GIT_ERROR_CHECK_ALLOC(esc_value);
}
- if ((error = config_write(b, name, key, NULL, esc_value)) < 0)
+ if ((error = config_file_write(b, name, key, NULL, esc_value)) < 0)
goto out;
out:
@@ -313,7 +318,7 @@ out:
}
/* release the map containing the entry as an equivalent to freeing it */
-static void free_diskfile_entry(git_config_entry *entry)
+static void config_file_entry_free(git_config_entry *entry)
{
git_config_entries *entries = (git_config_entries *) entry->payload;
git_config_entries_free(entries);
@@ -322,17 +327,17 @@ static void free_diskfile_entry(git_config_entry *entry)
/*
* Internal function that actually gets the value in string form
*/
-static int config_get(git_config_backend *cfg, const char *key, git_config_entry **out)
+static int config_file_get(git_config_backend *cfg, const char *key, git_config_entry **out)
{
config_file_backend *h = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
git_config_entries *entries = NULL;
git_config_entry *entry;
int error = 0;
- if (!h->parent.readonly && ((error = config_refresh(cfg)) < 0))
+ if (!h->parent.readonly && ((error = config_file_refresh(cfg)) < 0))
return error;
- if ((entries = diskfile_entries_take(h)) == NULL)
+ if ((entries = config_file_entries_take(h)) == NULL)
return -1;
if ((error = (git_config_entries_get(&entry, entries, key))) < 0) {
@@ -340,14 +345,14 @@ static int config_get(git_config_backend *cfg, const char *key, git_config_entry
return error;
}
- entry->free = free_diskfile_entry;
+ entry->free = config_file_entry_free;
entry->payload = entries;
*out = entry;
return 0;
}
-static int config_set_multivar(
+static int config_file_set_multivar(
git_config_backend *cfg, const char *name, const char *regexp, const char *value)
{
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
@@ -363,8 +368,8 @@ static int config_set_multivar(
if ((result = git_regexp_compile(&preg, regexp, 0)) < 0)
goto out;
- /* If we do have it, set call config_write() and reload */
- if ((result = config_write(b, name, key, &preg, value)) < 0)
+ /* If we do have it, set call config_file_write() and reload */
+ if ((result = config_file_write(b, name, key, &preg, value)) < 0)
goto out;
out:
@@ -374,7 +379,7 @@ out:
return result;
}
-static int config_delete(git_config_backend *cfg, const char *name)
+static int config_file_delete(git_config_backend *cfg, const char *name)
{
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
git_config_entries *entries = NULL;
@@ -385,7 +390,7 @@ static int config_delete(git_config_backend *cfg, const char *name)
if ((error = git_config__normalize_name(name, &key)) < 0)
goto out;
- if ((entries = diskfile_entries_take(b)) == NULL)
+ if ((entries = config_file_entries_take(b)) == NULL)
goto out;
/* Check whether we'd be modifying an included or multivar key */
@@ -395,7 +400,7 @@ static int config_delete(git_config_backend *cfg, const char *name)
goto out;
}
- if ((error = config_write(b, name, entry->name, NULL, NULL)) < 0)
+ if ((error = config_file_write(b, name, entry->name, NULL, NULL)) < 0)
goto out;
out:
@@ -404,7 +409,7 @@ out:
return error;
}
-static int config_delete_multivar(git_config_backend *cfg, const char *name, const char *regexp)
+static int config_file_delete_multivar(git_config_backend *cfg, const char *name, const char *regexp)
{
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
git_config_entries *entries = NULL;
@@ -416,7 +421,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
if ((result = git_config__normalize_name(name, &key)) < 0)
goto out;
- if ((entries = diskfile_entries_take(b)) == NULL) {
+ if ((entries = config_file_entries_take(b)) == NULL) {
result = -1;
goto out;
}
@@ -430,7 +435,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
if ((result = git_regexp_compile(&preg, regexp, 0)) < 0)
goto out;
- if ((result = config_write(b, name, key, &preg, NULL)) < 0)
+ if ((result = config_file_write(b, name, key, &preg, NULL)) < 0)
goto out;
out:
@@ -440,7 +445,7 @@ out:
return result;
}
-static int config_lock(git_config_backend *_cfg)
+static int config_file_lock(git_config_backend *_cfg)
{
config_file_backend *cfg = GIT_CONTAINER_OF(_cfg, config_file_backend, parent);
int error;
@@ -459,7 +464,7 @@ static int config_lock(git_config_backend *_cfg)
}
-static int config_unlock(git_config_backend *_cfg, int success)
+static int config_file_unlock(git_config_backend *_cfg, int success)
{
config_file_backend *cfg = GIT_CONTAINER_OF(_cfg, config_file_backend, parent);
int error = 0;
@@ -490,17 +495,17 @@ int git_config_backend_from_file(git_config_backend **out, const char *path)
GIT_ERROR_CHECK_ALLOC(backend->file.path);
git_array_init(backend->file.includes);
- backend->parent.open = config_open;
- backend->parent.get = config_get;
- backend->parent.set = config_set;
- backend->parent.set_multivar = config_set_multivar;
- backend->parent.del = config_delete;
- backend->parent.del_multivar = config_delete_multivar;
- backend->parent.iterator = config_iterator_new;
- backend->parent.snapshot = git_config_backend_snapshot;
- backend->parent.lock = config_lock;
- backend->parent.unlock = config_unlock;
- backend->parent.free = backend_free;
+ backend->parent.open = config_file_open;
+ backend->parent.get = config_file_get;
+ backend->parent.set = config_file_set;
+ backend->parent.set_multivar = config_file_set_multivar;
+ backend->parent.del = config_file_delete;
+ backend->parent.del_multivar = config_file_delete_multivar;
+ backend->parent.iterator = config_file_iterator;
+ backend->parent.snapshot = config_file_snapshot;
+ backend->parent.lock = config_file_lock;
+ backend->parent.unlock = config_file_unlock;
+ backend->parent.free = config_file_free;
*out = (git_config_backend *)backend;
@@ -574,8 +579,8 @@ static int parse_include(config_file_parse_data *parse_data, const char *file)
git_array_init(include->includes);
include->path = git_buf_detach(&path);
- result = config_read(parse_data->entries, parse_data->repo,
- include, parse_data->level, parse_data->depth+1);
+ result = config_file_read(parse_data->entries, parse_data->repo, include,
+ parse_data->level, parse_data->depth+1);
if (result == GIT_ENOTFOUND) {
git_error_clear();
@@ -793,7 +798,7 @@ static int read_on_variable(
return result;
}
-static int config_read_buffer(
+static int config_file_read_buffer(
git_config_entries *entries,
const git_repository *repo,
config_file *file,
@@ -833,7 +838,7 @@ out:
return error;
}
-static int config_read(
+static int config_file_read(
git_config_entries *entries,
const git_repository *repo,
config_file *file,
@@ -856,8 +861,8 @@ static int config_read(
if ((error = git_hash_buf(&file->checksum, contents.ptr, contents.size)) < 0)
goto out;
- if ((error = config_read_buffer(entries, repo, file, level, depth,
- contents.ptr, contents.size)) < 0)
+ if ((error = config_file_read_buffer(entries, repo, file, level, depth,
+ contents.ptr, contents.size)) < 0)
goto out;
out:
@@ -1088,7 +1093,7 @@ static int write_on_eof(
/*
* This is pretty much the parsing, except we write out anything we don't have
*/
-static int config_write(config_file_backend *cfg, const char *orig_key, const char *key, const git_regexp *preg, const char* value)
+static int config_file_write(config_file_backend *cfg, const char *orig_key, const char *key, const git_regexp *preg, const char* value)
{
char *orig_section = NULL, *section = NULL, *orig_name, *name, *ldot;
@@ -1149,7 +1154,7 @@ static int config_write(config_file_backend *cfg, const char *orig_key, const ch
if ((error = git_filebuf_commit(&file)) < 0)
goto done;
- if ((error = config_refresh_from_buffer(&cfg->parent, buf.ptr, buf.size)) < 0)
+ if ((error = config_file_refresh_from_buffer(&cfg->parent, buf.ptr, buf.size)) < 0)
goto done;
}