config: make git_{config,parse}_maybe_bool equivalent
authorMartin Ågren <martin.agren@gmail.com>
Mon, 7 Aug 2017 18:20:48 +0000 (20:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Aug 2017 20:27:24 +0000 (13:27 -0700)
Both of these act on a string `value` which they parse as a boolean. The
"parse"-variant was introduced as a replacement for the "config"-variant
which for historical reasons takes an unused argument `name`. That it
was intended as a replacement is not obvious from commit 9a549d43
("config.c: rename git_config_maybe_bool_text and export it as
git_parse_maybe_bool", 2015-08-19), but that is what the background on
the mailing list suggests [1].

However, these two functions do not parse `value` in exactly the same
way. In particular, git_config_maybe_bool accepts integers (0 for false,
non-0 for true). This means there are two slightly different definitions
of "maybe_bool" in the code-base, and that every time a call to
git_config_maybe_bool is changed to use git_parse_maybe_bool, it risks
breaking someone's workflow.

Move the implementation of "config" into "parse" and make the latter a
trivial wrapper.

This also fixes the only user of git_parse_maybe_bool, `git push
--signed=..`.

[1] https://public-inbox.org/git/xmqq7fotd71o.fsf@gitster.dls.corp.google.com/

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c
t/t5534-push-signed.sh
index ce763c824c3b03de4691a071cf778779e5acd27b..25d798f4cffe6e74884641c35135d0652c85b110 100644 (file)
--- a/config.c
+++ b/config.c
@@ -727,11 +727,6 @@ static int git_parse_maybe_bool_text(const char *value)
 }
 
 int git_parse_maybe_bool(const char *value)
-{
-       return git_parse_maybe_bool_text(value);
-}
-
-int git_config_maybe_bool(const char *name, const char *value)
 {
        int v = git_parse_maybe_bool_text(value);
        if (0 <= v)
@@ -741,6 +736,11 @@ int git_config_maybe_bool(const char *name, const char *value)
        return -1;
 }
 
+int git_config_maybe_bool(const char *name, const char *value)
+{
+       return git_parse_maybe_bool(value);
+}
+
 int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
 {
        int v = git_parse_maybe_bool_text(value);
index 591a26278d1e75d4a666c9ae88ed08ec9f1f7020..f88487bea2121ca3245b79592b786252b6935e7a 100755 (executable)
@@ -71,7 +71,7 @@ test_expect_success 'push --signed fails with a receiver without push certificat
        test_i18ngrep "the receiving end does not support" err
 '
 
-test_expect_failure 'push --signed=1 is accepted' '
+test_expect_success 'push --signed=1 is accepted' '
        prepare_dst &&
        mkdir -p dst/.git/hooks &&
        test_must_fail git push --signed=1 dst noop ff +noff 2>err &&