From: Junio C Hamano Date: Thu, 20 Nov 2014 19:40:29 +0000 (-0800) Subject: Merge branch 'jn/parse-config-slot' into jk/colors X-Git-Tag: v2.3.0-rc0~46^2~5 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/62ce40d9338046a89de5d2bfb6b258872fd366c0?ds=inline;hp=-c Merge branch 'jn/parse-config-slot' into jk/colors * jn/parse-config-slot: color_parse: do not mention variable name in error message pass config slots as pointers instead of offsets --- 62ce40d9338046a89de5d2bfb6b258872fd366c0 diff --combined builtin/clean.c index 3beeea6ec0,035ea391a2..a7e7b0bf6a --- a/builtin/clean.c +++ b/builtin/clean.c @@@ -67,7 -67,7 +67,7 @@@ struct menu_item char hotkey; const char *title; int selected; - int (*fn)(); + int (*fn)(void); }; enum menu_stuff_type { @@@ -116,8 -116,7 +116,7 @@@ static int git_clean_config(const char return 0; if (!value) return config_error_nonbool(var); - color_parse(value, var, clean_colors[slot]); - return 0; + return color_parse(value, clean_colors[slot]); } if (!strcmp(var, "clean.requireforce")) { diff --combined builtin/config.c index 84b8e1cfa5,842809b0b3..d11105d907 --- a/builtin/config.c +++ b/builtin/config.c @@@ -69,8 -69,8 +69,8 @@@ static struct option builtin_config_opt OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST), OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), - OPT_STRING(0, "get-color", &get_color_slot, N_("slot"), N_("find the color configured: [default]")), - OPT_STRING(0, "get-colorbool", &get_colorbool_slot, N_("slot"), N_("find the color setting: [stdout-is-tty]")), + OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), + OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), OPT_GROUP(N_("Type")), OPT_BIT(0, "bool", &types, N_("value is \"true\" or \"false\""), TYPE_BOOL), OPT_BIT(0, "int", &types, N_("value is decimal number"), TYPE_INT), @@@ -296,22 -296,24 +296,25 @@@ static int git_get_color_config(const c if (!strcmp(var, get_color_slot)) { if (!value) config_error_nonbool(var); - color_parse(value, var, parsed_color); + if (color_parse(value, parsed_color) < 0) + return -1; get_color_found = 1; } return 0; } -static void get_color(const char *def_color) +static void get_color(const char *var, const char *def_color) { + get_color_slot = var; get_color_found = 0; parsed_color[0] = '\0'; git_config_with_options(git_get_color_config, NULL, &given_config_source, respect_includes); - if (!get_color_found && def_color) - color_parse(def_color, "command line", parsed_color); + if (!get_color_found && def_color) { + if (color_parse(def_color, parsed_color) < 0) + die(_("unable to parse default color value")); + } fputs(parsed_color, stdout); } @@@ -331,9 -333,8 +334,9 @@@ static int git_get_colorbool_config(con return 0; } -static int get_colorbool(int print) +static int get_colorbool(const char *var, int print) { + get_colorbool_slot = var; get_colorbool_found = -1; get_diff_color_found = -1; get_color_ui_found = -1; @@@ -517,7 -518,12 +520,7 @@@ int cmd_config(int argc, const char **a usage_with_options(builtin_config_usage, builtin_config_options); } - if (get_color_slot) - actions |= ACTION_GET_COLOR; - if (get_colorbool_slot) - actions |= ACTION_GET_COLORBOOL; - - if ((get_color_slot || get_colorbool_slot) && types) { + if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && types) { error("--get-color and variable type are incoherent"); usage_with_options(builtin_config_usage, builtin_config_options); } @@@ -652,14 -658,12 +655,14 @@@ die("No such section!"); } else if (actions == ACTION_GET_COLOR) { - get_color(argv[0]); + check_argc(argc, 1, 2); + get_color(argv[0], argv[1]); } else if (actions == ACTION_GET_COLORBOOL) { - if (argc == 1) - color_stdout_is_tty = git_config_bool("command line", argv[0]); - return get_colorbool(argc != 0); + check_argc(argc, 1, 2); + if (argc == 2) + color_stdout_is_tty = git_config_bool("command line", argv[1]); + return get_colorbool(argv[0], argc == 2); } return 0;