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.
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
diff --git a/src/config_file.c b/src/config_file.c
index 4146bd8..0a15ca5 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;
}