{"thread":{"id":"17930","subject":"[PATCH A v4 3/5] git_config(): not having a per-repo config file is not an error","startedAt":"2009-02-21T00:48:52Z","lastAt":"2009-02-21T00:48:57Z","messageCount":6,"participants":["Felipe Contreras"],"isPatch":true,"patchVersion":4,"patchTotal":5},"messages":[{"id":"105682","messageId":"1235177337-2532-1-git-send-email-felipe.contreras@gmail.com","threadId":"17930","inReplyTo":null,"subject":"[PATCH A v4 0/5] git config: cleanups","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-21T00:48:52Z","receivedAt":"2009-02-21T00:48:52Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"This patch series is the first of a two parts reorganization for more\nmaintainability and user friendliness. Nonetheless stands on its own can be\napplied without the second part.\n\nThere are essentially no functional changes.\n\nFelipe Contreras (4):\n  git config: codestyle cleanups\n  git_config(): not having a per-repo config file is not an error\n  git config: trivial rename in preparation for parseopt\n  git config: reorganize get_color*\n\nJohannes Schindelin (1):\n  git config: trivial cleanup for editor action\n\n builtin-config.c |  108 ++++++++++++++++++++---------------------------------\n config.c         |   17 ++++++--\n 2 files changed, 54 insertions(+), 71 deletions(-)\n"},{"id":"105674","messageId":"1235177337-2532-2-git-send-email-felipe.contreras@gmail.com","threadId":"17930","inReplyTo":"1235177337-2532-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH A v4 1/5] git config: codestyle cleanups","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-21T00:48:53Z","receivedAt":"2009-02-21T00:48:53Z","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":"105684","messageId":"1235177337-2532-3-git-send-email-felipe.contreras@gmail.com","threadId":"17930","inReplyTo":"1235177337-2532-2-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH A v4 2/5] git config: trivial cleanup for editor action","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-21T00:48:54Z","receivedAt":"2009-02-21T00:48:54Z","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":"105672","messageId":"1235177337-2532-4-git-send-email-felipe.contreras@gmail.com","threadId":"17930","inReplyTo":"1235177337-2532-3-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH A v4 3/5] git_config(): not having a per-repo config file is not an error","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-21T00:48:55Z","receivedAt":"2009-02-21T00:48:55Z","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":"105673","messageId":"1235177337-2532-5-git-send-email-felipe.contreras@gmail.com","threadId":"17930","inReplyTo":"1235177337-2532-4-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH A v4 4/5] git config: trivial rename in preparation for parseopt","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-21T00:48:56Z","receivedAt":"2009-02-21T00:48:56Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Essentially 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":"105675","messageId":"1235177337-2532-6-git-send-email-felipe.contreras@gmail.com","threadId":"17930","inReplyTo":"1235177337-2532-5-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH A v4 5/5] git config: reorganize get_color*","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-21T00:48:57Z","receivedAt":"2009-02-21T00:48:57Z","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"}]}