{"thread":{"id":"34149","subject":"[PATCH] config: support mixed-case aliases","startedAt":"2013-06-15T16:26:28Z","lastAt":"2013-06-15T16:26:28Z","messageCount":1,"participants":["Ramkumar Ramachandra"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"220950","messageId":"1371313588-6180-1-git-send-email-artagnon@gmail.com","threadId":"34149","inReplyTo":null,"subject":"[PATCH] config: support mixed-case aliases","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-06-15T16:26:28Z","receivedAt":"2013-06-15T16:26:28Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"To support mixed-case aliases like:\n\n  bM = branch -M\n  bD = branch -D\n\nadd an argument to git_config_with_options() to block the tolower()\ncalls on key characters.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n The static variable is somewhat disturbing, but it's the most obvious\n choice to avoid refactoring config.c heavily.  What do you think?\n\n alias.c                |  2 +-\n builtin/config.c       |  8 ++++----\n cache.h                |  2 +-\n config.c               | 13 ++++++++++---\n t/t1300-repo-config.sh |  7 +++++++\n 5 files changed, 23 insertions(+), 9 deletions(-)\n\ndiff --git a/alias.c b/alias.c\nindex eb9f08b..c428592 100644\n--- a/alias.c\n+++ b/alias.c\n@@ -18,7 +18,7 @@ char *alias_lookup(const char *alias)\n {\n \talias_key = alias;\n \talias_val = NULL;\n-\tgit_config(alias_lookup_cb, NULL);\n+\tgit_config_with_options(alias_lookup_cb, NULL, NULL, 1, 1);\n \treturn alias_val;\n }\n \ndiff --git a/builtin/config.c b/builtin/config.c\nindex 19ffcaf..633b38a 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -218,7 +218,7 @@ static int get_value(const char *key_, const char *regex_)\n \t}\n \n \tgit_config_with_options(collect_config, &values,\n-\t\t\t\tgiven_config_file, respect_includes);\n+\t\t\t\tgiven_config_file, respect_includes, 0);\n \n \tret = !values.nr;\n \n@@ -302,7 +302,7 @@ static void get_color(const char *def_color)\n \tget_color_found = 0;\n \tparsed_color[0] = '\\0';\n \tgit_config_with_options(git_get_color_config, NULL,\n-\t\t\t\tgiven_config_file, respect_includes);\n+\t\t\t\tgiven_config_file, respect_includes, 0);\n \n \tif (!get_color_found && def_color)\n \t\tcolor_parse(def_color, \"command line\", parsed_color);\n@@ -330,7 +330,7 @@ static int get_colorbool(int print)\n \tget_colorbool_found = -1;\n \tget_diff_color_found = -1;\n \tgit_config_with_options(git_get_colorbool_config, NULL,\n-\t\t\t\tgiven_config_file, respect_includes);\n+\t\t\t\tgiven_config_file, respect_includes, 0);\n \n \tif (get_colorbool_found < 0) {\n \t\tif (!strcmp(get_colorbool_slot, \"color.diff\"))\n@@ -438,7 +438,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\tcheck_argc(argc, 0, 0);\n \t\tif (git_config_with_options(show_all_config, NULL,\n \t\t\t\t\t    given_config_file,\n-\t\t\t\t\t    respect_includes) < 0) {\n+\t\t\t\t\t    respect_includes, 0) < 0) {\n \t\t\tif (given_config_file)\n \t\t\t\tdie_errno(\"unable to read config file '%s'\",\n \t\t\t\t\t  given_config_file);\ndiff --git a/cache.h b/cache.h\nindex 820aa05..27d201e 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1161,7 +1161,7 @@ extern void git_config_push_parameter(const char *text);\n extern int git_config_from_parameters(config_fn_t fn, void *data);\n extern int git_config(config_fn_t fn, void *);\n extern int git_config_with_options(config_fn_t fn, void *,\n-\t\t\t\t   const char *filename, int respect_includes);\n+\t\t\t\tconst char *filename, int respect_includes, int respect_mixedcase);\n extern int git_config_early(config_fn_t fn, void *, const char *repo_config);\n extern int git_parse_ulong(const char *, unsigned long *);\n extern int git_config_int(const char *, const char *);\ndiff --git a/config.c b/config.c\nindex 7a85ebd..53ad448 100644\n--- a/config.c\n+++ b/config.c\n@@ -23,6 +23,7 @@ typedef struct config_file {\n static config_file *cf;\n \n static int zlib_compression_seen;\n+static int allow_mixedcase_keys;\n \n #define MAX_INCLUDE_DEPTH 10\n static const char include_depth_advice[] =\n@@ -270,7 +271,9 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)\n \t\t\tbreak;\n \t\tif (!iskeychar(c))\n \t\t\tbreak;\n-\t\tstrbuf_addch(name, tolower(c));\n+\t\tif (!allow_mixedcase_keys)\n+\t\t\tc = tolower(c);\n+\t\tstrbuf_addch(name, c);\n \t}\n \n \twhile (c == ' ' || c == '\\t')\n@@ -1005,7 +1008,8 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)\n }\n \n int git_config_with_options(config_fn_t fn, void *data,\n-\t\t\t    const char *filename, int respect_includes)\n+\t\t\tconst char *filename, int respect_includes,\n+\t\t\tint respect_mixedcase)\n {\n \tchar *repo_config = NULL;\n \tint ret;\n@@ -1018,6 +1022,9 @@ int git_config_with_options(config_fn_t fn, void *data,\n \t\tdata = &inc;\n \t}\n \n+\t/* For mixed-case aliases */\n+\tallow_mixedcase_keys = respect_mixedcase ? 1 : 0;\n+\n \t/*\n \t * If we have a specific filename, use it. Otherwise, follow the\n \t * regular lookup sequence.\n@@ -1034,7 +1041,7 @@ int git_config_with_options(config_fn_t fn, void *data,\n \n int git_config(config_fn_t fn, void *data)\n {\n-\treturn git_config_with_options(fn, data, NULL, 1);\n+\treturn git_config_with_options(fn, data, NULL, 1, 0);\n }\n \n /*\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex c4a7d84..db661a9 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -1021,6 +1021,13 @@ test_expect_success 'git -c works with aliases of builtins' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'git -c works with mixed-case aliases of builtins' '\n+\tgit config alias.checkConfig \"-c foo.check=bar config foo.check\" &&\n+\techo bar >expect &&\n+\tgit checkConfig >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'git -c does not split values on equals' '\n \techo \"value with = in it\" >expect &&\n \tgit -c core.foo=\"value with = in it\" config core.foo >actual &&\n-- \n1.8.3.1.436.gbdff0e3.dirty\n"}]}