{"thread":{"id":"17856","subject":"[PATCH v3 01/10] config: Codestyle cleanups.","startedAt":"2009-02-17T13:52:47Z","lastAt":"2009-02-18T22:01:38Z","messageCount":16,"participants":["Felipe Contreras","Sverre Rabbelier","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":10},"messages":[{"id":"105135","messageId":"1234878776-13250-1-git-send-email-felipe.contreras@gmail.com","threadId":"17856","inReplyTo":null,"subject":"[PATCH v3 01/10] config: Codestyle cleanups.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-17T13:52:47Z","receivedAt":"2009-02-17T13:52:47Z","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 6937eaf..afc4393 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -27,7 +27,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@@ -74,7 +74,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@@ -284,7 +284,7 @@ static int get_colorbool(int argc, const char **argv)\n int cmd_config(int argc, const char **argv, const char *prefix)\n {\n \tint nongit;\n-\tchar* value;\n+\tchar *value;\n \tconst char *file = setup_git_directory_gently(&nongit);\n \n \tconfig_exclusive_filename = getenv(CONFIG_ENVIRONMENT);\n-- \n1.6.1.3\n"},{"id":"105142","messageId":"1234878776-13250-2-git-send-email-felipe.contreras@gmail.com","threadId":"17856","inReplyTo":"1234878776-13250-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v3 02/10] config: Cleanup editor action.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-17T13:52:48Z","receivedAt":"2009-02-17T13:52:48Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |    9 +++------\n 1 files changed, 3 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex afc4393..d52a057 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -363,15 +363,12 @@ int cmd_config(int argc, const char **argv, const char *prefix)\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\tlaunch_editor(config_exclusive_filename ?\n+\t\t\t\t      config_exclusive_filename : git_path(\"config\"),\n+\t\t\t\t      NULL, NULL);\n \t\t\treturn 0;\n \t\t} else\n \t\t\tbreak;\n-- \n1.6.1.3\n"},{"id":"105136","messageId":"1234878776-13250-3-git-send-email-felipe.contreras@gmail.com","threadId":"17856","inReplyTo":"1234878776-13250-2-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v3 03/10] config: Make git_config() more flexible.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-17T13:52:49Z","receivedAt":"2009-02-17T13:52:49Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Currently git_config() returns an error if there is no repo config file\navailable (cwd is not a git repo); it will correctly parse the system\nand global config files, but still return an error.\n\nIt doesn't affect anything else since almost nobody is checking for the\nreturn code (with the exception of 'git remote update').\n\nA reorganization in 'git config' would benefit from being able to\nproperly detect errors in git_config without the noise generated when\ncwd is not a git repo.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n config.c |   17 +++++++++++++----\n 1 files changed, 13 insertions(+), 4 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 7dc1b0f..68ce519 100644\n--- a/config.c\n+++ b/config.c\n@@ -649,28 +649,37 @@ int git_config_global(void)\n \n int git_config(config_fn_t fn, void *data)\n {\n-\tint ret = 0;\n+\tint ret = 0, found = 0;\n \tchar *repo_config = NULL;\n \tconst char *home = NULL;\n \n \t/* Setting $GIT_CONFIG makes git read _only_ the given config file. */\n \tif (config_exclusive_filename)\n \t\treturn git_config_from_file(fn, config_exclusive_filename, data);\n-\tif (git_config_system() && !access(git_etc_gitconfig(), R_OK))\n+\tif (git_config_system() && !access(git_etc_gitconfig(), R_OK)) {\n \t\tret += git_config_from_file(fn, git_etc_gitconfig(),\n \t\t\t\t\t    data);\n+\t\tfound += 1;\n+\t}\n \n \thome = getenv(\"HOME\");\n \tif (git_config_global() && home) {\n \t\tchar *user_config = xstrdup(mkpath(\"%s/.gitconfig\", home));\n-\t\tif (!access(user_config, R_OK))\n+\t\tif (!access(user_config, R_OK)) {\n \t\t\tret += git_config_from_file(fn, user_config, data);\n+\t\t\tfound += 1;\n+\t\t}\n \t\tfree(user_config);\n \t}\n \n \trepo_config = git_pathdup(\"config\");\n-\tret += git_config_from_file(fn, repo_config, data);\n+\tif (!access(repo_config, R_OK)) {\n+\t\tret += git_config_from_file(fn, repo_config, data);\n+\t\tfound += 1;\n+\t}\n \tfree(repo_config);\n+\tif (found == 0)\n+\t\treturn -1;\n \treturn ret;\n }\n \n-- \n1.6.1.3\n"},{"id":"105141","messageId":"1234878776-13250-4-git-send-email-felipe.contreras@gmail.com","threadId":"17856","inReplyTo":"1234878776-13250-3-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v3 04/10] config: Trivial rename in preparation for parseopt.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-17T13:52:50Z","receivedAt":"2009-02-17T13:52:50Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Essensially this replaces 'file' with 'prefix' in the cases where the\nvariable is used as a prefix, which is consistent with other git\ncommands.\n\nWhen using the --list option general errors where not properly reported,\nonly errors related with the 'file'. Now they are reported, and 'file'\nis irrelevant.\n\nThat reduces the rest of 'file' usage to nothing, therefore now only\n'prefix' remains.\n\nSuggested by Johannes Schindelin.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |   32 ++++++++++++++++++--------------\n 1 files changed, 18 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex d52a057..5074c61 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@@ -281,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@@ -299,10 +300,13 @@ 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\tif (config_exclusive_filename)\n+\t\t\t\t\tdie(\"unable to read config file %s: %s\",\n+\t\t\t\t\t    config_exclusive_filename, strerror(errno));\n+\t\t\t\telse\n+\t\t\t\t\tdie(\"error processing config file(s)\");\n+\t\t\t}\n \t\t\treturn 0;\n \t\t}\n \t\telse if (!strcmp(argv[1], \"--global\")) {\n@@ -319,12 +323,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":"105140","messageId":"1234878776-13250-5-git-send-email-felipe.contreras@gmail.com","threadId":"17856","inReplyTo":"1234878776-13250-4-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v3 05/10] config: Reorganize get_color*.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-17T13:52:51Z","receivedAt":"2009-02-17T13:52:51Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"In preparation for parseopt.\n\nAlso remove some unecessary comments since the usage is described in the\ndocumentation.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |   63 +++++++++++++++--------------------------------------\n 1 files changed, 18 insertions(+), 45 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 5074c61..0836880 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -180,7 +180,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 +191,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 +201,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 +224,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 +237,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@@ -363,9 +325,20 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\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\tif (argc > 4 || argc < 3)\n+\t\t\t\tusage(git_config_set_usage);\n+\t\t\tget_color_slot = argv[2];\n+\t\t\tget_color(argv[3]);\n+\t\t\treturn 0;\n \t\t} else if (!strcmp(argv[1], \"--get-colorbool\")) {\n-\t\t\treturn get_colorbool(argc-2, argv+2);\n+\t\t\tif (argc == 4)\n+\t\t\t\tstdout_is_tty = git_config_bool(\"command line\", argv[3]);\n+\t\t\telse if (argc == 3)\n+\t\t\t\tstdout_is_tty = isatty(1);\n+\t\t\telse\n+\t\t\t\tusage(git_config_set_usage);\n+\t\t\tget_colorbool_slot = argv[2];\n+\t\t\treturn get_colorbool(argc != 3);\n \t\t} else if (!strcmp(argv[1], \"--edit\") || !strcmp(argv[1], \"-e\")) {\n \t\t\tif (argc != 2)\n \t\t\t\tusage(git_config_set_usage);\n-- \n1.6.1.3\n"},{"id":"105138","messageId":"1234878776-13250-6-git-send-email-felipe.contreras@gmail.com","threadId":"17856","inReplyTo":"1234878776-13250-5-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v3 06/10] config: Use parseopt.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-17T13:52:52Z","receivedAt":"2009-02-17T13:52:52Z","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 |  342 ++++++++++++++++++++++++++++++------------------------\n 1 files changed, 188 insertions(+), 154 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 0836880..45b4a9f 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,61 @@ 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+#define ACTION_SET (1<<11)\n+#define ACTION_SET_ALL (1<<12)\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_ALL),\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_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(\"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_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@@ -252,162 +310,138 @@ 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\tif (config_exclusive_filename)\n-\t\t\t\t\tdie(\"unable to read config file %s: %s\",\n-\t\t\t\t\t    config_exclusive_filename, strerror(errno));\n-\t\t\t\telse\n-\t\t\t\t\tdie(\"error processing config file(s)\");\n-\t\t\t}\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\tif (argc > 4 || argc < 3)\n-\t\t\t\tusage(git_config_set_usage);\n-\t\t\tget_color_slot = argv[2];\n-\t\t\tget_color(argv[3]);\n-\t\t\treturn 0;\n-\t\t} else if (!strcmp(argv[1], \"--get-colorbool\")) {\n-\t\t\tif (argc == 4)\n-\t\t\t\tstdout_is_tty = git_config_bool(\"command line\", argv[3]);\n-\t\t\telse if (argc == 3)\n-\t\t\t\tstdout_is_tty = isatty(1);\n-\t\t\telse\n-\t\t\t\tusage(git_config_set_usage);\n-\t\t\tget_colorbool_slot = argv[2];\n-\t\t\treturn get_colorbool(argc != 3);\n-\t\t} else if (!strcmp(argv[1], \"--edit\") || !strcmp(argv[1], \"-e\")) {\n-\t\t\tif (argc != 2)\n-\t\t\t\tusage(git_config_set_usage);\n-\t\t\tgit_config(git_default_config, NULL);\n-\t\t\tlaunch_editor(config_exclusive_filename ?\n-\t\t\t\t      config_exclusive_filename : git_path(\"config\"),\n-\t\t\t\t      NULL, NULL);\n-\t\t\treturn 0;\n-\t\t} else\n-\t\t\tbreak;\n-\t\targc--;\n-\t\targv++;\n-\t}\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+\targc = parse_options(argc, argv, builtin_config_options, builtin_config_usage,\n+\t\t\t     PARSE_OPT_STOP_AT_NON_OPTION);\n+\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(argv[1], value);\n+\t\t\tdie(\"$HOME not set\");\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-\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}\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_SET; break;\n+\t\tcase 3: actions = ACTION_SET_ALL; break;\n+\t\tdefault:\n+\t\t\tusage_with_options(builtin_config_usage, builtin_config_options);\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+\n+\tif (actions == ACTION_LIST) {\n+\t\tif (git_config(show_all_config, NULL) < 0) {\n+\t\t\tif (config_exclusive_filename)\n+\t\t\t\tdie(\"unable to read config file %s: %s\",\n+\t\t\t\t    config_exclusive_filename, strerror(errno));\n+\t\t\telse\n+\t\t\t\tdie(\"error processing config file(s)\");\n \t\t}\n-\tcase 1:\n-\tdefault:\n-\t\tusage(git_config_set_usage);\n \t}\n+\telse if (actions == ACTION_EDIT) {\n+\t\tgit_config(git_default_config, NULL);\n+\t\tlaunch_editor(config_exclusive_filename ?\n+\t\t\t      config_exclusive_filename : git_path(\"config\"),\n+\t\t\t      NULL, NULL);\n+\t}\n+\telse if (actions == ACTION_SET) {\n+\t\tcheck_argc(argc, 2, 2);\n+\t\tvalue = normalize_value(argv[0], argv[1]);\n+\t\treturn git_config_set(argv[0], value);\n+\t}\n+\telse if (actions == ACTION_SET_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], 0);\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":"105143","messageId":"1234878776-13250-7-git-send-email-felipe.contreras@gmail.com","threadId":"17856","inReplyTo":"1234878776-13250-6-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v3 07/10] config: Disallow --getcolor* and other actions.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-17T13:52:53Z","receivedAt":"2009-02-17T13:52:53Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"From: Junio C Hamano <gitster@pobox.com>\n\nSo that --get and --get-colorbool are diagnosed as errors.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin-config.c |   11 +++++++++--\n 1 files changed, 9 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 45b4a9f..8ee0cd9 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -40,6 +40,8 @@ static int end_null;\n #define ACTION_EDIT (1<<10)\n #define ACTION_SET (1<<11)\n #define ACTION_SET_ALL (1<<12)\n+#define ACTION_GET_COLOR (1<<13)\n+#define ACTION_GET_COLORBOOL (1<<14)\n \n static struct option builtin_config_options[] = {\n \tOPT_GROUP(\"Config file location\"),\n@@ -339,6 +341,11 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\tkey_delim = '\\n';\n \t}\n \n+\tif (get_color_slot)\n+\t    actions |= ACTION_GET_COLOR;\n+\tif (get_colorbool_slot)\n+\t    actions |= ACTION_GET_COLORBOOL;\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@@ -432,10 +439,10 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\tif (ret == 0)\n \t\t\tdie(\"No such section!\");\n \t}\n-\telse if (get_color_slot) {\n+\telse if (actions == ACTION_GET_COLOR) {\n \t\tget_color(argv[0]);\n \t}\n-\telse if (get_colorbool_slot) {\n+\telse if (actions == ACTION_GET_COLORBOOL) {\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-- \n1.6.1.3\n"},{"id":"105145","messageId":"1234878776-13250-8-git-send-email-felipe.contreras@gmail.com","threadId":"17856","inReplyTo":"1234878776-13250-7-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v3 08/10] config: Disallow multiple config file locations.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-17T13:52:54Z","receivedAt":"2009-02-17T13:52:54Z","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 |    5 +++++\n 1 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 8ee0cd9..a674246 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -315,6 +315,11 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \targc = parse_options(argc, argv, builtin_config_options, builtin_config_usage,\n \t\t\t     PARSE_OPT_STOP_AT_NON_OPTION);\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"},{"id":"105144","messageId":"1234878776-13250-9-git-send-email-felipe.contreras@gmail.com","threadId":"17856","inReplyTo":"1234878776-13250-8-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v3 09/10] config: Disallow multiple variable types.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-17T13:52:55Z","receivedAt":"2009-02-17T13:52:55Z","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 |   32 ++++++++++++++++++++------------\n 1 files changed, 20 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex a674246..060191c 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@@ -43,6 +42,10 @@ static int end_null;\n #define ACTION_GET_COLOR (1<<13)\n #define ACTION_GET_COLORBOOL (1<<14)\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@@ -63,9 +66,9 @@ static struct option builtin_config_options[] = {\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(\"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_GROUP(\"Other\"),\n \tOPT_BOOLEAN('z', \"null\", &end_null, \"terminate values with NUL byte\"),\n \tOPT_END(),\n@@ -109,11 +112,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@@ -212,18 +215,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@@ -346,6 +349,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 (get_color_slot)\n \t    actions |= ACTION_GET_COLOR;\n \tif (get_colorbool_slot)\n-- \n1.6.1.3\n"},{"id":"105139","messageId":"1234878776-13250-10-git-send-email-felipe.contreras@gmail.com","threadId":"17856","inReplyTo":"1234878776-13250-9-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v3 10/10] config: Don't allow extra arguments for -e or -l.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-17T13:52:56Z","receivedAt":"2009-02-17T13:52:56Z","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 060191c..ec7b613 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -373,6 +373,7 @@ 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\tif (config_exclusive_filename)\n \t\t\t\tdie(\"unable to read config file %s: %s\",\n@@ -382,6 +383,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\t}\n \t}\n \telse if (actions == ACTION_EDIT) {\n+\t\tcheck_argc(argc, 0, 0);\n \t\tgit_config(git_default_config, NULL);\n \t\tlaunch_editor(config_exclusive_filename ?\n \t\t\t      config_exclusive_filename : git_path(\"config\"),\n-- \n1.6.1.3\n"},{"id":"105173","messageId":"bd6139dc0902170833r7e6672f4p831dacb2ed841b32@mail.gmail.com","threadId":"17856","inReplyTo":"1234878776-13250-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH v3 01/10] config: Codestyle cleanups.","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-02-17T16:33:01Z","receivedAt":"2009-02-17T16:33:01Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"On Tue, Feb 17, 2009 at 14:52, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n\nDid I miss 0/10 somehow? If not, it would be nice to have one if you\nsend a long patch series :). That way I can ignore v3 of the series if\nthe cover letter tells me nothing significant (to me) has changed. 1\nminutes to write for you, saves 5 minutes for all reviewers :).\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"105282","messageId":"94a0d4530902180118j4746a690q7a42ea087e23488@mail.gmail.com","threadId":"17856","inReplyTo":"bd6139dc0902170833r7e6672f4p831dacb2ed841b32@mail.gmail.com","subject":"Re: [PATCH v3 01/10] config: Codestyle cleanups.","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-18T09:18:33Z","receivedAt":"2009-02-18T09:18:33Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Tue, Feb 17, 2009 at 6:33 PM, Sverre Rabbelier <srabbelier@gmail.com> wrote:\n> On Tue, Feb 17, 2009 at 14:52, Felipe Contreras\n> <felipe.contreras@gmail.com> wrote:\n>> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n>\n> Did I miss 0/10 somehow? If not, it would be nice to have one if you\n> send a long patch series :). That way I can ignore v3 of the series if\n> the cover letter tells me nothing significant (to me) has changed. 1\n> minutes to write for you, saves 5 minutes for all reviewers :).\n\nHmm, right. I was thinking on Junio and Johanness that already know\nthe context, so they don't need an introduction, but I forgot about\nother people that might be interested in giving this a review.\n\nIn any case, this patch series is a try to re-organize the code of\n'git config' and the main change is to use parseopt for better\nmaintainability and option parsing. A few functionality changes are\nprovided, like the fact that now the arguments don't need to be in a\nspecific order: (--global -l vs -l --global), and improvements in\nerror reporting. Otherwise it should work exactly the same as before\n(except with a much better --help).\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"105332","messageId":"7v8wo3y3eo.fsf@gitster.siamese.dyndns.org","threadId":"17856","inReplyTo":"94a0d4530902180118j4746a690q7a42ea087e23488@mail.gmail.com","subject":"Re: [PATCH v3 01/10] config: Codestyle cleanups.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-18T19:02:23Z","receivedAt":"2009-02-18T19:02:23Z","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> Hmm, right. I was thinking on Junio and Johanness that already know\n> the context, so they don't need an introduction, but I forgot about\n> other people that might be interested in giving this a review.\n\nAlso please don't assume anything about what other people may remember\nfrom your earlier series, after you received \"this round is not ready to\nbe applied because of this and that\" comments.  As far as the reviewer is\nconcerned, that's the end of the story about the entire series, until you\nsend a revised one.  The reviewers are not promising to remember the fine\ndetails of the code and to help you improve the series, thinking about the\nseries all the time until its next round materializes by reviewing the\nfirst round, and it is unrealistic to expect them to.  There are a lot\nmore patches and patch writers than there are people who review them.\n\nThe reason you are encouraged to say want was changed since the previous\nseries when you are sending v(n+1) patch in each patch after three-dash\nlines is exactly because by default we expect reviewers remember nothing\nabout the previous round and jogging their memory in such a way would help\nreviewing the new round.\n"},{"id":"105343","messageId":"7viqn7v47s.fsf@gitster.siamese.dyndns.org","threadId":"17856","inReplyTo":"1234878776-13250-3-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH v3 03/10] config: Make git_config() more flexible","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-18T21:13:11Z","receivedAt":"2009-02-18T21:13:11Z","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> Currently git_config() returns an error if there is no repo config file\n> available (cwd is not a git repo); it will correctly parse the system\n> and global config files, but still return an error.\n\nCurrently it does???\n\nHere is what I get from using the command from master and next:\n\n    $ cd /var/tmp\n    $ ls -d /.git /var/.git /var/tmp/.git /var/tmp/config\n    ls: /.git: No such file or directory\n    ls: /var/.git: No such file or directory\n    ls: /var/tmp/.git: No such file or directory\n    ls: /var/tmp/config: No such file or directory\n    $ git config -l >/dev/null ; echo $?\n    0\n    $ git config alias.co; echo $?\n    checkout\n    0\n\nI have $HOME/.gitconfig (where the alias comes from) and no system wide\nconfiguration file.\n\nAlso the patch is mistitled.  Whatever you are trying to say about the\ncurrent problem which I do not seem to get, and whatever different\nbehaviour from the current one you are trying to implement (which is not\nquite clear from the above log message), it is not about making it more\nflexible.\n\nThe patch text suggests you are trying to change the function's exit\nstatus so the title would be \"git-config: report errors correctly in its\nexit status\", but it is unspecified in your commit log message what\ndefinition of \"correctly\" you are using in this patch.\n"},{"id":"105345","messageId":"94a0d4530902181330o298fce1am31d9d15145956d78@mail.gmail.com","threadId":"17856","inReplyTo":"7viqn7v47s.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH v3 03/10] config: Make git_config() more flexible","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-18T21:30:39Z","receivedAt":"2009-02-18T21:30:39Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Wed, Feb 18, 2009 at 11:13 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Felipe Contreras <felipe.contreras@gmail.com> writes:\n>\n>> Currently git_config() returns an error if there is no repo config file\n>> available (cwd is not a git repo); it will correctly parse the system\n>> and global config files, but still return an error.\n>\n> Currently it does???\n>\n> Here is what I get from using the command from master and next:\n>\n>    $ cd /var/tmp\n>    $ ls -d /.git /var/.git /var/tmp/.git /var/tmp/config\n>    ls: /.git: No such file or directory\n>    ls: /var/.git: No such file or directory\n>    ls: /var/tmp/.git: No such file or directory\n>    ls: /var/tmp/config: No such file or directory\n>    $ git config -l >/dev/null ; echo $?\n>    0\n>    $ git config alias.co; echo $?\n>    checkout\n>    0\n\nThis patch doesn't alter the behavior of 'git config', it's for\ngit_config() (the function). At this point cmd_config() will return an\nexit code of 0 even if there's an error on git_config() when no\nexclusive file is specified.\n\n> I have $HOME/.gitconfig (where the alias comes from) and no system wide\n> configuration file.\n>\n> Also the patch is mistitled.  Whatever you are trying to say about the\n> current problem which I do not seem to get, and whatever different\n> behaviour from the current one you are trying to implement (which is not\n> quite clear from the above log message), it is not about making it more\n> flexible.\n>\n> The patch text suggests you are trying to change the function's exit\n> status so the title would be \"git-config: report errors correctly in its\n> exit status\", but it is unspecified in your commit log message what\n> definition of \"correctly\" you are using in this patch.\n\nWhat I'm trying to do is \"Make git_config() don't return an error when\nthere's no repo config file if there are other config files\navailable\"... I thought there was no short way to say that =/\n\n-- \nFelipe Contreras\n"},{"id":"105350","messageId":"7vvdr7tnel.fsf@gitster.siamese.dyndns.org","threadId":"17856","inReplyTo":"94a0d4530902181330o298fce1am31d9d15145956d78@mail.gmail.com","subject":"Re: [PATCH v3 03/10] config: Make git_config() more flexible","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-18T22:01:38Z","receivedAt":"2009-02-18T22:01:38Z","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> What I'm trying to do is \"Make git_config() don't return an error when\n> there's no repo config file if there are other config files\n> available\"... I thought there was no short way to say that =/\n\ngit_config(): not having a per-repo config file is not an error\n\nPlease drop the full-stop at the end of the Subject: line, by the way.\n"}]}