Skip to content

Commit 54d350e

Browse files
committed
config_file: embed file in diskfile parse data
The config file code needs to keep track of the actual `git_config_file` structure, as it not only contains the path of the current configuration file, but it also keeps tracks of all includes of that file. Right now, we keep track of that structure via the `git_config_parser`, but as that's supposed to be a backend generic implementation of configuration parsing it's a layering violation to have it in there. Switch over the config file backend to use its own config file structure that's embedded in the backend parse data. This allows us to switch over the generic config parser to avoid using the `git_config_file` structure.
1 parent 76749df commit 54d350e

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/config_file.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ typedef struct {
5555

5656
typedef struct {
5757
const git_repository *repo;
58-
const char *file_path;
58+
git_config_file *file;
5959
git_config_entries *entries;
6060
git_config_level_t level;
6161
unsigned int depth;
@@ -677,8 +677,7 @@ static char *escape_value(const char *ptr)
677677
return git_buf_detach(&buf);
678678
}
679679

680-
static int parse_include(git_config_parser *reader,
681-
diskfile_parse_state *parse_data, const char *file)
680+
static int parse_include(diskfile_parse_state *parse_data, const char *file)
682681
{
683682
git_config_file *include;
684683
git_buf path = GIT_BUF_INIT;
@@ -688,7 +687,7 @@ static int parse_include(git_config_parser *reader,
688687
if (!file)
689688
return 0;
690689

691-
if ((result = git_path_dirname_r(&path, reader->file->path)) < 0)
690+
if ((result = git_path_dirname_r(&path, parse_data->file->path)) < 0)
692691
return result;
693692

694693
dir = git_buf_detach(&path);
@@ -698,7 +697,7 @@ static int parse_include(git_config_parser *reader,
698697
if (result < 0)
699698
return result;
700699

701-
include = git_array_alloc(reader->file->includes);
700+
include = git_array_alloc(parse_data->file->includes);
702701
GIT_ERROR_CHECK_ALLOC(include);
703702
memset(include, 0, sizeof(*include));
704703
git_array_init(include->includes);
@@ -783,8 +782,7 @@ static const struct {
783782
{ "gitdir/i:", conditional_match_gitdir_i }
784783
};
785784

786-
static int parse_conditional_include(git_config_parser *reader,
787-
diskfile_parse_state *parse_data, const char *section, const char *file)
785+
static int parse_conditional_include(diskfile_parse_state *parse_data, const char *section, const char *file)
788786
{
789787
char *condition;
790788
size_t i;
@@ -802,12 +800,12 @@ static int parse_conditional_include(git_config_parser *reader,
802800

803801
if ((error = conditions[i].matches(&matches,
804802
parse_data->repo,
805-
parse_data->file_path,
803+
parse_data->file->path,
806804
condition + strlen(conditions[i].prefix))) < 0)
807805
break;
808806

809807
if (matches)
810-
error = parse_include(reader, parse_data, file);
808+
error = parse_include(parse_data, file);
811809

812810
break;
813811
}
@@ -831,6 +829,7 @@ static int read_on_variable(
831829
const char *c;
832830
int result = 0;
833831

832+
GIT_UNUSED(reader);
834833
GIT_UNUSED(line);
835834
GIT_UNUSED(line_len);
836835

@@ -863,11 +862,10 @@ static int read_on_variable(
863862

864863
/* Add or append the new config option */
865864
if (!git__strcmp(entry->name, "include.path"))
866-
result = parse_include(reader, parse_data, entry->value);
865+
result = parse_include(parse_data, entry->value);
867866
else if (!git__prefixcmp(entry->name, "includeif.") &&
868867
!git__suffixcmp(entry->name, ".path"))
869-
result = parse_conditional_include(reader, parse_data,
870-
entry->name, entry->value);
868+
result = parse_conditional_include(parse_data, entry->name, entry->value);
871869

872870
return result;
873871
}
@@ -901,7 +899,7 @@ static int config_read_buffer(
901899
}
902900

903901
parse_data.repo = repo;
904-
parse_data.file_path = file->path;
902+
parse_data.file = file;
905903
parse_data.entries = entries;
906904
parse_data.level = level;
907905
parse_data.depth = depth;

0 commit comments

Comments
 (0)