config_file: internalize `git_config_file` struct With the previous commits, we have finally separated the config parsing logic from the specific configuration file backend. Due to that, we can now move the `git_config_file` structure into the config file backend's implementation so that no other code may accidentally start using it again. Furthermore, we rename the structure to `diskfile` to make it obvious that it is internal, only, and to unify it with naming scheme of the other diskfile structures.
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
diff --git a/src/config_file.c b/src/config_file.c
index 89da829..14fc87f 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -26,6 +26,13 @@
/* Max depth for [include] directives */
#define MAX_INCLUDE_DEPTH 10
+typedef struct diskfile {
+ git_futils_filestamp stamp;
+ git_oid checksum;
+ char *path;
+ git_array_t(struct diskfile) includes;
+} diskfile;
+
typedef struct {
git_config_backend parent;
/* mutex to coordinate accessing the values */
@@ -44,7 +51,7 @@ typedef struct {
git_filebuf locked_buf;
git_buf locked_content;
- git_config_file file;
+ diskfile file;
} diskfile_backend;
typedef struct {
@@ -55,14 +62,14 @@ typedef struct {
typedef struct {
const git_repository *repo;
- git_config_file *file;
+ diskfile *file;
git_config_entries *entries;
git_config_level_t level;
unsigned int depth;
} diskfile_parse_state;
-static int config_read(git_config_entries *entries, const git_repository *repo, git_config_file *file, git_config_level_t level, int depth);
-static int config_read_buffer(git_config_entries *entries, const git_repository *repo, git_config_file *file, git_config_level_t level, int depth, const char *buf, size_t buflen);
+static int config_read(git_config_entries *entries, const git_repository *repo, diskfile *file, git_config_level_t level, int depth);
+static int config_read_buffer(git_config_entries *entries, const git_repository *repo, diskfile *file, git_config_level_t level, int depth, const char *buf, size_t buflen);
static int config_write(diskfile_backend *cfg, const char *orig_key, const char *key, const p_regex_t *preg, const char *value);
static char *escape_value(const char *ptr);
@@ -96,9 +103,9 @@ static git_config_entries *diskfile_entries_take(diskfile_header *h)
return entries;
}
-static void config_file_clear(git_config_file *file)
+static void config_file_clear(diskfile *file)
{
- git_config_file *include;
+ diskfile *include;
uint32_t i;
if (file == NULL)
@@ -134,9 +141,9 @@ static int config_open(git_config_backend *cfg, git_config_level_t level, const
return res;
}
-static int config_is_modified(int *modified, git_config_file *file)
+static int config_is_modified(int *modified, diskfile *file)
{
- git_config_file *include;
+ diskfile *include;
git_buf buf = GIT_BUF_INIT;
git_oid hash;
uint32_t i;
@@ -174,9 +181,9 @@ static int config_set_entries(git_config_backend *cfg, git_config_entries *entri
{
diskfile_backend *b = (diskfile_backend *)cfg;
git_config_entries *old = NULL;
- git_config_file *include;
+ diskfile *include;
int error;
- size_t i;
+ uint32_t i;
if (b->header.parent.readonly)
return config_error_readonly();
@@ -679,7 +686,7 @@ static char *escape_value(const char *ptr)
static int parse_include(diskfile_parse_state *parse_data, const char *file)
{
- git_config_file *include;
+ diskfile *include;
git_buf path = GIT_BUF_INIT;
char *dir;
int result;
@@ -873,7 +880,7 @@ static int read_on_variable(
static int config_read_buffer(
git_config_entries *entries,
const git_repository *repo,
- git_config_file *file,
+ diskfile *file,
git_config_level_t level,
int depth,
const char *buf,
@@ -913,7 +920,7 @@ out:
static int config_read(
git_config_entries *entries,
const git_repository *repo,
- git_config_file *file,
+ diskfile *file,
git_config_level_t level,
int depth)
{
diff --git a/src/config_parse.h b/src/config_parse.h
index a25da9d..a8657fd 100644
--- a/src/config_parse.h
+++ b/src/config_parse.h
@@ -17,13 +17,6 @@
extern const char *git_config_escapes;
extern const char *git_config_escaped;
-typedef struct config_file {
- git_futils_filestamp stamp;
- git_oid checksum;
- char *path;
- git_array_t(struct config_file) includes;
-} git_config_file;
-
typedef struct {
const char *path;
git_parse_ctx ctx;