Skip to content

Commit c274984

Browse files
committed
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 parent b30b04a commit c274984

File tree

1 file changed

+63
-58
lines changed

1 file changed

+63
-58
lines changed

src/config_file.c

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ typedef struct {
6060
unsigned int depth;
6161
} config_file_parse_data;
6262

63-
static int config_read(git_config_entries *entries, const git_repository *repo, config_file *file, git_config_level_t level, int depth);
64-
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);
65-
static int config_write(config_file_backend *cfg, const char *orig_key, const char *key, const git_regexp *preg, const char *value);
63+
static int config_file_read(git_config_entries *entries, const git_repository *repo, config_file *file, git_config_level_t level, int depth);
64+
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);
65+
static int config_file_write(config_file_backend *cfg, const char *orig_key, const char *key, const git_regexp *preg, const char *value);
6666
static char *escape_value(const char *ptr);
6767

6868
/**
6969
* Take the current values map from the backend and increase its
7070
* refcount. This is its own function to make sure we use the mutex to
7171
* avoid the map pointer from changing under us.
7272
*/
73-
static git_config_entries *diskfile_entries_take(config_file_backend *b)
73+
static git_config_entries *config_file_entries_take(config_file_backend *b)
7474
{
7575
git_config_entries *entries;
7676

@@ -103,7 +103,7 @@ static void config_file_clear(config_file *file)
103103
git__free(file->path);
104104
}
105105

