Commit d5b9d9e991f019119f3c18325987728ab69d6121

Patrick Steinhardt 2017-05-23T10:53:49

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.

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;
 }