{"thread":{"id":"28640","subject":"[BUG 1.7.6.1] `git config --bool --get-regexp' omits separating space... sometimes!","startedAt":"2011-10-10T10:20:21Z","lastAt":"2011-10-10T20:59:16Z","messageCount":4,"participants":["Brian Foster","Matthieu Moy","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"177312","messageId":"201110101220.21890.brian.foster@maxim-ic.com","threadId":"28640","inReplyTo":null,"subject":"[BUG 1.7.6.1] `git config --bool --get-regexp' omits separating space... sometimes!","fromName":"Brian Foster","fromEmail":"brian.foster@maxim-ic.com","sentAt":"2011-10-10T10:20:21Z","receivedAt":"2011-10-10T10:20:21Z","isPatch":false,"sender":{"key":"brian.foster@maxim-ic.com","avatar":null},"body":"Hello,\n\n# Script to illustrate the problem:\nrm -f Config\ncat <<\\EOF >Config\n[Example]\n\tBoolean\n\tOther = yes\nEOF\ngit_Config() { git config --file Config \"$@\"; }\n\ngit version\ngit_Config        --get-regexp '.*\\.Boolean'\t#1. ✓ Ok: example.boolean\ngit_Config --bool --get-regexp '.*\\.Boolean'\t#2. ✗ NO: example.booleantrue\ngit_Config        --get-regexp '.*\\.Other'\t#3. ✓ Ok: example.other yes\ngit_Config --bool --get-regexp '.*\\.Other'\t#4. ✓ Ok: example.other true\nexit\n\n# Output:\ngit version 1.7.6.1\nexample.boolean\nexample.booleantrue\nexample.other yes\nexample.other true\n\n Case 2 omits the space between the key-name and (generated) value,\n making the output difficult to parse/process.  Without checking,\n I assume --int (and friends) have a similar bug?\n\ncheers!\n\t-blf-\n\n-- \nBrian FOSTER\nPrincipal MTS, Software\nMaxim Integrated Products (Microcontroller BU), formerly Innova Card\nWeb    : http://www.maxim-ic.com/\n"},{"id":"177313","messageId":"vpq1uulm2wz.fsf@bauges.imag.fr","threadId":"28640","inReplyTo":"201110101220.21890.brian.foster@maxim-ic.com","subject":"Re: [BUG 1.7.6.1] `git config --bool --get-regexp' omits separating space... sometimes!","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2011-10-10T12:44:44Z","receivedAt":"2011-10-10T12:44:44Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Brian Foster <brian.foster@maxim-ic.com> writes:\n\n> example.boolean\n> example.booleantrue\n\nThere's a problem in\n\nstatic int show_config(const char *key_, const char *value_, void *cb)\n\nin builtin/config.c. Patch follows.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"177314","messageId":"1318251291-30297-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"28640","inReplyTo":"201110101220.21890.brian.foster@maxim-ic.com","subject":"[PATCH] config: display key_delim for config --bool --get-regexp","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2011-10-10T12:54:51Z","receivedAt":"2011-10-10T12:54:51Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"The previous logic in show_config was to print the delimiter when the\nvalue was set, but Boolean variables have an implicit value \"true\" when\nthey appear with no value in the config file. As a result, we got:\n\ngit_Config        --get-regexp '.*\\.Boolean'\t#1. Ok: example.boolean\ngit_Config --bool --get-regexp '.*\\.Boolean'\t#2. NO: example.booleantrue\n\nFix this by defering the display of the separator until after the value\nto display has been computed.\n\nReported-by: Brian Foster <brian.foster@maxim-ic.com>\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n builtin/config.c       |   20 +++++++++++++-------\n t/t1300-repo-config.sh |    6 ++++++\n 2 files changed, 19 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 0b4ecac..0315ad7 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -99,6 +99,7 @@ static int show_config(const char *key_, const char *value_, void *cb)\n \tconst char *vptr = value;\n \tint must_free_vptr = 0;\n \tint dup_error = 0;\n+\tint must_print_delim = 0;\n \n \tif (!use_key_regexp && strcmp(key_, key))\n \t\treturn 0;\n@@ -109,10 +110,8 @@ static int show_config(const char *key_, const char *value_, void *cb)\n \t\treturn 0;\n \n \tif (show_keys) {\n-\t\tif (value_)\n-\t\t\tprintf(\"%s%c\", key_, key_delim);\n-\t\telse\n-\t\t\tprintf(\"%s\", key_);\n+\t\tprintf(\"%s\", key_);\n+\t\tmust_print_delim = 1;\n \t}\n \tif (seen && !do_all)\n \t\tdup_error = 1;\n@@ -130,16 +129,23 @@ static int show_config(const char *key_, const char *value_, void *cb)\n \t} else if (types == TYPE_PATH) {\n \t\tgit_config_pathname(&vptr, key_, value_);\n \t\tmust_free_vptr = 1;\n+\t} else if (value_) {\n+\t\tvptr = value_;\n+\t} else {\n+\t\t/* Just show the key name */\n+\t\tvptr = \"\";\n+\t\tmust_print_delim = 0;\n \t}\n-\telse\n-\t\tvptr = value_?value_:\"\";\n \tseen++;\n \tif (dup_error) {\n \t\terror(\"More than one value for the key %s: %s\",\n \t\t\t\tkey_, vptr);\n \t}\n-\telse\n+\telse {\n+\t\tif (must_print_delim)\n+\t\t\tprintf(\"%c\", key_delim);\n \t\tprintf(\"%s%c\", vptr, term);\n+\t}\n \tif (must_free_vptr)\n \t\t/* If vptr must be freed, it's a pointer to a\n \t\t * dynamically allocated buffer, it's safe to cast to\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex 3e140c1..dffccf8 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -333,6 +333,12 @@ test_expect_success 'get-regexp variable with no value' \\\n \t'git config --get-regexp novalue > output &&\n \t cmp output expect'\n \n+echo 'novalue.variable true' > expect\n+\n+test_expect_success 'get-regexp --bool variable with no value' \\\n+\t'git config --bool --get-regexp novalue > output &&\n+\t cmp output expect'\n+\n echo 'emptyvalue.variable ' > expect\n \n test_expect_success 'get-regexp variable with empty value' \\\n-- \n1.7.7.140.ge3099\n"},{"id":"177331","messageId":"7vk48ck1gb.fsf@alter.siamese.dyndns.org","threadId":"28640","inReplyTo":"1318251291-30297-1-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH] config: display key_delim for config --bool --get-regexp","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-10-10T20:59:16Z","receivedAt":"2011-10-10T20:59:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@imag.fr> writes:\n\n> The previous logic in show_config was to print the delimiter when the\n> value was set, but Boolean variables have an implicit value \"true\" when\n> they appear with no value in the config file. As a result, we got:\n>\n> git_Config        --get-regexp '.*\\.Boolean'\t#1. Ok: example.boolean\n> git_Config --bool --get-regexp '.*\\.Boolean'\t#2. NO: example.booleantrue\n>\n> Fix this by defering the display of the separator until after the value\n> to display has been computed.\n>\n> Reported-by: Brian Foster <brian.foster@maxim-ic.com>\n> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n> ---\n\nThanks. Will queue for maintenance track.\n\n> diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\n> index 3e140c1..dffccf8 100755\n> --- a/t/t1300-repo-config.sh\n> +++ b/t/t1300-repo-config.sh\n> @@ -333,6 +333,12 @@ test_expect_success 'get-regexp variable with no value' \\\n>  \t'git config --get-regexp novalue > output &&\n>  \t cmp output expect'\n>  \n> +echo 'novalue.variable true' > expect\n> +\n> +test_expect_success 'get-regexp --bool variable with no value' \\\n> +\t'git config --bool --get-regexp novalue > output &&\n> +\t cmp output expect'\n> +\n>  echo 'emptyvalue.variable ' > expect\n>  \n>  test_expect_success 'get-regexp variable with empty value' \\\n\nThis matches the style of the surrounding code, but we may want to update\nthis to a more modern style.\n"}]}