{"thread":{"id":"24871","subject":"[PATCH] Test the interaction of --bool and --get-regexp on a key with no explicit value","startedAt":"2010-08-26T17:45:16Z","lastAt":"2010-08-27T03:17:57Z","messageCount":4,"participants":["Alex Vandiver","alex@chmrr.net","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"149075","messageId":"1282844716-30591-1-git-send-email-alex@chmrr.net","threadId":"24871","inReplyTo":null,"subject":"[PATCH] Test the interaction of --bool and --get-regexp on a key with no explicit value","fromName":"Alex Vandiver","fromEmail":"alex@chmrr.net","sentAt":"2010-08-26T17:45:16Z","receivedAt":"2010-08-26T17:45:16Z","isPatch":true,"sender":{"key":"alex@chmrr.net","avatar":"https://avatars.githubusercontent.com/u/28347?v=4"},"body":"Signed-off-by: Alex Vandiver <alex@chmrr.net>\n---\n\nThis test currently fails -- I don't have time to track down the fix,\nbut I figured that at least I could provide a failing test.  Note that\n--null isn't necessary for the failure; without it, one gets\n\"section.sub=section.val5true\", with no spacing between the key and\nvalue.\n\n t/t1300-repo-config.sh |   10 ++++++++++\n 1 files changed, 10 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex 074f2f2..147e0e6 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -816,6 +816,16 @@ echo >>result\n \n test_expect_success '--null --get-regexp' 'cmp result expect'\n \n+cat > expect <<\\EOF\n+section.sub=section.val5\n+trueQ\n+EOF\n+\n+git config --null --bool --get-regexp 'val5' | perl -pe 'y/\\000/Q/' > result\n+echo >>result\n+\n+test_expect_success '--null --get-regexp --bool' 'cmp result expect'\n+\n test_expect_success 'inner whitespace kept verbatim' '\n \tgit config section.val \"foo \t  bar\" &&\n \ttest \"z$(git config section.val)\" = \"zfoo \t  bar\"\n-- \n1.7.2.2.458.g8d9c8\n"},{"id":"149085","messageId":"1282855775-22582-1-git-send-email-alex@chmrr.net","threadId":"24871","inReplyTo":"1282844716-30591-1-git-send-email-alex@chmrr.net","subject":"[PATCH] config: Print the delimeter of intuited --bool values under --get-regexp","fromName":"","fromEmail":"alex@chmrr.net","sentAt":"2010-08-26T20:49:35Z","receivedAt":"2010-08-26T20:49:35Z","isPatch":true,"sender":{"key":"alex@chmrr.net","avatar":"https://avatars.githubusercontent.com/u/28347?v=4"},"body":"From: Alex Vandiver <alex@chmrr.net>\n\nKeys with no explicit value set may still have values that need to be\nprinted, if used in conjunction with --bool, for example.  Defer\nprinting the key-value delimeter until we know what value, if any, we\nintend to output.\n\nSigned-off-by: Alex Vandiver <alex@chmrr.net>\n---\n\nI found a couple tuits under the couch; perhaps something like the\nfollowing would be correct.\n\n builtin/config.c |   20 ++++++++++++--------\n 1 files changed, 12 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/config.c b/builtin/config.c\nindex ca4a0db..98fd1ba 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -108,12 +108,9 @@ static int show_config(const char *key_, const char *value_, void *cb)\n \t    (do_not_match ^ !!regexec(regexp, (value_?value_:\"\"), 0, NULL, 0)))\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}\n+\tif (show_keys)\n+\t\tprintf(\"%s\", key_);\n+\n \tif (seen && !do_all)\n \t\tdup_error = 1;\n \tif (types == TYPE_INT)\n@@ -132,14 +129,21 @@ static int show_config(const char *key_, const char *value_, void *cb)\n \t\tmust_free_vptr = 1;\n \t}\n \telse\n-\t\tvptr = value_?value_:\"\";\n+\t\tvptr = value_;\n+\n+\tif (show_keys && vptr)\n+\t\tprintf(\"%c\", key_delim);\n+\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 if (vptr)\n \t\tprintf(\"%s%c\", vptr, term);\n+\telse\n+\t\tprintf(\"%c\", term);\n+\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\n-- \n1.7.2.2.458.g8d9c8\n"},{"id":"149102","messageId":"20100827031511.GC23924@burratino","threadId":"24871","inReplyTo":"1282844716-30591-1-git-send-email-alex@chmrr.net","subject":"Re: [PATCH] Test the interaction of --bool and --get-regexp on a key with no explicit value","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-08-27T03:15:11Z","receivedAt":"2010-08-27T03:15:11Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Alex Vandiver wrote:\n\n> Signed-off-by: Alex Vandiver <alex@chmrr.net>\n> ---\n> \n> This test currently fails -- I don't have time to track down the fix,\n> but I figured that at least I could provide a failing test.  Note that\n> --null isn't necessary for the failure; without it, one gets\n> \"section.sub=section.val5true\", with no spacing between the key and\n> value.\n\nThis is useful info (the motivation!) for the log mesage I think,\nthough it might be even better to squash the patch with the fix. :)\n\n> --- a/t/t1300-repo-config.sh\n> +++ b/t/t1300-repo-config.sh\n> @@ -816,6 +816,16 @@ echo >>result\n>  \n>  test_expect_success '--null --get-regexp' 'cmp result expect'\n>  \n> +cat > expect <<\\EOF\n> +section.sub=section.val5\n> +trueQ\n> +EOF\n> +\n> +git config --null --bool --get-regexp 'val5' | perl -pe 'y/\\000/Q/' > result\n> +echo >>result\n> +\n> +test_expect_success '--null --get-regexp --bool' 'cmp result expect'\n\nStyle nitpicks (based on the \"Do's, don'ts &\" c section of t/README):\n\n - setup code (cat >expect) belongs in the body of tests.\n   That way, it is clearer when each test begins and ends, and\n   unexpected failures and output from setup code will be\n   automatically noticed and suppressed, respectively.\n\n - there is no public nul_to_q () function but I still think it\n   is clearer to use one;\n\n - test_cmp is guaranteed to work just as well as cmp and produces\n   nicer output when tests run with \"-v\" fail.\n\nSo maybe:\n\n test_expect_failure '--get-regexp --bool still separates key and value' '\n\techo 'section.sub=section.val5 true' >expected &&\n\tgit config --bool --get-regexp val5 >actual &&\n\ttest_cmp expected acutal\n '\n\n test_expect_failure '--get-regexp --bool --null' '\n\tprintf \"%s\\n%s\\0\" \"section.sub=section.val5\" \"true\" >expected &&\n\tgit config -z --bool --get-regexp val5 >actual &&\n\ttest_cmp expected actual\n '\n\nThanks for reporting.\n"},{"id":"149103","messageId":"20100827031757.GD23924@burratino","threadId":"24871","inReplyTo":"1282855775-22582-1-git-send-email-alex@chmrr.net","subject":"Re: [PATCH] config: Print the delimeter of intuited --bool values under --get-regexp","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-08-27T03:17:57Z","receivedAt":"2010-08-27T03:17:57Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Alex Vandiver wrote:\n\n> @@ -132,14 +129,21 @@ static int show_config(const char *key_, const char *value_, void *cb)\n>  \t\tmust_free_vptr = 1;\n>  \t}\n>  \telse\n> -\t\tvptr = value_?value_:\"\";\n> +\t\tvptr = value_;\n[...]\n>  \tif (dup_error) {\n>  \t\terror(\"More than one value for the key %s: %s\",\n>  \t\t\t\tkey_, vptr);\n\nCould this segfault?\n"}]}