106-
static int config_open(git_config_backend *cfg, git_config_level_t level, const git_repository *repo)
106+
static int config_file_open(git_config_backend *cfg, git_config_level_t level, const git_repository *repo)
107107
{
108108
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
109109
int res;
@@ -117,15 +117,15 @@ static int config_open(git_config_backend *cfg, git_config_level_t level, const
117117
if (!git_path_exists(b->file.path))
118118
return 0;
119119

120-
if (res < 0 || (res = config_read(b->entries, repo, &b->file, level, 0)) < 0) {
120+
if (res < 0 || (res = config_file_read(b->entries, repo, &b->file, level, 0)) < 0) {
121121
git_config_entries_free(b->entries);
122122
b->entries = NULL;
123123
}
124124

125125
return res;
126126
}
127127

128-
static int config_is_modified(int *modified, config_file *file)
128+
static int config_file_is_modified(int *modified, config_file *file)
129129
{
130130
config_file *include;
131131
git_buf buf = GIT_BUF_INIT;
@@ -151,7 +151,7 @@ static int config_is_modified(int *modified, config_file *file)
151151

152152
check_includes:
153153
git_array_foreach(file->includes, i, include) {
154-
if ((error = config_is_modified(modified, include)) < 0 || *modified)
154+
if ((error = config_file_is_modified(modified, include)) < 0 || *modified)
155155
goto out;
156156
}
157157

@@ -161,7 +161,7 @@ static int config_is_modified(int *modified, config_file *file)
161161
return error;
162162
}
163163

164-
static int config_set_entries(git_config_backend *cfg, git_config_entries *entries)
164+
static int config_file_set_entries(git_config_backend *cfg, git_config_entries *entries)
165165
{
166166
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
167167
git_config_entries *old = NULL;
@@ -193,16 +193,16 @@ static int config_set_entries(git_config_backend *cfg, git_config_entries *entri
193193
return error;
194194
}
195195

196-
static int config_refresh_from_buffer(git_config_backend *cfg, const char *buf, size_t buflen)
196+
static int config_file_refresh_from_buffer(git_config_backend *cfg, const char *buf, size_t buflen)
197197
{
198198
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
199199
git_config_entries *entries = NULL;
200200
int error;
201201

202202
if ((error = git_config_entries_new(&entries)) < 0 ||
203-
(error = config_read_buffer(entries, b->repo, &b->file,
204-
b->level, 0, buf, buflen)) < 0 ||
205-
(error = config_set_entries(cfg, entries)) < 0)
203+
(error = config_file_read_buffer(entries, b->repo, &b->file,
204+
b->level, 0, buf, buflen)) < 0 ||
205+
(error = config_file_set_entries(cfg, entries)) < 0)
206206
goto out;
207207

208208
entries = NULL;
@@ -211,7 +211,7 @@ static int config_refresh_from_buffer(git_config_backend *cfg, const char *buf,
211211
return error;
212212
}
213213

214-
static int config_refresh(git_config_backend *cfg)
214+
static int config_file_refresh(git_config_backend *cfg)
215215
{
216216
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
217217
git_config_entries *entries = NULL;
@@ -220,15 +220,15 @@ static int config_refresh(git_config_backend *cfg)
220220
if (cfg->readonly)
221221
return 0;
222222

223-
if ((error = config_is_modified(&modified, &b->file)) < 0 && error != GIT_ENOTFOUND)
223+
if ((error = config_file_is_modified(&modified, &b->file)) < 0 && error != GIT_ENOTFOUND)
224224
goto out;
225225

226226
if (!modified)
227227
return 0;
228228

229229
if ((error = git_config_entries_new(&entries)) < 0 ||
230-
(error = config_read(entries, b->repo, &b->file, b->level, 0)) < 0 ||
231-
(error = config_set_entries(cfg, entries)) < 0)
230+
(error = config_file_read(entries, b->repo, &b->file, b->level, 0)) < 0 ||
231+
(error = config_file_set_entries(cfg, entries)) < 0)
232232
goto out;
233233

234234
entries = NULL;
@@ -238,7 +238,7 @@ static int config_refresh(git_config_backend *cfg)
238238
return (error == GIT_ENOTFOUND) ? 0 : error;
239239
}
240240

241-
static void backend_free(git_config_backend *_backend)
241+
static void config_file_free(git_config_backend *_backend)
242242
{
243243
config_file_backend *backend = GIT_CONTAINER_OF(_backend, config_file_backend, parent);
244244

@@ -251,15 +251,15 @@ static void backend_free(git_config_backend *_backend)
251251
git__free(backend);
252252
}
253253

254-
static int config_iterator_new(
254+
static int config_file_iterator(
255255
git_config_iterator **iter,
256256
struct git_config_backend *backend)
257257
{
258258
config_file_backend *b = GIT_CONTAINER_OF(backend, config_file_backend, parent);
259259
git_config_entries *entries = NULL;
260260
int error;
261261

262-
if ((error = config_refresh(backend)) < 0 ||
262+
if ((error = config_file_refresh(backend)) < 0 ||
263263
(error = git_config_entries_dup(&entries, b->entries)) < 0 ||
264264
(error = git_config_entries_iterator_new(iter, entries)) < 0)
265265
goto out;
@@ -270,7 +270,12 @@ static int config_iterator_new(
270270
return error;
271271
}
272272

273-
static int config_set(git_config_backend *cfg, const char *name, const char *value)
273+
static int config_file_snapshot(git_config_backend **out, git_config_backend *backend)
274+
{
275+
return git_config_backend_snapshot(out, backend);
276+
}
277+
278+
static int config_file_set(git_config_backend *cfg, const char *name, const char *value)
274279
{
275280
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
276281
git_config_entries *entries;
@@ -281,7 +286,7 @@ static int config_set(git_config_backend *cfg, const char *name, const char *val
281286
if ((error = git_config__normalize_name(name, &key)) < 0)
282287
return error;
283288

284-
if ((entries = diskfile_entries_take(b)) == NULL)
289+
if ((entries = config_file_entries_take(b)) == NULL)
285290
return -1;
286291

287292
/* 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
302307
GIT_ERROR_CHECK_ALLOC(esc_value);
303308
}
304309

305-
if ((error = config_write(b, name, key, NULL, esc_value)) < 0)
310+
if ((error = config_file_write(b, name, key, NULL, esc_value)) < 0)
306311
goto out;
307312

308313
out:
@@ -313,7 +318,7 @@ static int config_set(git_config_backend *cfg, const char *name, const char *val
313318
}
314319

315320
/* release the map containing the entry as an equivalent to freeing it */
316-
static void free_diskfile_entry(git_config_entry *entry)
321+
static void config_file_entry_free(git_config_entry *entry)
317322
{
318323
git_config_entries *entries = (git_config_entries *) entry->payload;
319324
git_config_entries_free(entries);
@@ -322,32 +327,32 @@ static void free_diskfile_entry(git_config_entry *entry)
322327
/*
323328
* Internal function that actually gets the value in string form
324329
*/
325-
static int config_get(git_config_backend *cfg, const char *key, git_config_entry **out)
330+
static int config_file_get(git_config_backend *cfg, const char *key, git_config_entry **out)
326331
{
327332
config_file_backend *h = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
328333
git_config_entries *entries = NULL;
329334
git_config_entry *entry;
330335
int error = 0;
331336

332-
if (!h->parent.readonly && ((error = config_refresh(cfg)) < 0))
337+
if (!h->parent.readonly && ((error = config_file_refresh(cfg)) < 0))
333338
return error;
334339

335-
if ((entries = diskfile_entries_take(h)) == NULL)
340+
if ((entries = config_file_entries_take(h)) == NULL)
336341
return -1;
337342

338343
if ((error = (git_config_entries_get(&entry, entries, key))) < 0) {
339344
git_config_entries_free(entries);
340345
return error;
341346
}
342347

343-
entry->free = free_diskfile_entry;
348+
entry->free = config_file_entry_free;
344349
entry->payload = entries;
345350
*out = entry;
346351

347352
return 0;
348353
}
349354

350-
static int config_set_multivar(
355+
static int config_file_set_multivar(
351356
git_config_backend *cfg, const char *name, const char *regexp, const char *value)
352357
{
353358
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
@@ -363,8 +368,8 @@ static int config_set_multivar(
363368
if ((result = git_regexp_compile(&preg, regexp, 0)) < 0)
364369
goto out;
365370

366-
/* If we do have it, set call config_write() and reload */
367-
if ((result = config_write(b, name, key, &preg, value)) < 0)
371+
/* If we do have it, set call config_file_write() and reload */
372+
if ((result = config_file_write(b, name, key, &preg, value)) < 0)
368373
goto out;
369374

370375
out:
@@ -374,7 +379,7 @@ static int config_set_multivar(
374379
return result;
375380
}
376381

377-
static int config_delete(git_config_backend *cfg, const char *name)
382+
static int config_file_delete(git_config_backend *cfg, const char *name)
378383
{
379384
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
380385
git_config_entries *entries = NULL;
@@ -385,7 +390,7 @@ static int config_delete(git_config_backend *cfg, const char *name)
385390
if ((error = git_config__normalize_name(name, &key)) < 0)
386391
goto out;
387392

388-
if ((entries = diskfile_entries_take(b)) == NULL)
393+
if ((entries = config_file_entries_take(b)) == NULL)
389394
goto out;
390395

391396
/* 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)
395400
goto out;
396401
}
397402

398-
if ((error = config_write(b, name, entry->name, NULL, NULL)) < 0)
403+
if ((error = config_file_write(b, name, entry->name, NULL, NULL)) < 0)
399404
goto out;
400405

401406
out:
@@ -404,7 +409,7 @@ static int config_delete(git_config_backend *cfg, const char *name)
404409
return error;
405410
}
406411

407-
static int config_delete_multivar(git_config_backend *cfg, const char *name, const char *regexp)
412+
static int config_file_delete_multivar(git_config_backend *cfg, const char *name, const char *regexp)
408413
{
409414
config_file_backend *b = GIT_CONTAINER_OF(cfg, config_file_backend, parent);
410415
git_config_entries *entries = NULL;
@@ -416,7 +421,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
416421
if ((result = git_config__normalize_name(name, &key)) < 0)
417422
goto out;
418423

419-
if ((entries = diskfile_entries_take(b)) == NULL) {
424+
if ((entries = config_file_entries_take(b)) == NULL) {
420425
result = -1;
421426
goto out;
422427
}
@@ -430,7 +435,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
430435
if ((result = git_regexp_compile(&preg, regexp, 0)) < 0)
431436
goto out;
432437

433-
if ((result = config_write(b, name, key, &preg, NULL)) < 0)
438+
if ((result = config_file_write(b, name, key, &preg, NULL)) < 0)
434439
goto out;
435440

436441
out:
@@ -440,7 +445,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
440445
return result;
441446
}
442447

443-
static int config_lock(git_config_backend *_cfg)
448+
static int config_file_lock(git_config_backend *_cfg)
444449
{
445450
config_file_backend *cfg = GIT_CONTAINER_OF(_cfg, config_file_backend, parent);
446451
int error;
@@ -459,7 +464,7 @@ static int config_lock(git_config_backend *_cfg)
459464

460465
}
461466

462-
static int config_unlock(git_config_backend *_cfg, int success)
467+
static int config_file_unlock(git_config_backend *_cfg, int success)
463468
{
464469
config_file_backend *cfg = GIT_CONTAINER_OF(_cfg, config_file_backend, parent);
465470
int error = 0;
@@ -490,17 +495,17 @@ int git_config_backend_from_file(git_config_backend **out, const char *path)
490495
GIT_ERROR_CHECK_ALLOC(backend->file.path);
491496
git_array_init(backend->file.includes);
492497

493-
backend->parent.open = config_open;
494-
backend->parent.get = config_get;
495-
backend->parent.set = config_set;
496-
backend->parent.set_multivar = config_set_multivar;
497-
backend->parent.del = config_delete;
498-
backend->parent.del_multivar = config_delete_multivar;
499-
backend->parent.iterator = config_iterator_new;
500-
backend->parent.snapshot = git_config_backend_snapshot;
501-
backend->parent.lock = config_lock;
502-
backend->parent.unlock = config_unlock;
503-
backend->parent.free = backend_free;
498+
backend->parent.open = config_file_open;
499+
backend->parent.get = config_file_get;
500+
backend->parent.set = config_file_set;
501+
backend->parent.set_multivar = config_file_set_multivar;
502+
backend->parent.del = config_file_delete;
503+
backend->parent.del_multivar = config_file_delete_multivar;
504+
backend->parent.iterator = config_file_iterator;
505+
backend->parent.snapshot = config_file_snapshot;
506+
backend->parent.lock = config_file_lock;
507+
backend->parent.unlock = config_file_unlock;
508+
backend->parent.free = config_file_free;
504509

505510
*out = (git_config_backend *)backend;
506511

@@ -574,8 +579,8 @@ static int parse_include(config_file_parse_data *parse_data, const char *file)
574579
git_array_init(include->includes);
575580
include->path = git_buf_detach(&path);
576581

577-
result = config_read(parse_data->entries, parse_data->repo,
578-
include, parse_data->level, parse_data->depth+1);
582+
result = config_file_read(parse_data->entries, parse_data->repo, include,
583+
parse_data->level, parse_data->depth+1);
579584

580585
if (result == GIT_ENOTFOUND) {
581586
git_error_clear();
@@ -793,7 +798,7 @@ static int read_on_variable(
793798
return result;
794799
}
795800

796-
static int config_read_buffer(
801+
static int config_file_read_buffer(
797802
git_config_entries *entries,
798803
const git_repository *repo,
799804
config_file *file,
@@ -833,7 +838,7 @@ static int config_read_buffer(
833838
return error;
834839
}
835840

836-
static int config_read(
841+
static int config_file_read(
837842
git_config_entries *entries,
838843
const git_repository *repo,
839844
config_file *file,
@@ -856,8 +861,8 @@ static int config_read(
856861
if ((error = git_hash_buf(&file->checksum, contents.ptr, contents.size)) < 0)
857862
goto out;
858863

859-
if ((error = config_read_buffer(entries, repo, file, level, depth,
860-
contents.ptr, contents.size)) < 0)
864+
if ((error = config_file_read_buffer(entries, repo, file, level, depth,
865+
contents.ptr, contents.size)) < 0)
861866
goto out;
862867

863868
out:
@@ -1088,7 +1093,7 @@ static int write_on_eof(
10881093
/*
10891094
* This is pretty much the parsing, except we write out anything we don't have
10901095
*/
1091-
static int config_write(config_file_backend *cfg, const char *orig_key, const char *key, const git_regexp *preg, const char* value)
1096+
static int config_file_write(config_file_backend *cfg, const char *orig_key, const char *key, const git_regexp *preg, const char* value)
10921097

10931098
{
10941099
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
11491154
if ((error = git_filebuf_commit(&file)) < 0)
11501155
goto done;
11511156

1152-
if ((error = config_refresh_from_buffer(&cfg->parent, buf.ptr, buf.size)) < 0)
1157+
if ((error = config_file_refresh_from_buffer(&cfg->parent, buf.ptr, buf.size)) < 0)
11531158
goto done;
11541159
}
11551160

0 commit comments

Comments
 (0)