config_file: consistently use `GIT_CONTAINER_OF`
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
diff --git a/src/config_file.c b/src/config_file.c
index 51a3e93..a15dba0 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -121,8 +121,8 @@ static void config_file_clear(diskfile *file)
static int config_open(git_config_backend *cfg, git_config_level_t level, const git_repository *repo)
{
+ diskfile_backend *b = GIT_CONTAINER_OF(cfg, diskfile_backend, header.parent);
int res;
- diskfile_backend *b = (diskfile_backend *)cfg;
b->header.level = level;
b->header.repo = repo;
@@ -179,7 +179,7 @@ out:
static int config_set_entries(git_config_backend *cfg, git_config_entries *entries)
{
- diskfile_backend *b = (diskfile_backend *)cfg;
+ diskfile_backend *b = GIT_CONTAINER_OF(cfg, diskfile_backend, header.parent);
git_config_entries *old = NULL;
diskfile *include;
int error;
@@ -252,7 +252,7 @@ out:
static void backend_free(git_config_backend *_backend)
{
- diskfile_backend *backend = (diskfile_backend *)_backend;
+ diskfile_backend *backend = GIT_CONTAINER_OF(_backend, diskfile_backend, header.parent);
if (backend == NULL)
return;
@@ -285,7 +285,7 @@ out:
static int config_set(git_config_backend *cfg, const char *name, const char *value)
{
- diskfile_backend *b = (diskfile_backend *)cfg;
+ diskfile_backend *b = GIT_CONTAINER_OF(cfg, diskfile_backend, header.parent);
git_config_entries *entries;
git_config_entry *existing;
char *key, *esc_value = NULL;
@@ -337,7 +337,7 @@ static void free_diskfile_entry(git_config_entry *entry)
*/
static int config_get(git_config_backend *cfg, const char *key, git_config_entry **out)
{
- diskfile_header *h = (diskfile_header *)cfg;
+ diskfile_header *h = GIT_CONTAINER_OF(cfg, diskfile_header, parent);
git_config_entries *entries = NULL;
git_config_entry *entry;
int error = 0;
@@ -363,7 +363,7 @@ static int config_get(git_config_backend *cfg, const char *key, git_config_entry
static int config_set_multivar(
git_config_backend *cfg, const char *name, const char *regexp, const char *value)
{
- diskfile_backend *b = (diskfile_backend *)cfg;
+ diskfile_backend *b = GIT_CONTAINER_OF(cfg, diskfile_backend, header.parent);
char *key;
p_regex_t preg;
int result;
@@ -393,7 +393,7 @@ out:
static int config_delete(git_config_backend *cfg, const char *name)
{
- diskfile_backend *b = (diskfile_backend *)cfg;
+ diskfile_backend *b = GIT_CONTAINER_OF(cfg, diskfile_backend, header.parent);
git_config_entries *entries = NULL;
git_config_entry *entry;
char *key = NULL;
@@ -423,7 +423,7 @@ out:
static int config_delete_multivar(git_config_backend *cfg, const char *name, const char *regexp)
{
- diskfile_backend *b = (diskfile_backend *)cfg;
+ diskfile_backend *b = GIT_CONTAINER_OF(cfg, diskfile_backend, header.parent);
git_config_entries *entries = NULL;
git_config_entry *entry = NULL;
p_regex_t preg = { 0 };
@@ -462,7 +462,7 @@ out:
static int config_lock(git_config_backend *_cfg)
{
- diskfile_backend *cfg = (diskfile_backend *) _cfg;
+ diskfile_backend *cfg = GIT_CONTAINER_OF(_cfg, diskfile_backend, header.parent);
int error;
if ((error = git_filebuf_open(&cfg->locked_buf, cfg->file.path, 0, GIT_CONFIG_FILE_MODE)) < 0)
@@ -481,7 +481,7 @@ static int config_lock(git_config_backend *_cfg)
static int config_unlock(git_config_backend *_cfg, int success)
{
- diskfile_backend *cfg = (diskfile_backend *) _cfg;
+ diskfile_backend *cfg = GIT_CONTAINER_OF(_cfg, diskfile_backend, header.parent);
int error = 0;
if (success) {
@@ -581,7 +581,7 @@ static int config_unlock_readonly(git_config_backend *_cfg, int success)
static void backend_readonly_free(git_config_backend *_backend)
{
- diskfile_backend *backend = (diskfile_backend *)_backend;
+ diskfile_backend *backend = GIT_CONTAINER_OF(_backend, diskfile_backend, header.parent);
if (backend == NULL)
return;
@@ -593,7 +593,7 @@ static void backend_readonly_free(git_config_backend *_backend)
static int config_readonly_open(git_config_backend *cfg, git_config_level_t level, const git_repository *repo)
{
- diskfile_readonly_backend *b = (diskfile_readonly_backend *) cfg;
+ diskfile_readonly_backend *b = GIT_CONTAINER_OF(cfg, diskfile_readonly_backend, header.parent);
diskfile_backend *src = b->snapshot_from;
diskfile_header *src_header = &src->header;
git_config_entries *entries;
@@ -623,7 +623,7 @@ static int config_snapshot(git_config_backend **out, git_config_backend *in)
backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION;
git_mutex_init(&backend->header.values_mutex);
- backend->snapshot_from = (diskfile_backend *) in;
+ backend->snapshot_from = GIT_CONTAINER_OF(in, diskfile_backend, header.parent);
backend->header.parent.readonly = 1;
backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION;
@@ -638,7 +638,7 @@ static int config_snapshot(git_config_backend **out, git_config_backend *in)
backend->header.parent.unlock = config_unlock_readonly;
backend->header.parent.free = backend_readonly_free;
- *out = (git_config_backend *)backend;
+ *out = &backend->header.parent;
return 0;
}