{"thread":{"id":"23081","subject":"[PATCH] Allow passing of configuration parameters in the command line","startedAt":"2010-03-19T14:42:09Z","lastAt":"2010-03-20T16:20:02Z","messageCount":8,"participants":["Alex Riesen","Junio C Hamano","Nguyen Thai Ngoc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"137228","messageId":"81b0412b1003190742v6e5577c9wb121d5e3cbc9fccd@mail.gmail.com","threadId":"23081","inReplyTo":null,"subject":"[PATCH] Allow passing of configuration parameters in the command line","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2010-03-19T14:42:09Z","receivedAt":"2010-03-19T14:42:09Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"The values passed this way will override whatever is defined\nin the config files.\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n\nSomeone wanted to have this once. I accidentally remembered\nthat when I wanted to temporarily set some config parameter\n(format.suffix?). From looking at code it seemed simple enough,\nso I did it.\n\nI have to say that the feature is not very friendly: there are\nsome values in .git/config which may not like to be changed\n(like core.fileMode, ...ignoreCase or ...repositoryFormatVersion).\n\n Documentation/git.txt  |    7 +++++\n builtin/config.c       |    6 +++-\n cache.h                |    2 +\n config.c               |   71 ++++++++++++++++++++++++++++++++++++++++++++++++\n git.c                  |    9 ++++++\n t/t1300-repo-config.sh |    7 +++++\n 6 files changed, 101 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git.txt b/Documentation/git.txt\nindex 35c0c79..755fa4d 100644\n--- a/Documentation/git.txt\n+++ b/Documentation/git.txt\n@@ -12,6 +12,7 @@ SYNOPSIS\n 'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n     [-p|--paginate|--no-pager] [--no-replace-objects]\n     [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]\n+    [-c name=value]\n     [--help] COMMAND [ARGS]\n\n DESCRIPTION\n@@ -219,6 +220,12 @@ displayed. See linkgit:git-help[1] for more information,\n because `git --help ...` is converted internally into `git\n help ...`.\n\n+-c <name>=<value>::\n+\tPass a configuration parameter to the command. The value\n+\tgiven will override values from configuration files.\n+\tThe <name> is expected in the same format as listed by\n+\t'git config' (subkeys separated by dots).\n+\n --exec-path::\n \tPath to wherever your core git programs are installed.\n \tThis can also be controlled by setting the GIT_EXEC_PATH\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 4bc46b1..f3d1660 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -197,7 +197,11 @@ static int get_value(const char *key_, const char *regex_)\n \t\tgit_config_from_file(show_config, system_wide, NULL);\n \tif (do_all && global)\n \t\tgit_config_from_file(show_config, global, NULL);\n-\tgit_config_from_file(show_config, local, NULL);\n+\tif (do_all)\n+\t\tgit_config_from_file(show_config, local, NULL);\n+\tgit_config_from_parameters(show_config, NULL);\n+\tif (!do_all && !seen)\n+\t\tgit_config_from_file(show_config, local, NULL);\n \tif (!do_all && !seen && global)\n \t\tgit_config_from_file(show_config, global, NULL);\n \tif (!do_all && !seen && system_wide)\ndiff --git a/cache.h b/cache.h\nindex 89f6a40..4a0c75d 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -932,6 +932,8 @@ extern int update_server_info(int);\n typedef int (*config_fn_t)(const char *, const char *, void *);\n extern int git_default_config(const char *, const char *, void *);\n extern int git_config_from_file(config_fn_t fn, const char *, void *);\n+extern int git_config_parse_parameter(const char *text);\n+extern int git_config_from_parameters();\n extern int git_config(config_fn_t fn, void *);\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 6963fbe..2376ae9 100644\n--- a/config.c\n+++ b/config.c\n@@ -18,6 +18,62 @@ static int zlib_compression_seen;\n\n const char *config_exclusive_filename = NULL;\n\n+struct config_item\n+{\n+\tstruct config_item *next;\n+\tchar *value;\n+\tchar name[1];\n+};\n+static struct config_item *config_parameters;\n+static struct config_item **config_parametes_tail = &config_parameters;\n+\n+static void lowercase(char *p)\n+{\n+\tfor (; *p; ++p)\n+\t\t*p = tolower(*p);\n+}\n+static char *skip_space(const char *p)\n+{\n+\tfor (; *p; ++p)\n+\t\tif (!isspace(*p))\n+\t\t\tbreak;\n+\treturn (char *)p;\n+}\n+static char *trailing_space(const char *begin, const char *p)\n+{\n+\twhile (p-- > begin)\n+\t\tif (!isspace(*p))\n+\t\t\tbreak;\n+\treturn (char *)p + 1;\n+}\n+\n+int git_config_parse_parameter(const char *text)\n+{\n+\tstruct config_item *ct;\n+\tconst char *name;\n+\tconst char *val;\n+\tname = skip_space(text);\n+\ttext = val = strchr(name, '=');\n+\tif (!text)\n+\t\ttext = name + strlen(name);\n+\ttext = trailing_space(name, text);\n+\tif (text <= name)\n+\t\treturn -1;\n+\tct = calloc(1, sizeof(struct config_item) + (text - name));\n+\tmemcpy(ct->name, name, text - name);\n+\tlowercase(ct->name);\n+\tif (!val)\n+\t\tct->value = NULL;\n+\telse {\n+\t\tval = skip_space(++val /* skip \"=\" */);\n+\t\ttext = trailing_space(val, val + strlen(val));\n+\t\tct->value = strndup(val, text - val);\n+\t}\n+\t*config_parametes_tail = ct;\n+\tconfig_parametes_tail = &ct->next;\n+\treturn 0;\n+}\n+\n static int get_next_char(void)\n {\n \tint c;\n@@ -699,6 +755,15 @@ int git_config_global(void)\n \treturn !git_env_bool(\"GIT_CONFIG_NOGLOBAL\", 0);\n }\n\n+int git_config_from_parameters(config_fn_t fn, void *data)\n+{\n+\tconst struct config_item *ct;\n+\tfor (ct = config_parameters; ct; ct = ct->next)\n+\t\tif (fn(ct->name, ct->value, data) < 0)\n+\t\t\treturn -1;\n+\treturn 0;\n+}\n+\n int git_config(config_fn_t fn, void *data)\n {\n \tint ret = 0, found = 0;\n@@ -730,6 +795,12 @@ int git_config(config_fn_t fn, void *data)\n \t\tfound += 1;\n \t}\n \tfree(repo_config);\n+\n+\tif (config_parameters) {\n+\t\tret += git_config_from_parameters(fn, data);\n+\t\tfound += 1;\n+\t}\n+\n \tif (found == 0)\n \t\treturn -1;\n \treturn ret;\ndiff --git a/git.c b/git.c\nindex 6bae305..99f0363 100644\n--- a/git.c\n+++ b/git.c\n@@ -8,6 +8,7 @@ const char git_usage_string[] =\n \t\"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\\n\"\n \t\"           [-p|--paginate|--no-pager] [--no-replace-objects]\\n\"\n \t\"           [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]\\n\"\n+\t\"           [-c name=value\\n\"\n \t\"           [--help] COMMAND [ARGS]\";\n\n const char git_more_info_string[] =\n@@ -130,6 +131,14 @@ static int handle_options(const char ***argv, int\n*argc, int *envchanged)\n \t\t\tsetenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 0);\n \t\t\tif (envchanged)\n \t\t\t\t*envchanged = 1;\n+\t\t} else if (!strcmp(cmd, \"-c\")) {\n+\t\t\tif (*argc < 2) {\n+\t\t\t\tfprintf(stderr, \"-c expects a configuration string\\n\" );\n+\t\t\t\tusage(git_usage_string);\n+\t\t\t}\n+\t\t\tgit_config_parse_parameter((*argv)[1]);\n+\t\t\t(*argv)++;\n+\t\t\t(*argc)--;\n \t\t} else {\n \t\t\tfprintf(stderr, \"Unknown option: %s\\n\", cmd);\n \t\t\tusage(git_usage_string);\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex f11f98c..d7c5501 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -824,4 +824,11 @@ test_expect_success 'check split_cmdline return' \"\n \ttest_must_fail git merge master\n \t\"\n\n+test_expect_success 'git -c \"key=value\" support' '\n+\ttest \"z$(git -c name=value config name)\" = zvalue &&\n+\ttest \"z$(git -c core.name=value config core.name)\" = zvalue &&\n+\ttest \"z$(git -c flag config --bool flag)\" = ztrue &&\n+\ttest_must_fail git -c core.name=value config name\n+'\n+\n test_done\n-- \n1.7.0.2.318.g49250\n\n\nFrom 99febf0858fde149009cff7d031f229eff8a92e1 Mon Sep 17 00:00:00 2001\nFrom: Alex Riesen <raa.lkml@gmail.com>\nDate: Fri, 19 Mar 2010 15:19:24 +0100\nSubject: [PATCH] Allow passing of configuration parameters in the command line\n\nThe values passed this way will override whatever is defined\nin the config files.\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n Documentation/git.txt  |    7 +++++\n builtin/config.c       |    6 +++-\n cache.h                |    2 +\n config.c               |   71 ++++++++++++++++++++++++++++++++++++++++++++++++\n git.c                  |    9 ++++++\n t/t1300-repo-config.sh |    7 +++++\n 6 files changed, 101 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git.txt b/Documentation/git.txt\nindex 35c0c79..755fa4d 100644\n--- a/Documentation/git.txt\n+++ b/Documentation/git.txt\n@@ -12,6 +12,7 @@ SYNOPSIS\n 'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n     [-p|--paginate|--no-pager] [--no-replace-objects]\n     [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]\n+    [-c name=value]\n     [--help] COMMAND [ARGS]\n \n DESCRIPTION\n@@ -219,6 +220,12 @@ displayed. See linkgit:git-help[1] for more information,\n because `git --help ...` is converted internally into `git\n help ...`.\n \n+-c <name>=<value>::\n+\tPass a configuration parameter to the command. The value\n+\tgiven will override values from configuration files.\n+\tThe <name> is expected in the same format as listed by\n+\t'git config' (subkeys separated by dots).\n+\n --exec-path::\n \tPath to wherever your core git programs are installed.\n \tThis can also be controlled by setting the GIT_EXEC_PATH\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 4bc46b1..f3d1660 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -197,7 +197,11 @@ static int get_value(const char *key_, const char *regex_)\n \t\tgit_config_from_file(show_config, system_wide, NULL);\n \tif (do_all && global)\n \t\tgit_config_from_file(show_config, global, NULL);\n-\tgit_config_from_file(show_config, local, NULL);\n+\tif (do_all)\n+\t\tgit_config_from_file(show_config, local, NULL);\n+\tgit_config_from_parameters(show_config, NULL);\n+\tif (!do_all && !seen)\n+\t\tgit_config_from_file(show_config, local, NULL);\n \tif (!do_all && !seen && global)\n \t\tgit_config_from_file(show_config, global, NULL);\n \tif (!do_all && !seen && system_wide)\ndiff --git a/cache.h b/cache.h\nindex 89f6a40..4a0c75d 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -932,6 +932,8 @@ extern int update_server_info(int);\n typedef int (*config_fn_t)(const char *, const char *, void *);\n extern int git_default_config(const char *, const char *, void *);\n extern int git_config_from_file(config_fn_t fn, const char *, void *);\n+extern int git_config_parse_parameter(const char *text);\n+extern int git_config_from_parameters();\n extern int git_config(config_fn_t fn, void *);\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 6963fbe..2376ae9 100644\n--- a/config.c\n+++ b/config.c\n@@ -18,6 +18,62 @@ static int zlib_compression_seen;\n \n const char *config_exclusive_filename = NULL;\n \n+struct config_item\n+{\n+\tstruct config_item *next;\n+\tchar *value;\n+\tchar name[1];\n+};\n+static struct config_item *config_parameters;\n+static struct config_item **config_parametes_tail = &config_parameters;\n+\n+static void lowercase(char *p)\n+{\n+\tfor (; *p; ++p)\n+\t\t*p = tolower(*p);\n+}\n+static char *skip_space(const char *p)\n+{\n+\tfor (; *p; ++p)\n+\t\tif (!isspace(*p))\n+\t\t\tbreak;\n+\treturn (char *)p;\n+}\n+static char *trailing_space(const char *begin, const char *p)\n+{\n+\twhile (p-- > begin)\n+\t\tif (!isspace(*p))\n+\t\t\tbreak;\n+\treturn (char *)p + 1;\n+}\n+\n+int git_config_parse_parameter(const char *text)\n+{\n+\tstruct config_item *ct;\n+\tconst char *name;\n+\tconst char *val;\n+\tname = skip_space(text);\n+\ttext = val = strchr(name, '=');\n+\tif (!text)\n+\t\ttext = name + strlen(name);\n+\ttext = trailing_space(name, text);\n+\tif (text <= name)\n+\t\treturn -1;\n+\tct = calloc(1, sizeof(struct config_item) + (text - name));\n+\tmemcpy(ct->name, name, text - name);\n+\tlowercase(ct->name);\n+\tif (!val)\n+\t\tct->value = NULL;\n+\telse {\n+\t\tval = skip_space(++val /* skip \"=\" */);\n+\t\ttext = trailing_space(val, val + strlen(val));\n+\t\tct->value = strndup(val, text - val);\n+\t}\n+\t*config_parametes_tail = ct;\n+\tconfig_parametes_tail = &ct->next;\n+\treturn 0;\n+}\n+\n static int get_next_char(void)\n {\n \tint c;\n@@ -699,6 +755,15 @@ int git_config_global(void)\n \treturn !git_env_bool(\"GIT_CONFIG_NOGLOBAL\", 0);\n }\n \n+int git_config_from_parameters(config_fn_t fn, void *data)\n+{\n+\tconst struct config_item *ct;\n+\tfor (ct = config_parameters; ct; ct = ct->next)\n+\t\tif (fn(ct->name, ct->value, data) < 0)\n+\t\t\treturn -1;\n+\treturn 0;\n+}\n+\n int git_config(config_fn_t fn, void *data)\n {\n \tint ret = 0, found = 0;\n@@ -730,6 +795,12 @@ int git_config(config_fn_t fn, void *data)\n \t\tfound += 1;\n \t}\n \tfree(repo_config);\n+\n+\tif (config_parameters) {\n+\t\tret += git_config_from_parameters(fn, data);\n+\t\tfound += 1;\n+\t}\n+\n \tif (found == 0)\n \t\treturn -1;\n \treturn ret;\ndiff --git a/git.c b/git.c\nindex 6bae305..99f0363 100644\n--- a/git.c\n+++ b/git.c\n@@ -8,6 +8,7 @@ const char git_usage_string[] =\n \t\"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\\n\"\n \t\"           [-p|--paginate|--no-pager] [--no-replace-objects]\\n\"\n \t\"           [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]\\n\"\n+\t\"           [-c name=value\\n\"\n \t\"           [--help] COMMAND [ARGS]\";\n \n const char git_more_info_string[] =\n@@ -130,6 +131,14 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n \t\t\tsetenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 0);\n \t\t\tif (envchanged)\n \t\t\t\t*envchanged = 1;\n+\t\t} else if (!strcmp(cmd, \"-c\")) {\n+\t\t\tif (*argc < 2) {\n+\t\t\t\tfprintf(stderr, \"-c expects a configuration string\\n\" );\n+\t\t\t\tusage(git_usage_string);\n+\t\t\t}\n+\t\t\tgit_config_parse_parameter((*argv)[1]);\n+\t\t\t(*argv)++;\n+\t\t\t(*argc)--;\n \t\t} else {\n \t\t\tfprintf(stderr, \"Unknown option: %s\\n\", cmd);\n \t\t\tusage(git_usage_string);\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex f11f98c..d7c5501 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -824,4 +824,11 @@ test_expect_success 'check split_cmdline return' \"\n \ttest_must_fail git merge master\n \t\"\n \n+test_expect_success 'git -c \"key=value\" support' '\n+\ttest \"z$(git -c name=value config name)\" = zvalue &&\n+\ttest \"z$(git -c core.name=value config core.name)\" = zvalue &&\n+\ttest \"z$(git -c flag config --bool flag)\" = ztrue &&\n+\ttest_must_fail git -c core.name=value config name\n+'\n+\n test_done\n-- \n1.7.0.2.318.g49250\n\n"},{"id":"137262","messageId":"7vmxy4kss9.fsf@alter.siamese.dyndns.org","threadId":"23081","inReplyTo":"81b0412b1003190742v6e5577c9wb121d5e3cbc9fccd@mail.gmail.com","subject":"Re: [PATCH] Allow passing of configuration parameters in the command line","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-19T19:36:38Z","receivedAt":"2010-03-19T19:36:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Riesen <raa.lkml@gmail.com> writes:\n\n> The values passed this way will override whatever is defined\n> in the config files.\n>\n> Signed-off-by: Alex Riesen <raa.lkml@gmail.com>\n> ---\n>\n> Someone wanted to have this once. I accidentally remembered\n> that when I wanted to temporarily set some config parameter\n> (format.suffix?). From looking at code it seemed simple enough,\n> so I did it.\n\nHow does this interact with core.worktree and the setup sequence in\ngeneral?\n\nBy \"setup sequence\", I mean something I tried to extract from Nguyen here:\n\n http://thread.gmane.org/gmane.comp.version-control.git/141962/focus=142001\n \nDuring the process of finding the repository (.git/ or project.git/), we\nwould open its config to check the repository format version, that that\nwould be the earliest point we might decide where the work tree is (or if\nwe have work tree at all).  Where should this new mechanism hook into the\nsequence to give users an expected behaviour (what's expected in the first\nplace)?\n"},{"id":"137318","messageId":"fcaeb9bf1003200209r6051f906kf2a0a1e96752845e@mail.gmail.com","threadId":"23081","inReplyTo":"7vmxy4kss9.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Allow passing of configuration parameters in the command line","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-03-20T09:09:47Z","receivedAt":"2010-03-20T09:09:47Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On 3/20/10, Junio C Hamano <gitster@pobox.com> wrote:\n> Alex Riesen <raa.lkml@gmail.com> writes:\n>\n>  > The values passed this way will override whatever is defined\n>  > in the config files.\n>  >\n>  > Signed-off-by: Alex Riesen <raa.lkml@gmail.com>\n>  > ---\n>  >\n>  > Someone wanted to have this once. I accidentally remembered\n>  > that when I wanted to temporarily set some config parameter\n>  > (format.suffix?). From looking at code it seemed simple enough,\n>  > so I did it.\n>\n>\n> How does this interact with core.worktree and the setup sequence in\n>  general?\n\nTo me it looks like another config file to the config stack. No thing\ncan go worse (except that if you have core.worktree in\n$GIT_DIR/config, now also specify -c core.worktree=foo, then\ncore.worktree code would be called twice).\n\nHowever, specifying \"-c foo=relativepath\" may surprise users. Current\nworking directory may have been moved when that config is used.\n-- \nDuy\n"},{"id":"137319","messageId":"81b0412b1003200217m39c79418w54ac0735e8e6405a@mail.gmail.com","threadId":"23081","inReplyTo":"fcaeb9bf1003200209r6051f906kf2a0a1e96752845e@mail.gmail.com","subject":"Re: [PATCH] Allow passing of configuration parameters in the command line","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2010-03-20T09:17:06Z","receivedAt":"2010-03-20T09:17:06Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On Sat, Mar 20, 2010 at 10:09, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:\n> On 3/20/10, Junio C Hamano <gitster@pobox.com> wrote:\n>> Alex Riesen <raa.lkml@gmail.com> writes:\n>>\n>>  > The values passed this way will override whatever is defined\n>>  > in the config files.\n>>  >\n>>  > Signed-off-by: Alex Riesen <raa.lkml@gmail.com>\n>>  > ---\n>>  >\n>>  > Someone wanted to have this once. I accidentally remembered\n>>  > that when I wanted to temporarily set some config parameter\n>>  > (format.suffix?). From looking at code it seemed simple enough,\n>>  > so I did it.\n>>\n>> How does this interact with core.worktree and the setup sequence in\n>>  general?\n>\n> To me it looks like another config file to the config stack. No thing\n> can go worse (except that if you have core.worktree in\n> $GIT_DIR/config, now also specify -c core.worktree=foo, then\n> core.worktree code would be called twice).\n\nYes, that's why I said the whole thing is not very friendly.\nTo an experienced user it will be expected, though.\n"},{"id":"137343","messageId":"7vbpejkmo5.fsf@alter.siamese.dyndns.org","threadId":"23081","inReplyTo":"81b0412b1003190742v6e5577c9wb121d5e3cbc9fccd@mail.gmail.com","subject":"Re: [PATCH] Allow passing of configuration parameters in the command line","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-20T16:00:58Z","receivedAt":"2010-03-20T16:00:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Riesen <raa.lkml@gmail.com> writes:\n\n> The values passed this way will override whatever is defined\n> in the config files.\n\nYou sent MIME multipart-mixed and I am getting a broken patch.\n\nHow could this be... If I cannot expect to reliably get a non-linewrapped\npatch, there doesn't seem to be much point in you and I taking extra time\nto bother with MIME.\n\nVery unhappy (not with you, Alex, but with MIME and whatever tool that\nwrapped your lines).\n"},{"id":"137345","messageId":"81b0412b1003200903gb6923e1ved6de423db97b28@mail.gmail.com","threadId":"23081","inReplyTo":"7vbpejkmo5.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Allow passing of configuration parameters in the command line","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2010-03-20T16:03:36Z","receivedAt":"2010-03-20T16:03:36Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On Sat, Mar 20, 2010 at 17:00, Junio C Hamano <gitster@pobox.com> wrote:\n> Alex Riesen <raa.lkml@gmail.com> writes:\n>\n>> The values passed this way will override whatever is defined\n>> in the config files.\n>\n> You sent MIME multipart-mixed and I am getting a broken patch.\n>\n> How could this be... If I cannot expect to reliably get a non-linewrapped\n> patch, there doesn't seem to be much point in you and I taking extra time\n> to bother with MIME.\n\nThat's gmail, again. There must be an attachment with a normal patch,\nbut I'll resend.\n"},{"id":"137347","messageId":"20100320160543.GA18709@blimp.localdomain","threadId":"23081","inReplyTo":"7vbpejkmo5.fsf@alter.siamese.dyndns.org","subject":"[PATCH, resend] Allow passing of configuration parameters in the command line","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2010-03-20T16:05:43Z","receivedAt":"2010-03-20T16:05:43Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"The values passed this way will override whatever is defined\nin the config files.\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n Documentation/git.txt  |    7 +++++\n builtin/config.c       |    6 +++-\n cache.h                |    2 +\n config.c               |   71 ++++++++++++++++++++++++++++++++++++++++++++++++\n git.c                  |    9 ++++++\n t/t1300-repo-config.sh |    7 +++++\n 6 files changed, 101 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git.txt b/Documentation/git.txt\nindex 35c0c79..755fa4d 100644\n--- a/Documentation/git.txt\n+++ b/Documentation/git.txt\n@@ -12,6 +12,7 @@ SYNOPSIS\n 'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n     [-p|--paginate|--no-pager] [--no-replace-objects]\n     [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]\n+    [-c name=value]\n     [--help] COMMAND [ARGS]\n \n DESCRIPTION\n@@ -219,6 +220,12 @@ displayed. See linkgit:git-help[1] for more information,\n because `git --help ...` is converted internally into `git\n help ...`.\n \n+-c <name>=<value>::\n+\tPass a configuration parameter to the command. The value\n+\tgiven will override values from configuration files.\n+\tThe <name> is expected in the same format as listed by\n+\t'git config' (subkeys separated by dots).\n+\n --exec-path::\n \tPath to wherever your core git programs are installed.\n \tThis can also be controlled by setting the GIT_EXEC_PATH\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 4bc46b1..f3d1660 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -197,7 +197,11 @@ static int get_value(const char *key_, const char *regex_)\n \t\tgit_config_from_file(show_config, system_wide, NULL);\n \tif (do_all && global)\n \t\tgit_config_from_file(show_config, global, NULL);\n-\tgit_config_from_file(show_config, local, NULL);\n+\tif (do_all)\n+\t\tgit_config_from_file(show_config, local, NULL);\n+\tgit_config_from_parameters(show_config, NULL);\n+\tif (!do_all && !seen)\n+\t\tgit_config_from_file(show_config, local, NULL);\n \tif (!do_all && !seen && global)\n \t\tgit_config_from_file(show_config, global, NULL);\n \tif (!do_all && !seen && system_wide)\ndiff --git a/cache.h b/cache.h\nindex 89f6a40..4a0c75d 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -932,6 +932,8 @@ extern int update_server_info(int);\n typedef int (*config_fn_t)(const char *, const char *, void *);\n extern int git_default_config(const char *, const char *, void *);\n extern int git_config_from_file(config_fn_t fn, const char *, void *);\n+extern int git_config_parse_parameter(const char *text);\n+extern int git_config_from_parameters();\n extern int git_config(config_fn_t fn, void *);\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 6963fbe..2376ae9 100644\n--- a/config.c\n+++ b/config.c\n@@ -18,6 +18,62 @@ static int zlib_compression_seen;\n \n const char *config_exclusive_filename = NULL;\n \n+struct config_item\n+{\n+\tstruct config_item *next;\n+\tchar *value;\n+\tchar name[1];\n+};\n+static struct config_item *config_parameters;\n+static struct config_item **config_parametes_tail = &config_parameters;\n+\n+static void lowercase(char *p)\n+{\n+\tfor (; *p; ++p)\n+\t\t*p = tolower(*p);\n+}\n+static char *skip_space(const char *p)\n+{\n+\tfor (; *p; ++p)\n+\t\tif (!isspace(*p))\n+\t\t\tbreak;\n+\treturn (char *)p;\n+}\n+static char *trailing_space(const char *begin, const char *p)\n+{\n+\twhile (p-- > begin)\n+\t\tif (!isspace(*p))\n+\t\t\tbreak;\n+\treturn (char *)p + 1;\n+}\n+\n+int git_config_parse_parameter(const char *text)\n+{\n+\tstruct config_item *ct;\n+\tconst char *name;\n+\tconst char *val;\n+\tname = skip_space(text);\n+\ttext = val = strchr(name, '=');\n+\tif (!text)\n+\t\ttext = name + strlen(name);\n+\ttext = trailing_space(name, text);\n+\tif (text <= name)\n+\t\treturn -1;\n+\tct = calloc(1, sizeof(struct config_item) + (text - name));\n+\tmemcpy(ct->name, name, text - name);\n+\tlowercase(ct->name);\n+\tif (!val)\n+\t\tct->value = NULL;\n+\telse {\n+\t\tval = skip_space(++val /* skip \"=\" */);\n+\t\ttext = trailing_space(val, val + strlen(val));\n+\t\tct->value = strndup(val, text - val);\n+\t}\n+\t*config_parametes_tail = ct;\n+\tconfig_parametes_tail = &ct->next;\n+\treturn 0;\n+}\n+\n static int get_next_char(void)\n {\n \tint c;\n@@ -699,6 +755,15 @@ int git_config_global(void)\n \treturn !git_env_bool(\"GIT_CONFIG_NOGLOBAL\", 0);\n }\n \n+int git_config_from_parameters(config_fn_t fn, void *data)\n+{\n+\tconst struct config_item *ct;\n+\tfor (ct = config_parameters; ct; ct = ct->next)\n+\t\tif (fn(ct->name, ct->value, data) < 0)\n+\t\t\treturn -1;\n+\treturn 0;\n+}\n+\n int git_config(config_fn_t fn, void *data)\n {\n \tint ret = 0, found = 0;\n@@ -730,6 +795,12 @@ int git_config(config_fn_t fn, void *data)\n \t\tfound += 1;\n \t}\n \tfree(repo_config);\n+\n+\tif (config_parameters) {\n+\t\tret += git_config_from_parameters(fn, data);\n+\t\tfound += 1;\n+\t}\n+\n \tif (found == 0)\n \t\treturn -1;\n \treturn ret;\ndiff --git a/git.c b/git.c\nindex 6bae305..99f0363 100644\n--- a/git.c\n+++ b/git.c\n@@ -8,6 +8,7 @@ const char git_usage_string[] =\n \t\"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\\n\"\n \t\"           [-p|--paginate|--no-pager] [--no-replace-objects]\\n\"\n \t\"           [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]\\n\"\n+\t\"           [-c name=value\\n\"\n \t\"           [--help] COMMAND [ARGS]\";\n \n const char git_more_info_string[] =\n@@ -130,6 +131,14 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n \t\t\tsetenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 0);\n \t\t\tif (envchanged)\n \t\t\t\t*envchanged = 1;\n+\t\t} else if (!strcmp(cmd, \"-c\")) {\n+\t\t\tif (*argc < 2) {\n+\t\t\t\tfprintf(stderr, \"-c expects a configuration string\\n\" );\n+\t\t\t\tusage(git_usage_string);\n+\t\t\t}\n+\t\t\tgit_config_parse_parameter((*argv)[1]);\n+\t\t\t(*argv)++;\n+\t\t\t(*argc)--;\n \t\t} else {\n \t\t\tfprintf(stderr, \"Unknown option: %s\\n\", cmd);\n \t\t\tusage(git_usage_string);\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex f11f98c..d7c5501 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -824,4 +824,11 @@ test_expect_success 'check split_cmdline return' \"\n \ttest_must_fail git merge master\n \t\"\n \n+test_expect_success 'git -c \"key=value\" support' '\n+\ttest \"z$(git -c name=value config name)\" = zvalue &&\n+\ttest \"z$(git -c core.name=value config core.name)\" = zvalue &&\n+\ttest \"z$(git -c flag config --bool flag)\" = ztrue &&\n+\ttest_must_fail git -c core.name=value config name\n+'\n+\n test_done\n-- \n1.7.0.2.318.g49250\n"},{"id":"137348","messageId":"7v634rj77x.fsf@alter.siamese.dyndns.org","threadId":"23081","inReplyTo":"81b0412b1003200903gb6923e1ved6de423db97b28@mail.gmail.com","subject":"Re: [PATCH] Allow passing of configuration parameters in the command line","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-20T16:20:02Z","receivedAt":"2010-03-20T16:20:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Riesen <raa.lkml@gmail.com> writes:\n\n> On Sat, Mar 20, 2010 at 17:00, Junio C Hamano <gitster@pobox.com> wrote:\n>> Alex Riesen <raa.lkml@gmail.com> writes:\n>>\n>>> The values passed this way will override whatever is defined\n>>> in the config files.\n>>\n>> You sent MIME multipart-mixed and I am getting a broken patch.\n>>\n>> How could this be... If I cannot expect to reliably get a non-linewrapped\n>> patch, there doesn't seem to be much point in you and I taking extra time\n>> to bother with MIME.\n>\n> That's gmail, again. There must be an attachment with a normal patch,\n> but I'll resend.\n\nI think it was coming from duplicates.  The attachment was fine, but the\nnormal part was wrapped.\n\nApplied with a manual fix.  But thanks anyway.\n"}]}