{"thread":{"id":"17798","subject":"[PATCH 3/8] config: Use parseopt.","startedAt":"2009-02-15T09:00:53Z","lastAt":"2009-02-16T01:15:50Z","messageCount":19,"participants":["Felipe Contreras","Johannes Schindelin","Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"104746","messageId":"1234688460-9248-1-git-send-email-felipe.contreras@gmail.com","threadId":"17798","inReplyTo":null,"subject":"[PATCH 1/8] config: Trivial rename in preparation for parseopt.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T09:00:53Z","receivedAt":"2009-02-15T09:00:53Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"As suggested by Johannes Schindelin.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |    7 ++++---\n 1 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 6937eaf..bf8df58 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -178,6 +178,7 @@ static char *normalize_value(const char *key, const char *value)\n \n static int get_color_found;\n static const char *get_color_slot;\n+static const char *get_colorbool_slot;\n static char parsed_color[COLOR_MAXLEN];\n \n static int git_get_color_config(const char *var, const char *value, void *cb)\n@@ -231,7 +232,7 @@ static int get_diff_color_found;\n static int git_get_colorbool_config(const char *var, const char *value,\n \t\tvoid *cb)\n {\n-\tif (!strcmp(var, get_color_slot)) {\n+\tif (!strcmp(var, get_colorbool_slot)) {\n \t\tget_colorbool_found =\n \t\t\tgit_config_colorbool(var, value, stdout_is_tty);\n \t}\n@@ -263,11 +264,11 @@ static int get_colorbool(int argc, const char **argv)\n \t\tusage(git_config_set_usage);\n \tget_colorbool_found = -1;\n \tget_diff_color_found = -1;\n-\tget_color_slot = argv[0];\n+\tget_colorbool_slot = argv[0];\n \tgit_config(git_get_colorbool_config, NULL);\n \n \tif (get_colorbool_found < 0) {\n-\t\tif (!strcmp(get_color_slot, \"color.diff\"))\n+\t\tif (!strcmp(get_colorbool_slot, \"color.diff\"))\n \t\t\tget_colorbool_found = get_diff_color_found;\n \t\tif (get_colorbool_found < 0)\n \t\t\tget_colorbool_found = git_use_color_default;\n-- \n1.6.1.3\n"},{"id":"104747","messageId":"1234688460-9248-2-git-send-email-felipe.contreras@gmail.com","threadId":"17798","inReplyTo":"1234688460-9248-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 2/8] config: Cleanup config file handling.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T09:00:54Z","receivedAt":"2009-02-15T09:00:54Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"As suggested by Johannes Schindelin.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |   20 +++++++++-----------\n 1 files changed, 9 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex bf8df58..da754e0 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -282,11 +282,11 @@ static int get_colorbool(int argc, const char **argv)\n \t}\n }\n \n-int cmd_config(int argc, const char **argv, const char *prefix)\n+int cmd_config(int argc, const char **argv, const char *unused_prefix)\n {\n \tint nongit;\n \tchar* value;\n-\tconst char *file = setup_git_directory_gently(&nongit);\n+\tconst char *prefix = setup_git_directory_gently(&nongit);\n \n \tconfig_exclusive_filename = getenv(CONFIG_ENVIRONMENT);\n \n@@ -300,10 +300,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\telse if (!strcmp(argv[1], \"--list\") || !strcmp(argv[1], \"-l\")) {\n \t\t\tif (argc != 2)\n \t\t\t\tusage(git_config_set_usage);\n-\t\t\tif (git_config(show_all_config, NULL) < 0 &&\n-\t\t\t\t\tfile && errno)\n-\t\t\t\tdie(\"unable to read config file %s: %s\", file,\n-\t\t\t\t    strerror(errno));\n+\t\t\tif (git_config(show_all_config, NULL) < 0)\n+\t\t\t\tdie(\"error processing config file(s)\");\n \t\t\treturn 0;\n \t\t}\n \t\telse if (!strcmp(argv[1], \"--global\")) {\n@@ -320,12 +318,12 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\telse if (!strcmp(argv[1], \"--file\") || !strcmp(argv[1], \"-f\")) {\n \t\t\tif (argc < 3)\n \t\t\t\tusage(git_config_set_usage);\n-\t\t\tif (!is_absolute_path(argv[2]) && file)\n-\t\t\t\tfile = prefix_filename(file, strlen(file),\n-\t\t\t\t\t\t       argv[2]);\n+\t\t\tif (!is_absolute_path(argv[2]) && prefix)\n+\t\t\t\tconfig_exclusive_filename = prefix_filename(prefix,\n+\t\t\t\t\t\t\t\t\t    strlen(prefix),\n+\t\t\t\t\t\t\t\t\t    argv[2]);\n \t\t\telse\n-\t\t\t\tfile = argv[2];\n-\t\t\tconfig_exclusive_filename = file;\n+\t\t\t\tconfig_exclusive_filename = argv[2];\n \t\t\targc--;\n \t\t\targv++;\n \t\t}\n-- \n1.6.1.3\n"},{"id":"104741","messageId":"1234688460-9248-3-git-send-email-felipe.contreras@gmail.com","threadId":"17798","inReplyTo":"1234688460-9248-2-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 3/8] config: Use parseopt.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T09:00:55Z","receivedAt":"2009-02-15T09:00:55Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Reorganizing the code to use parseopt as suggested by Johannes\nSchindelin.\n\nThis patch has benefited from comments by Johannes\nSchindelin and Junio C Hamano.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |  362 ++++++++++++++++++++++++++---------------------------\n 1 files changed, 178 insertions(+), 184 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex da754e0..084222a 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -1,9 +1,12 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"color.h\"\n+#include \"parse-options.h\"\n \n-static const char git_config_set_usage[] =\n-\"git config [ --global | --system | [ -f | --file ] config-file ] [ --bool | --int | --bool-or-int ] [ -z | --null ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --remove-section name | --list | --get-color var [default] | --get-colorbool name [stdout-is-tty] | --edit | -e ]\";\n+static const char *const builtin_config_usage[] = {\n+\t\"git config [options]\",\n+\tNULL\n+};\n \n static char *key;\n static regex_t *key_regexp;\n@@ -18,6 +21,59 @@ static char key_delim = ' ';\n static char term = '\\n';\n static enum { T_RAW, T_INT, T_BOOL, T_BOOL_OR_INT } type = T_RAW;\n \n+static int use_global_config, use_system_config;\n+static const char *given_config_file;\n+static int actions;\n+static const char *get_color_slot, *get_colorbool_slot;\n+static int end_null;\n+\n+#define ACTION_GET (1<<0)\n+#define ACTION_GET_ALL (1<<1)\n+#define ACTION_GET_REGEXP (1<<2)\n+#define ACTION_REPLACE_ALL (1<<3)\n+#define ACTION_ADD (1<<4)\n+#define ACTION_UNSET (1<<5)\n+#define ACTION_UNSET_ALL (1<<6)\n+#define ACTION_RENAME_SECTION (1<<7)\n+#define ACTION_REMOVE_SECTION (1<<8)\n+#define ACTION_LIST (1<<9)\n+#define ACTION_EDIT (1<<10)\n+\n+static struct option builtin_config_options[] = {\n+\tOPT_GROUP(\"Config file location\"),\n+\tOPT_BOOLEAN(0, \"global\", &use_global_config, \"use global config file\"),\n+\tOPT_BOOLEAN(0, \"system\", &use_system_config, \"use system config file\"),\n+\tOPT_STRING('f', \"file\", &given_config_file, \"FILE\", \"use given config file\"),\n+\tOPT_GROUP(\"Action\"),\n+\tOPT_BIT(0, \"get\", &actions, \"get value: name [value-regex]\", ACTION_GET),\n+\tOPT_BIT(0, \"get-all\", &actions, \"get all values: key [value-regex]\", ACTION_GET),\n+\tOPT_BIT(0, \"get-regexp\", &actions, \"get values for regexp: name-regex [value-regex]\", ACTION_GET_REGEXP),\n+\tOPT_BIT(0, \"replace-all\", &actions, \"replace all matching variables: name [value [value_regex]\", ACTION_REPLACE_ALL),\n+\tOPT_BIT(0, \"add\", &actions, \"adds a new variable: name value\", ACTION_ADD),\n+\tOPT_BIT(0, \"unset\", &actions, \"removes a variable: name [value-regex]\", ACTION_UNSET),\n+\tOPT_BIT(0, \"unset-all\", &actions, \"removes all matches: name [value-regex]\", ACTION_UNSET_ALL),\n+\tOPT_BIT(0, \"rename-section\", &actions, \"rename section: old-name new-name\", ACTION_RENAME_SECTION),\n+\tOPT_BIT(0, \"remove-section\", &actions, \"remove a section: name\", ACTION_REMOVE_SECTION),\n+\tOPT_BIT('l', \"list\", &actions, \"list all\", ACTION_LIST),\n+\tOPT_BIT('e', \"edit\", &actions, \"opens an editor\", ACTION_EDIT),\n+\tOPT_GROUP(\"Type\"),\n+\tOPT_SET_INT(0, \"bool\", &type, \"value is \\\"true\\\" or \\\"false\\\"\", T_BOOL),\n+\tOPT_SET_INT(0, \"int\", &type, \"value is decimal number\", T_INT),\n+\tOPT_SET_INT(0, \"bool-or-int\", &type, NULL, T_BOOL_OR_INT),\n+\tOPT_STRING(0, \"get-color\", &get_color_slot, \"slot\", \"find the color configured: [default]\"),\n+\tOPT_STRING(0, \"get-colorbool\", &get_colorbool_slot, \"slot\", \"find the color setting: [stdout-is-tty]\"),\n+\tOPT_GROUP(\"Other\"),\n+\tOPT_BOOLEAN('z', \"null\", &end_null, \"terminate values with NUL byte\"),\n+\tOPT_END(),\n+};\n+\n+static void check_argc(int argc, int min, int max) {\n+\tif (argc >= min && argc <= max)\n+\t\treturn;\n+\terror(\"wrong number of arguments\");\n+\tusage_with_options(builtin_config_usage, builtin_config_options);\n+}\n+\n static int show_all_config(const char *key_, const char *value_, void *cb)\n {\n \tif (value_)\n@@ -180,7 +236,6 @@ static int get_color_found;\n static const char *get_color_slot;\n static const char *get_colorbool_slot;\n static char parsed_color[COLOR_MAXLEN];\n-\n static int git_get_color_config(const char *var, const char *value, void *cb)\n {\n \tif (!strcmp(var, get_color_slot)) {\n@@ -192,29 +247,8 @@ static int git_get_color_config(const char *var, const char *value, void *cb)\n \treturn 0;\n }\n \n-static int get_color(int argc, const char **argv)\n+static void get_color(const char *def_color)\n {\n-\t/*\n-\t * grab the color setting for the given slot from the configuration,\n-\t * or parse the default value if missing, and return ANSI color\n-\t * escape sequence.\n-\t *\n-\t * e.g.\n-\t * git config --get-color color.diff.whitespace \"blue reverse\"\n-\t */\n-\tconst char *def_color = NULL;\n-\n-\tswitch (argc) {\n-\tdefault:\n-\t\tusage(git_config_set_usage);\n-\tcase 2:\n-\t\tdef_color = argv[1];\n-\t\t/* fallthru */\n-\tcase 1:\n-\t\tget_color_slot = argv[0];\n-\t\tbreak;\n-\t}\n-\n \tget_color_found = 0;\n \tparsed_color[0] = '\\0';\n \tgit_config(git_get_color_config, NULL);\n@@ -223,7 +257,6 @@ static int get_color(int argc, const char **argv)\n \t\tcolor_parse(def_color, \"command line\", parsed_color);\n \n \tfputs(parsed_color, stdout);\n-\treturn 0;\n }\n \n static int stdout_is_tty;\n@@ -247,24 +280,10 @@ static int git_get_colorbool_config(const char *var, const char *value,\n \treturn 0;\n }\n \n-static int get_colorbool(int argc, const char **argv)\n+static int get_colorbool(int print)\n {\n-\t/*\n-\t * git config --get-colorbool <slot> [<stdout-is-tty>]\n-\t *\n-\t * returns \"true\" or \"false\" depending on how <slot>\n-\t * is configured.\n-\t */\n-\n-\tif (argc == 2)\n-\t\tstdout_is_tty = git_config_bool(\"command line\", argv[1]);\n-\telse if (argc == 1)\n-\t\tstdout_is_tty = isatty(1);\n-\telse\n-\t\tusage(git_config_set_usage);\n \tget_colorbool_found = -1;\n \tget_diff_color_found = -1;\n-\tget_colorbool_slot = argv[0];\n \tgit_config(git_get_colorbool_config, NULL);\n \n \tif (get_colorbool_found < 0) {\n@@ -274,12 +293,11 @@ static int get_colorbool(int argc, const char **argv)\n \t\t\tget_colorbool_found = git_use_color_default;\n \t}\n \n-\tif (argc == 1) {\n-\t\treturn get_colorbool_found ? 0 : 1;\n-\t} else {\n+\tif (print) {\n \t\tprintf(\"%s\\n\", get_colorbool_found ? \"true\" : \"false\");\n \t\treturn 0;\n-\t}\n+\t} else\n+\t\treturn get_colorbool_found ? 0 : 1;\n }\n \n int cmd_config(int argc, const char **argv, const char *unused_prefix)\n@@ -290,149 +308,125 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \n \tconfig_exclusive_filename = getenv(CONFIG_ENVIRONMENT);\n \n-\twhile (1 < argc) {\n-\t\tif (!strcmp(argv[1], \"--int\"))\n-\t\t\ttype = T_INT;\n-\t\telse if (!strcmp(argv[1], \"--bool\"))\n-\t\t\ttype = T_BOOL;\n-\t\telse if (!strcmp(argv[1], \"--bool-or-int\"))\n-\t\t\ttype = T_BOOL_OR_INT;\n-\t\telse if (!strcmp(argv[1], \"--list\") || !strcmp(argv[1], \"-l\")) {\n-\t\t\tif (argc != 2)\n-\t\t\t\tusage(git_config_set_usage);\n-\t\t\tif (git_config(show_all_config, NULL) < 0)\n-\t\t\t\tdie(\"error processing config file(s)\");\n-\t\t\treturn 0;\n-\t\t}\n-\t\telse if (!strcmp(argv[1], \"--global\")) {\n-\t\t\tchar *home = getenv(\"HOME\");\n-\t\t\tif (home) {\n-\t\t\t\tchar *user_config = xstrdup(mkpath(\"%s/.gitconfig\", home));\n-\t\t\t\tconfig_exclusive_filename = user_config;\n-\t\t\t} else {\n-\t\t\t\tdie(\"$HOME not set\");\n-\t\t\t}\n-\t\t}\n-\t\telse if (!strcmp(argv[1], \"--system\"))\n-\t\t\tconfig_exclusive_filename = git_etc_gitconfig();\n-\t\telse if (!strcmp(argv[1], \"--file\") || !strcmp(argv[1], \"-f\")) {\n-\t\t\tif (argc < 3)\n-\t\t\t\tusage(git_config_set_usage);\n-\t\t\tif (!is_absolute_path(argv[2]) && prefix)\n-\t\t\t\tconfig_exclusive_filename = prefix_filename(prefix,\n-\t\t\t\t\t\t\t\t\t    strlen(prefix),\n-\t\t\t\t\t\t\t\t\t    argv[2]);\n-\t\t\telse\n-\t\t\t\tconfig_exclusive_filename = argv[2];\n-\t\t\targc--;\n-\t\t\targv++;\n-\t\t}\n-\t\telse if (!strcmp(argv[1], \"--null\") || !strcmp(argv[1], \"-z\")) {\n-\t\t\tterm = '\\0';\n-\t\t\tdelim = '\\n';\n-\t\t\tkey_delim = '\\n';\n-\t\t}\n-\t\telse if (!strcmp(argv[1], \"--rename-section\")) {\n-\t\t\tint ret;\n-\t\t\tif (argc != 4)\n-\t\t\t\tusage(git_config_set_usage);\n-\t\t\tret = git_config_rename_section(argv[2], argv[3]);\n-\t\t\tif (ret < 0)\n-\t\t\t\treturn ret;\n-\t\t\tif (ret == 0) {\n-\t\t\t\tfprintf(stderr, \"No such section!\\n\");\n-\t\t\t\treturn 1;\n-\t\t\t}\n-\t\t\treturn 0;\n-\t\t}\n-\t\telse if (!strcmp(argv[1], \"--remove-section\")) {\n-\t\t\tint ret;\n-\t\t\tif (argc != 3)\n-\t\t\t\tusage(git_config_set_usage);\n-\t\t\tret = git_config_rename_section(argv[2], NULL);\n-\t\t\tif (ret < 0)\n-\t\t\t\treturn ret;\n-\t\t\tif (ret == 0) {\n-\t\t\t\tfprintf(stderr, \"No such section!\\n\");\n-\t\t\t\treturn 1;\n-\t\t\t}\n-\t\t\treturn 0;\n-\t\t} else if (!strcmp(argv[1], \"--get-color\")) {\n-\t\t\treturn get_color(argc-2, argv+2);\n-\t\t} else if (!strcmp(argv[1], \"--get-colorbool\")) {\n-\t\t\treturn get_colorbool(argc-2, argv+2);\n-\t\t} else if (!strcmp(argv[1], \"--edit\") || !strcmp(argv[1], \"-e\")) {\n-\t\t\tconst char *config_filename;\n-\t\t\tif (argc != 2)\n-\t\t\t\tusage(git_config_set_usage);\n-\t\t\tif (config_exclusive_filename)\n-\t\t\t\tconfig_filename = config_exclusive_filename;\n-\t\t\telse\n-\t\t\t\tconfig_filename = git_path(\"config\");\n-\t\t\tgit_config(git_default_config, NULL);\n-\t\t\tlaunch_editor(config_filename, NULL, NULL);\n-\t\t\treturn 0;\n-\t\t} else\n-\t\t\tbreak;\n-\t\targc--;\n-\t\targv++;\n-\t}\n+\targc = parse_options(argc, argv, builtin_config_options, builtin_config_usage, 0);\n \n-\tswitch (argc) {\n-\tcase 2:\n-\t\treturn get_value(argv[1], NULL);\n-\tcase 3:\n-\t\tif (!strcmp(argv[1], \"--unset\"))\n-\t\t\treturn git_config_set(argv[2], NULL);\n-\t\telse if (!strcmp(argv[1], \"--unset-all\"))\n-\t\t\treturn git_config_set_multivar(argv[2], NULL, NULL, 1);\n-\t\telse if (!strcmp(argv[1], \"--get\"))\n-\t\t\treturn get_value(argv[2], NULL);\n-\t\telse if (!strcmp(argv[1], \"--get-all\")) {\n-\t\t\tdo_all = 1;\n-\t\t\treturn get_value(argv[2], NULL);\n-\t\t} else if (!strcmp(argv[1], \"--get-regexp\")) {\n-\t\t\tshow_keys = 1;\n-\t\t\tuse_key_regexp = 1;\n-\t\t\tdo_all = 1;\n-\t\t\treturn get_value(argv[2], NULL);\n-\t\t} else {\n-\t\t\tvalue = normalize_value(argv[1], argv[2]);\n-\t\t\treturn git_config_set(argv[1], value);\n-\t\t}\n-\tcase 4:\n-\t\tif (!strcmp(argv[1], \"--unset\"))\n-\t\t\treturn git_config_set_multivar(argv[2], NULL, argv[3], 0);\n-\t\telse if (!strcmp(argv[1], \"--unset-all\"))\n-\t\t\treturn git_config_set_multivar(argv[2], NULL, argv[3], 1);\n-\t\telse if (!strcmp(argv[1], \"--get\"))\n-\t\t\treturn get_value(argv[2], argv[3]);\n-\t\telse if (!strcmp(argv[1], \"--get-all\")) {\n-\t\t\tdo_all = 1;\n-\t\t\treturn get_value(argv[2], argv[3]);\n-\t\t} else if (!strcmp(argv[1], \"--get-regexp\")) {\n-\t\t\tshow_keys = 1;\n-\t\t\tuse_key_regexp = 1;\n-\t\t\tdo_all = 1;\n-\t\t\treturn get_value(argv[2], argv[3]);\n-\t\t} else if (!strcmp(argv[1], \"--add\")) {\n-\t\t\tvalue = normalize_value(argv[2], argv[3]);\n-\t\t\treturn git_config_set_multivar(argv[2], value, \"^$\", 0);\n-\t\t} else if (!strcmp(argv[1], \"--replace-all\")) {\n-\t\t\tvalue = normalize_value(argv[2], argv[3]);\n-\t\t\treturn git_config_set_multivar(argv[2], value, NULL, 1);\n+\tif (use_global_config) {\n+\t\tchar *home = getenv(\"HOME\");\n+\t\tif (home) {\n+\t\t\tchar *user_config = xstrdup(mkpath(\"%s/.gitconfig\", home));\n+\t\t\tconfig_exclusive_filename = user_config;\n \t\t} else {\n-\t\t\tvalue = normalize_value(argv[1], argv[2]);\n-\t\t\treturn git_config_set_multivar(argv[1], value, argv[3], 0);\n+\t\t\tdie(\"$HOME not set\");\n \t\t}\n-\tcase 5:\n-\t\tif (!strcmp(argv[1], \"--replace-all\")) {\n-\t\t\tvalue = normalize_value(argv[2], argv[3]);\n-\t\t\treturn git_config_set_multivar(argv[2], value, argv[4], 1);\n+\t}\n+\telse if (use_system_config)\n+\t\tconfig_exclusive_filename = git_etc_gitconfig();\n+\telse if (given_config_file) {\n+\t\tif (!is_absolute_path(given_config_file) && prefix)\n+\t\t\tconfig_exclusive_filename = prefix_filename(prefix,\n+\t\t\t\t\t\t\t\t    strlen(prefix),\n+\t\t\t\t\t\t\t\t    argv[2]);\n+\t\telse\n+\t\t\tconfig_exclusive_filename = given_config_file;\n+\t}\n+\n+\tif (end_null) {\n+\t\tterm = '\\0';\n+\t\tdelim = '\\n';\n+\t\tkey_delim = '\\n';\n+\t}\n+\n+\tif (HAS_MULTI_BITS(actions)) {\n+\t\terror(\"only one action at a time.\");\n+\t\tusage_with_options(builtin_config_usage, builtin_config_options);\n+\t}\n+\tif (actions == 0)\n+\t\tswitch (argc) {\n+\t\tcase 1: actions |= ACTION_GET; break;\n+\t\tcase 2: actions |= ACTION_ADD; break;\n+\t\tcase 3: actions |= ACTION_REPLACE_ALL; break;\n+\t\tdefault:\n+\t\t\tusage_with_options(builtin_config_usage, builtin_config_options);\n \t\t}\n-\tcase 1:\n-\tdefault:\n-\t\tusage(git_config_set_usage);\n+\n+\tif (actions & ACTION_LIST) {\n+\t\tif (git_config(show_all_config, NULL) < 0)\n+\t\t\tdie(\"error processing config file(s)\");\n+\t}\n+\telse if (actions & ACTION_EDIT) {\n+\t\tconst char *config_filename;\n+\t\tif (config_exclusive_filename)\n+\t\t\tconfig_filename = config_exclusive_filename;\n+\t\telse\n+\t\t\tconfig_filename = git_path(\"config\");\n+\t\tgit_config(git_default_config, NULL);\n+\t\tlaunch_editor(config_filename, NULL, NULL);\n+\t}\n+\telse if (actions & ACTION_ADD) {\n+\t\tcheck_argc(argc, 2, 2);\n+\t\tvalue = normalize_value(argv[0], argv[1]);\n+\t\treturn git_config_set_multivar(argv[0], value, \"^$\", 0);\n+\t}\n+\telse if (actions & ACTION_REPLACE_ALL) {\n+\t\tcheck_argc(argc, 2, 3);\n+\t\tvalue = normalize_value(argv[0], argv[1]);\n+\t\treturn git_config_set_multivar(argv[0], value, argv[2], 1);\n+\t}\n+\telse if (actions & ACTION_GET) {\n+\t\tcheck_argc(argc, 1, 2);\n+\t\treturn get_value(argv[0], argv[1]);\n \t}\n+\telse if (actions & ACTION_GET_ALL) {\n+\t\tdo_all = 1;\n+\t\tcheck_argc(argc, 1, 2);\n+\t\treturn get_value(argv[0], argv[1]);\n+\t}\n+\telse if (actions & ACTION_GET_REGEXP) {\n+\t\tshow_keys = 1;\n+\t\tuse_key_regexp = 1;\n+\t\tdo_all = 1;\n+\t\tcheck_argc(argc, 1, 2);\n+\t\treturn get_value(argv[0], argv[1]);\n+\t}\n+\telse if (actions & ACTION_UNSET) {\n+\t\tcheck_argc(argc, 1, 2);\n+\t\tif (argc == 2)\n+\t\t\treturn git_config_set_multivar(argv[0], NULL, argv[1], 0);\n+\t\telse\n+\t\t\treturn git_config_set(argv[0], NULL);\n+\t}\n+\telse if (actions & ACTION_UNSET_ALL) {\n+\t\tcheck_argc(argc, 1, 2);\n+\t\treturn git_config_set_multivar(argv[0], NULL, argv[1], 1);\n+\t}\n+\telse if (actions & ACTION_RENAME_SECTION) {\n+\t\tint ret;\n+\t\tcheck_argc(argc, 2, 2);\n+\t\tret = git_config_rename_section(argv[0], argv[1]);\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\t\tif (ret == 0)\n+\t\t\tdie(\"No such section!\");\n+\t}\n+\telse if (actions & ACTION_REMOVE_SECTION) {\n+\t\tint ret;\n+\t\tcheck_argc(argc, 1, 1);\n+\t\tret = git_config_rename_section(argv[0], NULL);\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\t\tif (ret == 0)\n+\t\t\tdie(\"No such section!\");\n+\t}\n+\telse if (get_color_slot) {\n+\t\tget_color(argv[0]);\n+\t}\n+\telse if (get_colorbool_slot) {\n+\t\tif (argc == 1)\n+\t\t\tstdout_is_tty = git_config_bool(\"command line\", argv[0]);\n+\t\telse if (argc == 0)\n+\t\t\tstdout_is_tty = isatty(1);\n+\t\treturn get_colorbool(argc != 1);\n+\t}\n+\n \treturn 0;\n }\n-- \n1.6.1.3\n"},{"id":"104742","messageId":"1234688460-9248-4-git-send-email-felipe.contreras@gmail.com","threadId":"17798","inReplyTo":"1234688460-9248-3-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 4/8] config: Improve variable 'type' handling.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T09:00:56Z","receivedAt":"2009-02-15T09:00:56Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"So now only either --bool, --int, or --bool-or-int can be used, but not\nany combination of them.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |   23 +++++++++++++++++++----\n 1 files changed, 19 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 084222a..83f8b74 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -23,7 +23,7 @@ static enum { T_RAW, T_INT, T_BOOL, T_BOOL_OR_INT } type = T_RAW;\n \n static int use_global_config, use_system_config;\n static const char *given_config_file;\n-static int actions;\n+static int actions, types;\n static const char *get_color_slot, *get_colorbool_slot;\n static int end_null;\n \n@@ -39,6 +39,10 @@ static int end_null;\n #define ACTION_LIST (1<<9)\n #define ACTION_EDIT (1<<10)\n \n+#define TYPE_BOOL (1<<0)\n+#define TYPE_INT (1<<1)\n+#define TYPE_BOOL_OR_INT (1<<2)\n+\n static struct option builtin_config_options[] = {\n \tOPT_GROUP(\"Config file location\"),\n \tOPT_BOOLEAN(0, \"global\", &use_global_config, \"use global config file\"),\n@@ -57,9 +61,9 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT('l', \"list\", &actions, \"list all\", ACTION_LIST),\n \tOPT_BIT('e', \"edit\", &actions, \"opens an editor\", ACTION_EDIT),\n \tOPT_GROUP(\"Type\"),\n-\tOPT_SET_INT(0, \"bool\", &type, \"value is \\\"true\\\" or \\\"false\\\"\", T_BOOL),\n-\tOPT_SET_INT(0, \"int\", &type, \"value is decimal number\", T_INT),\n-\tOPT_SET_INT(0, \"bool-or-int\", &type, NULL, T_BOOL_OR_INT),\n+\tOPT_BIT(0, \"bool\", &types, \"value is \\\"true\\\" or \\\"false\\\"\", TYPE_BOOL),\n+\tOPT_BIT(0, \"int\", &types, \"value is decimal number\", TYPE_INT),\n+\tOPT_BIT(0, \"bool-or-int\", &types, NULL, TYPE_BOOL_OR_INT),\n \tOPT_STRING(0, \"get-color\", &get_color_slot, \"slot\", \"find the color configured: [default]\"),\n \tOPT_STRING(0, \"get-colorbool\", &get_colorbool_slot, \"slot\", \"find the color setting: [stdout-is-tty]\"),\n \tOPT_GROUP(\"Other\"),\n@@ -336,6 +340,17 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\tkey_delim = '\\n';\n \t}\n \n+\tif (HAS_MULTI_BITS(types)) {\n+\t\terror(\"only one type at a time.\");\n+\t\tusage_with_options(builtin_config_usage, builtin_config_options);\n+\t}\n+\tswitch (types) {\n+\tcase TYPE_BOOL: type = T_BOOL; break;\n+\tcase TYPE_INT: type = T_INT; break;\n+\tcase TYPE_BOOL_OR_INT: type = T_BOOL_OR_INT; break;\n+\tdefault: break;\n+\t}\n+\n \tif (HAS_MULTI_BITS(actions)) {\n \t\terror(\"only one action at a time.\");\n \t\tusage_with_options(builtin_config_usage, builtin_config_options);\n-- \n1.6.1.3\n"},{"id":"104743","messageId":"1234688460-9248-5-git-send-email-felipe.contreras@gmail.com","threadId":"17798","inReplyTo":"1234688460-9248-4-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 5/8] config: Disallow multiple config file locations.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T09:00:57Z","receivedAt":"2009-02-15T09:00:57Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Either --global, --system, or --file should be used, but not any\ncombination.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |   10 ++++++++++\n 1 files changed, 10 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 83f8b74..e744ad8 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -314,6 +314,16 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \n \targc = parse_options(argc, argv, builtin_config_options, builtin_config_usage, 0);\n \n+\t{\n+\t\tint config_file_count = use_global_config + use_system_config;\n+\t\tif (given_config_file)\n+\t\t\tconfig_file_count++;\n+\t\tif (config_file_count > 1) {\n+\t\t\terror(\"only one config file at a time.\");\n+\t\t\tusage_with_options(builtin_config_usage, builtin_config_options);\n+\t\t}\n+\t}\n+\n \tif (use_global_config) {\n \t\tchar *home = getenv(\"HOME\");\n \t\tif (home) {\n-- \n1.6.1.3\n"},{"id":"104748","messageId":"1234688460-9248-6-git-send-email-felipe.contreras@gmail.com","threadId":"17798","inReplyTo":"1234688460-9248-5-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 6/8] config: Don't allow extra arguments for -e or -l.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T09:00:58Z","receivedAt":"2009-02-15T09:00:58Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"As suggested by Johannes Schindelin.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |    2 ++\n 1 files changed, 2 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex e744ad8..3463b1c 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -375,10 +375,12 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\t}\n \n \tif (actions & ACTION_LIST) {\n+\t\tcheck_argc(argc, 0, 0);\n \t\tif (git_config(show_all_config, NULL) < 0)\n \t\t\tdie(\"error processing config file(s)\");\n \t}\n \telse if (actions & ACTION_EDIT) {\n+\t\tcheck_argc(argc, 0, 0);\n \t\tconst char *config_filename;\n \t\tif (config_exclusive_filename)\n \t\t\tconfig_filename = config_exclusive_filename;\n-- \n1.6.1.3\n"},{"id":"104744","messageId":"1234688460-9248-7-git-send-email-felipe.contreras@gmail.com","threadId":"17798","inReplyTo":"1234688460-9248-6-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 7/8] config: Don't return negative exit codes.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T09:00:59Z","receivedAt":"2009-02-15T09:00:59Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"As suggested by Johannes Schindelin.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |   27 +++++++++++----------------\n 1 files changed, 11 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 3463b1c..677ae3f 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -308,6 +308,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n {\n \tint nongit;\n \tchar* value;\n+\tint ret = 0;\n \tconst char *prefix = setup_git_directory_gently(&nongit);\n \n \tconfig_exclusive_filename = getenv(CONFIG_ENVIRONMENT);\n@@ -392,55 +393,49 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \telse if (actions & ACTION_ADD) {\n \t\tcheck_argc(argc, 2, 2);\n \t\tvalue = normalize_value(argv[0], argv[1]);\n-\t\treturn git_config_set_multivar(argv[0], value, \"^$\", 0);\n+\t\tret = git_config_set_multivar(argv[0], value, \"^$\", 0);\n \t}\n \telse if (actions & ACTION_REPLACE_ALL) {\n \t\tcheck_argc(argc, 2, 3);\n \t\tvalue = normalize_value(argv[0], argv[1]);\n-\t\treturn git_config_set_multivar(argv[0], value, argv[2], 1);\n+\t\tret = git_config_set_multivar(argv[0], value, argv[2], 1);\n \t}\n \telse if (actions & ACTION_GET) {\n \t\tcheck_argc(argc, 1, 2);\n-\t\treturn get_value(argv[0], argv[1]);\n+\t\tret = get_value(argv[0], argv[1]);\n \t}\n \telse if (actions & ACTION_GET_ALL) {\n \t\tdo_all = 1;\n \t\tcheck_argc(argc, 1, 2);\n-\t\treturn get_value(argv[0], argv[1]);\n+\t\tret = get_value(argv[0], argv[1]);\n \t}\n \telse if (actions & ACTION_GET_REGEXP) {\n \t\tshow_keys = 1;\n \t\tuse_key_regexp = 1;\n \t\tdo_all = 1;\n \t\tcheck_argc(argc, 1, 2);\n-\t\treturn get_value(argv[0], argv[1]);\n+\t\tret = get_value(argv[0], argv[1]);\n \t}\n \telse if (actions & ACTION_UNSET) {\n \t\tcheck_argc(argc, 1, 2);\n \t\tif (argc == 2)\n-\t\t\treturn git_config_set_multivar(argv[0], NULL, argv[1], 0);\n+\t\t\tret = git_config_set_multivar(argv[0], NULL, argv[1], 0);\n \t\telse\n-\t\t\treturn git_config_set(argv[0], NULL);\n+\t\t\tret = git_config_set(argv[0], NULL);\n \t}\n \telse if (actions & ACTION_UNSET_ALL) {\n \t\tcheck_argc(argc, 1, 2);\n-\t\treturn git_config_set_multivar(argv[0], NULL, argv[1], 1);\n+\t\tret = git_config_set_multivar(argv[0], NULL, argv[1], 1);\n \t}\n \telse if (actions & ACTION_RENAME_SECTION) {\n-\t\tint ret;\n \t\tcheck_argc(argc, 2, 2);\n \t\tret = git_config_rename_section(argv[0], argv[1]);\n-\t\tif (ret < 0)\n-\t\t\treturn ret;\n \t\tif (ret == 0)\n \t\t\tdie(\"No such section!\");\n \t}\n \telse if (actions & ACTION_REMOVE_SECTION) {\n-\t\tint ret;\n \t\tcheck_argc(argc, 1, 1);\n \t\tret = git_config_rename_section(argv[0], NULL);\n-\t\tif (ret < 0)\n-\t\t\treturn ret;\n \t\tif (ret == 0)\n \t\t\tdie(\"No such section!\");\n \t}\n@@ -452,8 +447,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\t\tstdout_is_tty = git_config_bool(\"command line\", argv[0]);\n \t\telse if (argc == 0)\n \t\t\tstdout_is_tty = isatty(1);\n-\t\treturn get_colorbool(argc != 1);\n+\t\tret = get_colorbool(argc != 1);\n \t}\n \n-\treturn 0;\n+\treturn !!ret;\n }\n-- \n1.6.1.3\n"},{"id":"104745","messageId":"1234688460-9248-8-git-send-email-felipe.contreras@gmail.com","threadId":"17798","inReplyTo":"1234688460-9248-7-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 8/8] config: Codestyle cleanups.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T09:01:00Z","receivedAt":"2009-02-15T09:01:00Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |    6 +++---\n 1 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 677ae3f..4d1805b 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -87,7 +87,7 @@ static int show_all_config(const char *key_, const char *value_, void *cb)\n \treturn 0;\n }\n \n-static int show_config(const char* key_, const char* value_, void *cb)\n+static int show_config(const char *key_, const char *value_, void *cb)\n {\n \tchar value[256];\n \tconst char *vptr = value;\n@@ -134,7 +134,7 @@ static int show_config(const char* key_, const char* value_, void *cb)\n \treturn 0;\n }\n \n-static int get_value(const char* key_, const char* regex_)\n+static int get_value(const char *key_, const char *regex_)\n {\n \tint ret = -1;\n \tchar *tl;\n@@ -307,7 +307,7 @@ static int get_colorbool(int print)\n int cmd_config(int argc, const char **argv, const char *unused_prefix)\n {\n \tint nongit;\n-\tchar* value;\n+\tchar *value;\n \tint ret = 0;\n \tconst char *prefix = setup_git_directory_gently(&nongit);\n \n-- \n1.6.1.3\n"},{"id":"104765","messageId":"alpine.DEB.1.00.0902151321310.10279@pacific.mpi-cbg.de","threadId":"17798","inReplyTo":"1234688460-9248-7-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH 7/8] config: Don't return negative exit codes.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-02-15T12:22:30Z","receivedAt":"2009-02-15T12:22:30Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 15 Feb 2009, Felipe Contreras wrote:\n\n\n>  \telse if (actions & ACTION_RENAME_SECTION) {\n> -\t\tint ret;\n>  \t\tcheck_argc(argc, 2, 2);\n>  \t\tret = git_config_rename_section(argv[0], argv[1]);\n> -\t\tif (ret < 0)\n> -\t\t\treturn ret;\n>  \t\tif (ret == 0)\n>  \t\t\tdie(\"No such section!\");\n>  \t}\n\nYou need an \"if (ret > 0) ret = 0;\" to avoid regressions.\n\n>  \telse if (actions & ACTION_REMOVE_SECTION) {\n> -\t\tint ret;\n>  \t\tcheck_argc(argc, 1, 1);\n>  \t\tret = git_config_rename_section(argv[0], NULL);\n> -\t\tif (ret < 0)\n> -\t\t\treturn ret;\n>  \t\tif (ret == 0)\n>  \t\t\tdie(\"No such section!\");\n>  \t}\n\nLikewise.\n\nThanks,\nDscho\n"},{"id":"104766","messageId":"alpine.DEB.1.00.0902151323100.10279@pacific.mpi-cbg.de","threadId":"17798","inReplyTo":"1234688460-9248-4-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH 4/8] config: Improve variable 'type' handling.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-02-15T12:24:33Z","receivedAt":"2009-02-15T12:24:33Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 15 Feb 2009, Felipe Contreras wrote:\n\n> +\tswitch (types) {\n> +\tcase TYPE_BOOL: type = T_BOOL; break;\n> +\tcase TYPE_INT: type = T_INT; break;\n> +\tcase TYPE_BOOL_OR_INT: type = T_BOOL_OR_INT; break;\n> +\tdefault: break;\n> +\t}\n\nWould it not be nicer to get rid of the variable named \"type\" and use \n\"types == TYPE_BOOL\" and similar statements instead?\n\nCiao,\nDscho\n"},{"id":"293755","messageId":"alpine.DEB.1.00.0902151324530.10279@pacific.mpi-cbg.de","threadId":"17798","inReplyTo":"1234688460-9248-5-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH 5/8] config: Disallow multiple config file locations.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-02-15T12:26:34Z","receivedAt":"2009-02-15T12:26:34Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 15 Feb 2009, Felipe Contreras wrote:\n\n> Either --global, --system, or --file should be used, but not any\n> combination.\n> \n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n> ---\n>  builtin-config.c |   10 ++++++++++\n>  1 files changed, 10 insertions(+), 0 deletions(-)\n> \n> diff --git a/builtin-config.c b/builtin-config.c\n> index 83f8b74..e744ad8 100644\n> --- a/builtin-config.c\n> +++ b/builtin-config.c\n> @@ -314,6 +314,16 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n>  \n>  \targc = parse_options(argc, argv, builtin_config_options, builtin_config_usage, 0);\n>  \n> +\t{\n> +\t\tint config_file_count = use_global_config + use_system_config;\n> +\t\tif (given_config_file)\n> +\t\t\tconfig_file_count++;\n> +\t\tif (config_file_count > 1) {\n> +\t\t\terror(\"only one config file at a time.\");\n> +\t\t\tusage_with_options(builtin_config_usage, builtin_config_options);\n> +\t\t}\n> +\t}\n\nHmm.  Is this a convoluted way to write\n\n\tif (use_global_config + use_system_config + !!given_config_file > 1)\n\nor am I misunderstanding anything?\n\nCiao,\nDscho\n"},{"id":"104768","messageId":"94a0d4530902150439peac228ckec79f8c692b84e4e@mail.gmail.com","threadId":"17798","inReplyTo":"alpine.DEB.1.00.0902151321310.10279@pacific.mpi-cbg.de","subject":"Re: [PATCH 7/8] config: Don't return negative exit codes.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T12:39:47Z","receivedAt":"2009-02-15T12:39:47Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Feb 15, 2009 at 2:22 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Sun, 15 Feb 2009, Felipe Contreras wrote:\n>\n>\n>>       else if (actions & ACTION_RENAME_SECTION) {\n>> -             int ret;\n>>               check_argc(argc, 2, 2);\n>>               ret = git_config_rename_section(argv[0], argv[1]);\n>> -             if (ret < 0)\n>> -                     return ret;\n>>               if (ret == 0)\n>>                       die(\"No such section!\");\n>>       }\n>\n> You need an \"if (ret > 0) ret = 0;\" to avoid regressions.\n>\n>>       else if (actions & ACTION_REMOVE_SECTION) {\n>> -             int ret;\n>>               check_argc(argc, 1, 1);\n>>               ret = git_config_rename_section(argv[0], NULL);\n>> -             if (ret < 0)\n>> -                     return ret;\n>>               if (ret == 0)\n>>                       die(\"No such section!\");\n>>       }\n>\n> Likewise.\n\nTrue. Fixed in the attached patch.\n\n-- \nFelipe Contreras\n\n\nFrom b682131b61d01cac2946e7c7ab6666fef86441a4 Mon Sep 17 00:00:00 2001\nFrom: Felipe Contreras <felipe.contreras@gmail.com>\nDate: Sun, 15 Feb 2009 10:54:53 +0200\nSubject: [PATCH 7/8] config: Don't return negative exit codes.\n\nAs suggested by Johannes Schindelin.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |   31 +++++++++++++++----------------\n 1 files changed, 15 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 5891a4e..0606ada 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -307,6 +307,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n {\n \tint nongit;\n \tchar* value;\n+\tint ret = 0;\n \tconst char *prefix = setup_git_directory_gently(&nongit);\n \n \tconfig_exclusive_filename = getenv(CONFIG_ENVIRONMENT);\n@@ -380,57 +381,55 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \telse if (actions & ACTION_ADD) {\n \t\tcheck_argc(argc, 2, 2);\n \t\tvalue = normalize_value(argv[0], argv[1]);\n-\t\treturn git_config_set_multivar(argv[0], value, \"^$\", 0);\n+\t\tret = git_config_set_multivar(argv[0], value, \"^$\", 0);\n \t}\n \telse if (actions & ACTION_REPLACE_ALL) {\n \t\tcheck_argc(argc, 2, 3);\n \t\tvalue = normalize_value(argv[0], argv[1]);\n-\t\treturn git_config_set_multivar(argv[0], value, argv[2], 1);\n+\t\tret = git_config_set_multivar(argv[0], value, argv[2], 1);\n \t}\n \telse if (actions & ACTION_GET) {\n \t\tcheck_argc(argc, 1, 2);\n-\t\treturn get_value(argv[0], argv[1]);\n+\t\tret = get_value(argv[0], argv[1]);\n \t}\n \telse if (actions & ACTION_GET_ALL) {\n \t\tdo_all = 1;\n \t\tcheck_argc(argc, 1, 2);\n-\t\treturn get_value(argv[0], argv[1]);\n+\t\tret = get_value(argv[0], argv[1]);\n \t}\n \telse if (actions & ACTION_GET_REGEXP) {\n \t\tshow_keys = 1;\n \t\tuse_key_regexp = 1;\n \t\tdo_all = 1;\n \t\tcheck_argc(argc, 1, 2);\n-\t\treturn get_value(argv[0], argv[1]);\n+\t\tret = get_value(argv[0], argv[1]);\n \t}\n \telse if (actions & ACTION_UNSET) {\n \t\tcheck_argc(argc, 1, 2);\n \t\tif (argc == 2)\n-\t\t\treturn git_config_set_multivar(argv[0], NULL, argv[1], 0);\n+\t\t\tret = git_config_set_multivar(argv[0], NULL, argv[1], 0);\n \t\telse\n-\t\t\treturn git_config_set(argv[0], NULL);\n+\t\t\tret = git_config_set(argv[0], NULL);\n \t}\n \telse if (actions & ACTION_UNSET_ALL) {\n \t\tcheck_argc(argc, 1, 2);\n-\t\treturn git_config_set_multivar(argv[0], NULL, argv[1], 1);\n+\t\tret = git_config_set_multivar(argv[0], NULL, argv[1], 1);\n \t}\n \telse if (actions & ACTION_RENAME_SECTION) {\n-\t\tint ret;\n \t\tcheck_argc(argc, 2, 2);\n \t\tret = git_config_rename_section(argv[0], argv[1]);\n-\t\tif (ret < 0)\n-\t\t\treturn ret;\n \t\tif (ret == 0)\n \t\t\tdie(\"No such section!\");\n+\t\tif (ret > 0)\n+\t\t\tret = 0;\n \t}\n \telse if (actions & ACTION_REMOVE_SECTION) {\n-\t\tint ret;\n \t\tcheck_argc(argc, 1, 1);\n \t\tret = git_config_rename_section(argv[0], NULL);\n-\t\tif (ret < 0)\n-\t\t\treturn ret;\n \t\tif (ret == 0)\n \t\t\tdie(\"No such section!\");\n+\t\tif (ret > 0)\n+\t\t\tret = 0;\n \t}\n \telse if (get_color_slot) {\n \t\tget_color(argv[0]);\n@@ -440,8 +439,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\t\tstdout_is_tty = git_config_bool(\"command line\", argv[0]);\n \t\telse if (argc == 0)\n \t\t\tstdout_is_tty = isatty(1);\n-\t\treturn get_colorbool(argc != 1);\n+\t\tret = get_colorbool(argc != 1);\n \t}\n \n-\treturn 0;\n+\treturn !!ret;\n }\n-- \n1.6.1.3\n\n"},{"id":"104769","messageId":"94a0d4530902150443t38d9253bi85ec42f3afbf0a1d@mail.gmail.com","threadId":"17798","inReplyTo":"alpine.DEB.1.00.0902151323100.10279@pacific.mpi-cbg.de","subject":"Re: [PATCH 4/8] config: Improve variable 'type' handling.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T12:43:15Z","receivedAt":"2009-02-15T12:43:15Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Feb 15, 2009 at 2:24 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Sun, 15 Feb 2009, Felipe Contreras wrote:\n>\n>> +     switch (types) {\n>> +     case TYPE_BOOL: type = T_BOOL; break;\n>> +     case TYPE_INT: type = T_INT; break;\n>> +     case TYPE_BOOL_OR_INT: type = T_BOOL_OR_INT; break;\n>> +     default: break;\n>> +     }\n>\n> Would it not be nicer to get rid of the variable named \"type\" and use\n> \"types == TYPE_BOOL\" and similar statements instead?\n\nI'm not too sure about that. If you read the code you might think you\ncould actually have multiple types, but the same can be said about\nactions.\n\nAnyway, attached is a patch with that change.\n\n-- \nFelipe Contreras\n\n\nFrom a2ca08ace97e070d10496eee3e84c8ba2f052b50 Mon Sep 17 00:00:00 2001\nFrom: Felipe Contreras <felipe.contreras@gmail.com>\nDate: Sun, 15 Feb 2009 10:38:01 +0200\nSubject: [PATCH 4/8] config: Improve variable 'type' handling.\n\nSo now only either --bool, --int, or --bool-or-int can be used, but not\nany combination of them.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |   32 ++++++++++++++++++++------------\n 1 files changed, 20 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 084222a..30de93e 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -19,11 +19,10 @@ static int seen;\n static char delim = '=';\n static char key_delim = ' ';\n static char term = '\\n';\n-static enum { T_RAW, T_INT, T_BOOL, T_BOOL_OR_INT } type = T_RAW;\n \n static int use_global_config, use_system_config;\n static const char *given_config_file;\n-static int actions;\n+static int actions, types;\n static const char *get_color_slot, *get_colorbool_slot;\n static int end_null;\n \n@@ -39,6 +38,10 @@ static int end_null;\n #define ACTION_LIST (1<<9)\n #define ACTION_EDIT (1<<10)\n \n+#define TYPE_BOOL (1<<0)\n+#define TYPE_INT (1<<1)\n+#define TYPE_BOOL_OR_INT (1<<2)\n+\n static struct option builtin_config_options[] = {\n \tOPT_GROUP(\"Config file location\"),\n \tOPT_BOOLEAN(0, \"global\", &use_global_config, \"use global config file\"),\n@@ -57,9 +60,9 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT('l', \"list\", &actions, \"list all\", ACTION_LIST),\n \tOPT_BIT('e', \"edit\", &actions, \"opens an editor\", ACTION_EDIT),\n \tOPT_GROUP(\"Type\"),\n-\tOPT_SET_INT(0, \"bool\", &type, \"value is \\\"true\\\" or \\\"false\\\"\", T_BOOL),\n-\tOPT_SET_INT(0, \"int\", &type, \"value is decimal number\", T_INT),\n-\tOPT_SET_INT(0, \"bool-or-int\", &type, NULL, T_BOOL_OR_INT),\n+\tOPT_BIT(0, \"bool\", &types, \"value is \\\"true\\\" or \\\"false\\\"\", TYPE_BOOL),\n+\tOPT_BIT(0, \"int\", &types, \"value is decimal number\", TYPE_INT),\n+\tOPT_BIT(0, \"bool-or-int\", &types, NULL, TYPE_BOOL_OR_INT),\n \tOPT_STRING(0, \"get-color\", &get_color_slot, \"slot\", \"find the color configured: [default]\"),\n \tOPT_STRING(0, \"get-colorbool\", &get_colorbool_slot, \"slot\", \"find the color setting: [stdout-is-tty]\"),\n \tOPT_GROUP(\"Other\"),\n@@ -105,11 +108,11 @@ static int show_config(const char* key_, const char* value_, void *cb)\n \t}\n \tif (seen && !do_all)\n \t\tdup_error = 1;\n-\tif (type == T_INT)\n+\tif (types & TYPE_INT)\n \t\tsprintf(value, \"%d\", git_config_int(key_, value_?value_:\"\"));\n-\telse if (type == T_BOOL)\n+\telse if (types & TYPE_BOOL)\n \t\tvptr = git_config_bool(key_, value_) ? \"true\" : \"false\";\n-\telse if (type == T_BOOL_OR_INT) {\n+\telse if (types & TYPE_BOOL_OR_INT) {\n \t\tint is_bool, v;\n \t\tv = git_config_bool_or_int(key_, value_, &is_bool);\n \t\tif (is_bool)\n@@ -208,18 +211,18 @@ static char *normalize_value(const char *key, const char *value)\n \tif (!value)\n \t\treturn NULL;\n \n-\tif (type == T_RAW)\n+\tif (types == 0)\n \t\tnormalized = xstrdup(value);\n \telse {\n \t\tnormalized = xmalloc(64);\n-\t\tif (type == T_INT) {\n+\t\tif (types & TYPE_INT) {\n \t\t\tint v = git_config_int(key, value);\n \t\t\tsprintf(normalized, \"%d\", v);\n \t\t}\n-\t\telse if (type == T_BOOL)\n+\t\telse if (types & TYPE_BOOL)\n \t\t\tsprintf(normalized, \"%s\",\n \t\t\t\tgit_config_bool(key, value) ? \"true\" : \"false\");\n-\t\telse if (type == T_BOOL_OR_INT) {\n+\t\telse if (types & TYPE_BOOL_OR_INT) {\n \t\t\tint is_bool, v;\n \t\t\tv = git_config_bool_or_int(key, value, &is_bool);\n \t\t\tif (!is_bool)\n@@ -336,6 +339,11 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\tkey_delim = '\\n';\n \t}\n \n+\tif (HAS_MULTI_BITS(types)) {\n+\t\terror(\"only one type at a time.\");\n+\t\tusage_with_options(builtin_config_usage, builtin_config_options);\n+\t}\n+\n \tif (HAS_MULTI_BITS(actions)) {\n \t\terror(\"only one action at a time.\");\n \t\tusage_with_options(builtin_config_usage, builtin_config_options);\n-- \n1.6.1.3\n\n"},{"id":"104770","messageId":"94a0d4530902150444t6e4dcd3btda79aaa0efebfe62@mail.gmail.com","threadId":"17798","inReplyTo":"alpine.DEB.1.00.0902151324530.10279@pacific.mpi-cbg.de","subject":"Re: [PATCH 5/8] config: Disallow multiple config file locations.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T12:44:29Z","receivedAt":"2009-02-15T12:44:29Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Feb 15, 2009 at 2:26 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Sun, 15 Feb 2009, Felipe Contreras wrote:\n>\n>> Either --global, --system, or --file should be used, but not any\n>> combination.\n>>\n>> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n>> ---\n>>  builtin-config.c |   10 ++++++++++\n>>  1 files changed, 10 insertions(+), 0 deletions(-)\n>>\n>> diff --git a/builtin-config.c b/builtin-config.c\n>> index 83f8b74..e744ad8 100644\n>> --- a/builtin-config.c\n>> +++ b/builtin-config.c\n>> @@ -314,6 +314,16 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n>>\n>>       argc = parse_options(argc, argv, builtin_config_options, builtin_config_usage, 0);\n>>\n>> +     {\n>> +             int config_file_count = use_global_config + use_system_config;\n>> +             if (given_config_file)\n>> +                     config_file_count++;\n>> +             if (config_file_count > 1) {\n>> +                     error(\"only one config file at a time.\");\n>> +                     usage_with_options(builtin_config_usage, builtin_config_options);\n>> +             }\n>> +     }\n>\n> Hmm.  Is this a convoluted way to write\n>\n>        if (use_global_config + use_system_config + !!given_config_file > 1)\n>\n> or am I misunderstanding anything?\n\nAh, much better. (the !!foo trick is new to me)\n\n-- \nFelipe Contreras\n\n\nFrom 1ef7e251a2ab24f213af3022dd0a98785c8127b7 Mon Sep 17 00:00:00 2001\nFrom: Felipe Contreras <felipe.contreras@gmail.com>\nDate: Sun, 15 Feb 2009 10:46:03 +0200\nSubject: [PATCH 5/8] config: Disallow multiple config file locations.\n\nEither --global, --system, or --file should be used, but not any\ncombination.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |    5 +++++\n 1 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 30de93e..cdd8a12 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -313,6 +313,11 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \n \targc = parse_options(argc, argv, builtin_config_options, builtin_config_usage, 0);\n \n+\tif (use_global_config + use_system_config + !!given_config_file > 1) {\n+\t\terror(\"only one config file at a time.\");\n+\t\tusage_with_options(builtin_config_usage, builtin_config_options);\n+\t}\n+\n \tif (use_global_config) {\n \t\tchar *home = getenv(\"HOME\");\n \t\tif (home) {\n-- \n1.6.1.3\n\n"},{"id":"104773","messageId":"20090215133012.GA13801@annwn","threadId":"17798","inReplyTo":"94a0d4530902150439peac228ckec79f8c692b84e4e@mail.gmail.com","subject":"Re: [PATCH 7/8] config: Don't return negative exit codes.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T13:30:12Z","receivedAt":"2009-02-15T13:30:12Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Feb 15, 2009 at 02:39:47PM +0200, Felipe Contreras wrote:\n> On Sun, Feb 15, 2009 at 2:22 PM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> > Hi,\n> >\n> > On Sun, 15 Feb 2009, Felipe Contreras wrote:\n> >\n> >\n> >>       else if (actions & ACTION_RENAME_SECTION) {\n> >> -             int ret;\n> >>               check_argc(argc, 2, 2);\n> >>               ret = git_config_rename_section(argv[0], argv[1]);\n> >> -             if (ret < 0)\n> >> -                     return ret;\n> >>               if (ret == 0)\n> >>                       die(\"No such section!\");\n> >>       }\n> >\n> > You need an \"if (ret > 0) ret = 0;\" to avoid regressions.\n> >\n> >>       else if (actions & ACTION_REMOVE_SECTION) {\n> >> -             int ret;\n> >>               check_argc(argc, 1, 1);\n> >>               ret = git_config_rename_section(argv[0], NULL);\n> >> -             if (ret < 0)\n> >> -                     return ret;\n> >>               if (ret == 0)\n> >>                       die(\"No such section!\");\n> >>       }\n> >\n> > Likewise.\n> \n> True. Fixed in the attached patch.\n\nI'm inlining the patch as Johannes requested:\n\n---\n builtin-config.c |   31 +++++++++++++++----------------\n 1 files changed, 15 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 5891a4e..0606ada 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -307,6 +307,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n {\n \tint nongit;\n \tchar* value;\n+\tint ret = 0;\n \tconst char *prefix = setup_git_directory_gently(&nongit);\n \n \tconfig_exclusive_filename = getenv(CONFIG_ENVIRONMENT);\n@@ -380,57 +381,55 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \telse if (actions & ACTION_ADD) {\n \t\tcheck_argc(argc, 2, 2);\n \t\tvalue = normalize_value(argv[0], argv[1]);\n-\t\treturn git_config_set_multivar(argv[0], value, \"^$\", 0);\n+\t\tret = git_config_set_multivar(argv[0], value, \"^$\", 0);\n \t}\n \telse if (actions & ACTION_REPLACE_ALL) {\n \t\tcheck_argc(argc, 2, 3);\n \t\tvalue = normalize_value(argv[0], argv[1]);\n-\t\treturn git_config_set_multivar(argv[0], value, argv[2], 1);\n+\t\tret = git_config_set_multivar(argv[0], value, argv[2], 1);\n \t}\n \telse if (actions & ACTION_GET) {\n \t\tcheck_argc(argc, 1, 2);\n-\t\treturn get_value(argv[0], argv[1]);\n+\t\tret = get_value(argv[0], argv[1]);\n \t}\n \telse if (actions & ACTION_GET_ALL) {\n \t\tdo_all = 1;\n \t\tcheck_argc(argc, 1, 2);\n-\t\treturn get_value(argv[0], argv[1]);\n+\t\tret = get_value(argv[0], argv[1]);\n \t}\n \telse if (actions & ACTION_GET_REGEXP) {\n \t\tshow_keys = 1;\n \t\tuse_key_regexp = 1;\n \t\tdo_all = 1;\n \t\tcheck_argc(argc, 1, 2);\n-\t\treturn get_value(argv[0], argv[1]);\n+\t\tret = get_value(argv[0], argv[1]);\n \t}\n \telse if (actions & ACTION_UNSET) {\n \t\tcheck_argc(argc, 1, 2);\n \t\tif (argc == 2)\n-\t\t\treturn git_config_set_multivar(argv[0], NULL, argv[1], 0);\n+\t\t\tret = git_config_set_multivar(argv[0], NULL, argv[1], 0);\n \t\telse\n-\t\t\treturn git_config_set(argv[0], NULL);\n+\t\t\tret = git_config_set(argv[0], NULL);\n \t}\n \telse if (actions & ACTION_UNSET_ALL) {\n \t\tcheck_argc(argc, 1, 2);\n-\t\treturn git_config_set_multivar(argv[0], NULL, argv[1], 1);\n+\t\tret = git_config_set_multivar(argv[0], NULL, argv[1], 1);\n \t}\n \telse if (actions & ACTION_RENAME_SECTION) {\n-\t\tint ret;\n \t\tcheck_argc(argc, 2, 2);\n \t\tret = git_config_rename_section(argv[0], argv[1]);\n-\t\tif (ret < 0)\n-\t\t\treturn ret;\n \t\tif (ret == 0)\n \t\t\tdie(\"No such section!\");\n+\t\tif (ret > 0)\n+\t\t\tret = 0;\n \t}\n \telse if (actions & ACTION_REMOVE_SECTION) {\n-\t\tint ret;\n \t\tcheck_argc(argc, 1, 1);\n \t\tret = git_config_rename_section(argv[0], NULL);\n-\t\tif (ret < 0)\n-\t\t\treturn ret;\n \t\tif (ret == 0)\n \t\t\tdie(\"No such section!\");\n+\t\tif (ret > 0)\n+\t\t\tret = 0;\n \t}\n \telse if (get_color_slot) {\n \t\tget_color(argv[0]);\n@@ -440,8 +439,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\t\tstdout_is_tty = git_config_bool(\"command line\", argv[0]);\n \t\telse if (argc == 0)\n \t\t\tstdout_is_tty = isatty(1);\n-\t\treturn get_colorbool(argc != 1);\n+\t\tret = get_colorbool(argc != 1);\n \t}\n \n-\treturn 0;\n+\treturn !!ret;\n }\n-- \n1.6.1.3\n\n-- \nFelipe Contreras\n"},{"id":"104774","messageId":"20090215133449.GA13810@annwn","threadId":"17798","inReplyTo":"94a0d4530902150443t38d9253bi85ec42f3afbf0a1d@mail.gmail.com","subject":"Re: [PATCH 4/8] config: Improve variable 'type' handling.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T13:34:49Z","receivedAt":"2009-02-15T13:34:49Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Feb 15, 2009 at 02:43:15PM +0200, Felipe Contreras wrote:\n> On Sun, Feb 15, 2009 at 2:24 PM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> > Hi,\n> >\n> > On Sun, 15 Feb 2009, Felipe Contreras wrote:\n> >\n> >> +     switch (types) {\n> >> +     case TYPE_BOOL: type = T_BOOL; break;\n> >> +     case TYPE_INT: type = T_INT; break;\n> >> +     case TYPE_BOOL_OR_INT: type = T_BOOL_OR_INT; break;\n> >> +     default: break;\n> >> +     }\n> >\n> > Would it not be nicer to get rid of the variable named \"type\" and use\n> > \"types == TYPE_BOOL\" and similar statements instead?\n> \n> I'm not too sure about that. If you read the code you might think you\n> could actually have multiple types, but the same can be said about\n> actions.\n> \n> Anyway, attached is a patch with that change.\n\nSorry, again, but now inlined:\n\n---\n builtin-config.c |   32 ++++++++++++++++++++------------\n 1 files changed, 20 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 084222a..30de93e 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -19,11 +19,10 @@ static int seen;\n static char delim = '=';\n static char key_delim = ' ';\n static char term = '\\n';\n-static enum { T_RAW, T_INT, T_BOOL, T_BOOL_OR_INT } type = T_RAW;\n \n static int use_global_config, use_system_config;\n static const char *given_config_file;\n-static int actions;\n+static int actions, types;\n static const char *get_color_slot, *get_colorbool_slot;\n static int end_null;\n \n@@ -39,6 +38,10 @@ static int end_null;\n #define ACTION_LIST (1<<9)\n #define ACTION_EDIT (1<<10)\n \n+#define TYPE_BOOL (1<<0)\n+#define TYPE_INT (1<<1)\n+#define TYPE_BOOL_OR_INT (1<<2)\n+\n static struct option builtin_config_options[] = {\n \tOPT_GROUP(\"Config file location\"),\n \tOPT_BOOLEAN(0, \"global\", &use_global_config, \"use global config file\"),\n@@ -57,9 +60,9 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT('l', \"list\", &actions, \"list all\", ACTION_LIST),\n \tOPT_BIT('e', \"edit\", &actions, \"opens an editor\", ACTION_EDIT),\n \tOPT_GROUP(\"Type\"),\n-\tOPT_SET_INT(0, \"bool\", &type, \"value is \\\"true\\\" or \\\"false\\\"\", T_BOOL),\n-\tOPT_SET_INT(0, \"int\", &type, \"value is decimal number\", T_INT),\n-\tOPT_SET_INT(0, \"bool-or-int\", &type, NULL, T_BOOL_OR_INT),\n+\tOPT_BIT(0, \"bool\", &types, \"value is \\\"true\\\" or \\\"false\\\"\", TYPE_BOOL),\n+\tOPT_BIT(0, \"int\", &types, \"value is decimal number\", TYPE_INT),\n+\tOPT_BIT(0, \"bool-or-int\", &types, NULL, TYPE_BOOL_OR_INT),\n \tOPT_STRING(0, \"get-color\", &get_color_slot, \"slot\", \"find the color configured: [default]\"),\n \tOPT_STRING(0, \"get-colorbool\", &get_colorbool_slot, \"slot\", \"find the color setting: [stdout-is-tty]\"),\n \tOPT_GROUP(\"Other\"),\n@@ -105,11 +108,11 @@ static int show_config(const char* key_, const char* value_, void *cb)\n \t}\n \tif (seen && !do_all)\n \t\tdup_error = 1;\n-\tif (type == T_INT)\n+\tif (types & TYPE_INT)\n \t\tsprintf(value, \"%d\", git_config_int(key_, value_?value_:\"\"));\n-\telse if (type == T_BOOL)\n+\telse if (types & TYPE_BOOL)\n \t\tvptr = git_config_bool(key_, value_) ? \"true\" : \"false\";\n-\telse if (type == T_BOOL_OR_INT) {\n+\telse if (types & TYPE_BOOL_OR_INT) {\n \t\tint is_bool, v;\n \t\tv = git_config_bool_or_int(key_, value_, &is_bool);\n \t\tif (is_bool)\n@@ -208,18 +211,18 @@ static char *normalize_value(const char *key, const char *value)\n \tif (!value)\n \t\treturn NULL;\n \n-\tif (type == T_RAW)\n+\tif (types == 0)\n \t\tnormalized = xstrdup(value);\n \telse {\n \t\tnormalized = xmalloc(64);\n-\t\tif (type == T_INT) {\n+\t\tif (types & TYPE_INT) {\n \t\t\tint v = git_config_int(key, value);\n \t\t\tsprintf(normalized, \"%d\", v);\n \t\t}\n-\t\telse if (type == T_BOOL)\n+\t\telse if (types & TYPE_BOOL)\n \t\t\tsprintf(normalized, \"%s\",\n \t\t\t\tgit_config_bool(key, value) ? \"true\" : \"false\");\n-\t\telse if (type == T_BOOL_OR_INT) {\n+\t\telse if (types & TYPE_BOOL_OR_INT) {\n \t\t\tint is_bool, v;\n \t\t\tv = git_config_bool_or_int(key, value, &is_bool);\n \t\t\tif (!is_bool)\n@@ -336,6 +339,11 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\tkey_delim = '\\n';\n \t}\n \n+\tif (HAS_MULTI_BITS(types)) {\n+\t\terror(\"only one type at a time.\");\n+\t\tusage_with_options(builtin_config_usage, builtin_config_options);\n+\t}\n+\n \tif (HAS_MULTI_BITS(actions)) {\n \t\terror(\"only one action at a time.\");\n \t\tusage_with_options(builtin_config_usage, builtin_config_options);\n-- \n1.6.1.3\n\n-- \nFelipe Contreras\n"},{"id":"104775","messageId":"20090215133557.GB13810@annwn","threadId":"17798","inReplyTo":"94a0d4530902150444t6e4dcd3btda79aaa0efebfe62@mail.gmail.com","subject":"Re: [PATCH 5/8] config: Disallow multiple config file locations.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-15T13:35:57Z","receivedAt":"2009-02-15T13:35:57Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Feb 15, 2009 at 02:44:29PM +0200, Felipe Contreras wrote:\n> On Sun, Feb 15, 2009 at 2:26 PM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> > Hi,\n> >\n> > On Sun, 15 Feb 2009, Felipe Contreras wrote:\n> >\n> >> Either --global, --system, or --file should be used, but not any\n> >> combination.\n> >>\n> >> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n> >> ---\n> >>  builtin-config.c |   10 ++++++++++\n> >>  1 files changed, 10 insertions(+), 0 deletions(-)\n> >>\n> >> diff --git a/builtin-config.c b/builtin-config.c\n> >> index 83f8b74..e744ad8 100644\n> >> --- a/builtin-config.c\n> >> +++ b/builtin-config.c\n> >> @@ -314,6 +314,16 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n> >>\n> >>       argc = parse_options(argc, argv, builtin_config_options, builtin_config_usage, 0);\n> >>\n> >> +     {\n> >> +             int config_file_count = use_global_config + use_system_config;\n> >> +             if (given_config_file)\n> >> +                     config_file_count++;\n> >> +             if (config_file_count > 1) {\n> >> +                     error(\"only one config file at a time.\");\n> >> +                     usage_with_options(builtin_config_usage, builtin_config_options);\n> >> +             }\n> >> +     }\n> >\n> > Hmm.  Is this a convoluted way to write\n> >\n> >        if (use_global_config + use_system_config + !!given_config_file > 1)\n> >\n> > or am I misunderstanding anything?\n> \n> Ah, much better. (the !!foo trick is new to me)\n\nNow inlined:\n\n---\n builtin-config.c |    5 +++++\n 1 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 30de93e..cdd8a12 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -313,6 +313,11 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \n \targc = parse_options(argc, argv, builtin_config_options, builtin_config_usage, 0);\n \n+\tif (use_global_config + use_system_config + !!given_config_file > 1) {\n+\t\terror(\"only one config file at a time.\");\n+\t\tusage_with_options(builtin_config_usage, builtin_config_options);\n+\t}\n+\n \tif (use_global_config) {\n \t\tchar *home = getenv(\"HOME\");\n \t\tif (home) {\n-- \n1.6.1.3\n\n\n-- \nFelipe Contreras\n"},{"id":"104820","messageId":"20090215201505.GC26779@coredump.intra.peff.net","threadId":"17798","inReplyTo":"1234688460-9248-2-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH 2/8] config: Cleanup config file handling.","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-02-15T20:15:06Z","receivedAt":"2009-02-15T20:15:06Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Feb 15, 2009 at 11:00:54AM +0200, Felipe Contreras wrote:\n\n> As suggested by Johannes Schindelin.\n\nThank you for splitting this patch up. I have to admit I was too scared\nto read the original after seeing the diffstat.\n\nBut part of the nice thing about splitting up is that you can write\nmeaningful commit messages for each individual change. Reading this\ncommit message, I don't know what to expect.\n\nYour 1/8, though short, tells me what to expect: a trivial rename. But\n\"clean up config file handling\" is quite ambiguous. And after reading\nthe patch, I am left wondering why the filename and errno are not useful\nas part of the die() message. I think even a single sentence would\nprobably make it clear.\n\nAnd yes, I know I can look elsewhere in the thread to find the\ndiscussion between you and Dscho. But think of the poor \"git log\" user\nsix months from now.\n\n-Peff\n"},{"id":"104872","messageId":"7vljs7gp15.fsf@gitster.siamese.dyndns.org","threadId":"17798","inReplyTo":"1234688460-9248-2-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH 2/8] config: Cleanup config file handling.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-16T01:15:50Z","receivedAt":"2009-02-16T01:15:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> As suggested by Johannes Schindelin.\n>\n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n\nDscho won't be the only person who will read \"git log\" output.  What was\nsuggested, what convinced you it is a good idea, what goodness would this\npatch add if I take it?\n\n> -\t\t\tif (git_config(show_all_config, NULL) < 0 &&\n> -\t\t\t\t\tfile && errno)\n> -\t\t\t\tdie(\"unable to read config file %s: %s\", file,\n> -\t\t\t\t    strerror(errno));\n> +\t\t\tif (git_config(show_all_config, NULL) < 0)\n> +\t\t\t\tdie(\"error processing config file(s)\");\n>  \t\t\treturn 0;\n\nThis is the only change with substance in this patch.  What difference\ndoes it make?  Earlier we failed to say \"die\" with message in some\nsituations, and now we die when git_config() signals any error.\n\nWhat are the situations in whoich the command misbehaved?  The commit log\nmessage is where you are expected to explain that.\n"}]}