{"thread":{"id":"26100","subject":"[PATCH] handle arbitrary ints in git_config_maybe_bool","startedAt":"2010-12-19T03:36:41Z","lastAt":"2010-12-21T00:49:00Z","messageCount":2,"participants":["Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"158353","messageId":"20101219033640.GA6889@sigill.intra.peff.net","threadId":"26100","inReplyTo":null,"subject":"[PATCH] handle arbitrary ints in git_config_maybe_bool","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-12-19T03:36:41Z","receivedAt":"2010-12-19T03:36:41Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This function recently gained the ability to recognize the\ndocumented \"0\" and \"1\" values as false/true. However, unlike\nregular git_config_bool, it did not treat arbitrary numbers\nas true. While this is undocumented and probably ridiculous\nfor somebody to rely on, it is safer to behave exactly as\ngit_config_bool would. Because git_config_maybe_bool can be\nused to retrofit new non-bool values onto existing bool\noptions, not behaving in exactly the same way is technically\na regression.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThis was posted earlier as part of the command-specific pager topic; you\nended up splitting part of that out into jk/maint-decorate-01-bool. This\nshould logically go on top of that (b2be2f6).\n\nIt probably doesn't make a difference in the real world, but I think it\nis safer (as described above), and the code is a little cleaner. I\nshould have just done it this way in the first place.\n\n config.c |    8 +++-----\n 1 files changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 32c0b2c..d73b090 100644\n--- a/config.c\n+++ b/config.c\n@@ -429,13 +429,11 @@ static int git_config_maybe_bool_text(const char *name, const char *value)\n \n int git_config_maybe_bool(const char *name, const char *value)\n {\n-\tint v = git_config_maybe_bool_text(name, value);\n+\tlong v = git_config_maybe_bool_text(name, value);\n \tif (0 <= v)\n \t\treturn v;\n-\tif (!strcmp(value, \"0\"))\n-\t\treturn 0;\n-\tif (!strcmp(value, \"1\"))\n-\t\treturn 1;\n+\tif (git_parse_long(value, &v))\n+\t\treturn !!v;\n \treturn -1;\n }\n \n-- \n1.7.3.4.761.g98ad5\n"},{"id":"158423","messageId":"7vfwtsar2b.fsf@alter.siamese.dyndns.org","threadId":"26100","inReplyTo":"20101219033640.GA6889@sigill.intra.peff.net","subject":"Re: [PATCH] handle arbitrary ints in git_config_maybe_bool","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-12-21T00:49:00Z","receivedAt":"2010-12-21T00:49:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> This function recently gained the ability to recognize the\n> documented \"0\" and \"1\" values as false/true. However, unlike\n> regular git_config_bool, it did not treat arbitrary numbers\n> as true. While this is undocumented and probably ridiculous\n> for somebody to rely on, it is safer to behave exactly as\n> git_config_bool would. Because git_config_maybe_bool can be\n> used to retrofit new non-bool values onto existing bool\n> options, not behaving in exactly the same way is technically\n> a regression.\n>\n> Signed-off-by: Jeff King <peff@peff.net>\n> ---\n> This was posted earlier as part of the command-specific pager topic; you\n> ended up splitting part of that out into jk/maint-decorate-01-bool. This\n> should logically go on top of that (b2be2f6).\n>\n> It probably doesn't make a difference in the real world, but I think it\n> is safer (as described above), and the code is a little cleaner. I\n> should have just done it this way in the first place.\n\nI'd reword \"arbitrary numbers\" to \"arbitrary non-zero numbers\".\nOther than that, thanks for your attention to the details.\n\nWill apply.\n\n>  config.c |    8 +++-----\n>  1 files changed, 3 insertions(+), 5 deletions(-)\n>\n> diff --git a/config.c b/config.c\n> index 32c0b2c..d73b090 100644\n> --- a/config.c\n> +++ b/config.c\n> @@ -429,13 +429,11 @@ static int git_config_maybe_bool_text(const char *name, const char *value)\n>  \n>  int git_config_maybe_bool(const char *name, const char *value)\n>  {\n> -\tint v = git_config_maybe_bool_text(name, value);\n> +\tlong v = git_config_maybe_bool_text(name, value);\n>  \tif (0 <= v)\n>  \t\treturn v;\n> -\tif (!strcmp(value, \"0\"))\n> -\t\treturn 0;\n> -\tif (!strcmp(value, \"1\"))\n> -\t\treturn 1;\n> +\tif (git_parse_long(value, &v))\n> +\t\treturn !!v;\n>  \treturn -1;\n>  }\n>  \n> -- \n> 1.7.3.4.761.g98ad5\n"}]}