diff options
| author | Patrick Steinhardt <ps@pks.im> | 2017-05-23 10:53:49 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2017-10-09 11:19:42 +0200 |
| commit | d5b9d9e991f019119f3c18325987728ab69d6121 (patch) | |
| tree | 1f417fe89c46b4d7e962972fb00188a5df4d06fc /src | |
| parent | 529e873cef18ec98246d32d28c7a0b0e3467fe27 (diff) | |
| download | libgit2-d5b9d9e991f019119f3c18325987728ab69d6121.tar.gz | |
config_file: extract function to parse include path
The logic inside this function will be required later on, when
implementing conditional includes. Extract it into its own function to
ease the implementation.
Diffstat (limited to 'src')
| -rw-r--r-- | src/config_file.c | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/src/config_file.c b/src/config_file.c index 4146bd8b2..0a15ca5b3 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -1576,6 +1576,39 @@ struct parse_data { int depth; }; +static int parse_include(struct reader *reader, + struct parse_data *parse_data, const char *file) +{ + struct config_file *include; + git_buf path = GIT_BUF_INIT; + char *dir; + int result; + + if ((result = git_path_dirname_r(&path, reader->file->path)) < 0) + return result; + + dir = git_buf_detach(&path); + result = included_path(&path, dir, file); + git__free(dir); + + if (result < 0) + return result; + + include = git_array_alloc(reader->file->includes); + memset(include, 0, sizeof(*include)); + git_array_init(include->includes); + include->path = git_buf_detach(&path); + + result = config_read(parse_data->values, include, parse_data->level, parse_data->depth+1); + + if (result == GIT_ENOTFOUND) { + giterr_clear(); + result = 0; + } + + return result; +} + static int read_on_variable( struct reader *reader, const char *current_section, @@ -1618,33 +1651,8 @@ static int read_on_variable( result = 0; /* Add or append the new config option */ - if (!git__strcmp(var->entry->name, "include.path")) { - struct config_file *include; - git_buf path = GIT_BUF_INIT; - char *dir; - - if ((result = git_path_dirname_r(&path, reader->file->path)) < 0) - return result; - - dir = git_buf_detach(&path); - result = included_path(&path, dir, var->entry->value); - git__free(dir); - - if (result < 0) - return result; - - include = git_array_alloc(reader->file->includes); - memset(include, 0, sizeof(*include)); - git_array_init(include->includes); - include->path = git_buf_detach(&path); - - result = config_read(parse_data->values, include, parse_data->level, parse_data->depth+1); - - if (result == GIT_ENOTFOUND) { - giterr_clear(); - result = 0; - } - } + if (!git__strcmp(var->entry->name, "include.path")) + result = parse_include(reader, parse_data, var->entry->value); return result; } |
