Merge branch 'jn/parse-config-slot' into jk/colors
authorJunio C Hamano <gitster@pobox.com>
Thu, 20 Nov 2014 19:40:29 +0000 (11:40 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 Nov 2014 19:40:29 +0000 (11:40 -0800)
* jn/parse-config-slot:
color_parse: do not mention variable name in error message
pass config slots as pointers instead of offsets

1  2 
builtin/clean.c
builtin/config.c
diff --combined builtin/clean.c
index 3beeea6ec0fdc3883f2456caf46f3e1c4dadc682,035ea391a2ec0c9399fa9868888d32e84c93b227..a7e7b0bf6abc0d9d662ab99273dc1c2a86f26698
@@@ -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 84b8e1cfa5515c8a0c1dc5c22c5c1bb708847532,842809b0b3b0907a883d651a72891a071367ab9e..d11105d9070c9aaf4c5170715a4a53ce091dc094
@@@ -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);
        }
                        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;