diff options
Diffstat (limited to 'builtin/config.c')
| -rw-r--r-- | builtin/config.c | 45 | 
1 files changed, 28 insertions, 17 deletions
diff --git a/builtin/config.c b/builtin/config.c index 59fb113b07..75852bd79d 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -547,30 +547,37 @@ static int git_get_color_config(const char *var, const char *value,  	return 0;  } -static void get_color(const struct config_location_options *opts, +static int get_color(const struct config_location_options *opts,  		      const char *var, const char *def_color)  {  	struct get_color_config_data data = {  		.get_color_slot = var,  		.parsed_color[0] = '\0',  	}; +	int ret;  	config_with_options(git_get_color_config, &data,  			    &opts->source, the_repository,  			    &opts->options);  	if (!data.get_color_found && def_color) { -		if (color_parse(def_color, data.parsed_color) < 0) -			die(_("unable to parse default color value")); +		if (color_parse(def_color, data.parsed_color) < 0) { +			ret = error(_("unable to parse default color value")); +			goto out; +		}  	} +	ret = 0; + +out:  	fputs(data.parsed_color, stdout); +	return ret;  }  struct get_colorbool_config_data { -	int get_colorbool_found; -	int get_diff_color_found; -	int get_color_ui_found; +	enum git_colorbool get_colorbool_found; +	enum git_colorbool get_diff_color_found; +	enum git_colorbool get_color_ui_found;  	const char *get_colorbool_slot;  }; @@ -594,33 +601,34 @@ static int get_colorbool(const struct config_location_options *opts,  {  	struct get_colorbool_config_data data = {  		.get_colorbool_slot = var, -		.get_colorbool_found = -1, -		.get_diff_color_found = -1, -		.get_color_ui_found = -1, +		.get_colorbool_found = GIT_COLOR_UNKNOWN, +		.get_diff_color_found = GIT_COLOR_UNKNOWN, +		.get_color_ui_found = GIT_COLOR_UNKNOWN,  	}; +	bool result;  	config_with_options(git_get_colorbool_config, &data,  			    &opts->source, the_repository,  			    &opts->options); -	if (data.get_colorbool_found < 0) { +	if (data.get_colorbool_found == GIT_COLOR_UNKNOWN) {  		if (!strcmp(data.get_colorbool_slot, "color.diff"))  			data.get_colorbool_found = data.get_diff_color_found; -		if (data.get_colorbool_found < 0) +		if (data.get_colorbool_found == GIT_COLOR_UNKNOWN)  			data.get_colorbool_found = data.get_color_ui_found;  	} -	if (data.get_colorbool_found < 0) +	if (data.get_colorbool_found == GIT_COLOR_UNKNOWN)  		/* default value if none found in config */  		data.get_colorbool_found = GIT_COLOR_AUTO; -	data.get_colorbool_found = want_color(data.get_colorbool_found); +	result = want_color(data.get_colorbool_found);  	if (print) { -		printf("%s\n", data.get_colorbool_found ? "true" : "false"); +		printf("%s\n", result ? "true" : "false");  		return 0;  	} else -		return data.get_colorbool_found ? 0 : 1; +		return result ? 0 : 1;  }  static void check_write(const struct git_config_source *source) @@ -912,10 +920,13 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix,  	location_options_init(&location_opts, prefix);  	display_options_init(&display_opts); -	setup_auto_pager("config", 1); +	if (display_opts.type != TYPE_COLOR) +		setup_auto_pager("config", 1);  	if (url)  		ret = get_urlmatch(&location_opts, &display_opts, argv[0], url); +	else if (display_opts.type == TYPE_COLOR && !strlen(argv[0]) && display_opts.default_value) +		ret = get_color(&location_opts, "", display_opts.default_value);  	else  		ret = get_value(&location_opts, &display_opts, argv[0], value_pattern,  				get_value_flags, flags); @@ -1390,7 +1401,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)  	}  	else if (actions == ACTION_GET_COLOR) {  		check_argc(argc, 1, 2); -		get_color(&location_opts, argv[0], argv[1]); +		ret = get_color(&location_opts, argv[0], argv[1]);  	}  	else if (actions == ACTION_GET_COLORBOOL) {  		check_argc(argc, 1, 2);  | 
