From 9be04d64c9b45a37cba161ba2eff2e784f87f91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C3=85gren?= Date: Mon, 7 Aug 2017 20:20:47 +0200 Subject: config: introduce git_parse_maybe_bool_text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 9a549d43 ("config.c: rename git_config_maybe_bool_text and export it as git_parse_maybe_bool", 2015-08-19) intended git_parse_maybe_bool to be a replacement for git_config_maybe_bool, which could then be retired. That is not obvious from the commit message, but that is what the background on the mailing list suggests [1]. However, git_{config,parse}_maybe_bool do not handle all input the same. Before the rename, that was by design and there is a caller in config.c which requires git_parse_maybe_bool to behave exactly as it does. Prepare for the next patch by renaming git_parse_maybe_bool to ..._text and reimplementing the first one as a simple call to the second one. Let the existing users in config.c use ..._text, since it does what they need. [1] https://public-inbox.org/git/xmqq7fotd71o.fsf@gitster.dls.corp.google.com/ Signed-off-by: Martin Ågren Signed-off-by: Junio C Hamano --- config.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index c6b874a7b..ce763c824 100644 --- a/config.c +++ b/config.c @@ -709,7 +709,7 @@ unsigned long git_config_ulong(const char *name, const char *value) return ret; } -int git_parse_maybe_bool(const char *value) +static int git_parse_maybe_bool_text(const char *value) { if (!value) return 1; @@ -726,9 +726,14 @@ int git_parse_maybe_bool(const char *value) return -1; } +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(value); + int v = git_parse_maybe_bool_text(value); if (0 <= v) return v; if (git_parse_int(value, &v)) @@ -738,7 +743,7 @@ int git_config_maybe_bool(const char *name, const char *value) int git_config_bool_or_int(const char *name, const char *value, int *is_bool) { - int v = git_parse_maybe_bool(value); + int v = git_parse_maybe_bool_text(value); if (0 <= v) { *is_bool = 1; return v; -- cgit v1.2.1 From 4666741823239ed45ce9a63914dfd3c1601cf868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C3=85gren?= Date: Mon, 7 Aug 2017 20:20:48 +0200 Subject: config: make git_{config,parse}_maybe_bool equivalent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- config.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index ce763c824..25d798f4c 100644 --- 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); -- cgit v1.2.1 From 8957661378b073b49875059d6426614facb0d7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C3=85gren?= Date: Mon, 7 Aug 2017 20:20:49 +0200 Subject: treewide: deprecate git_config_maybe_bool, use git_parse_maybe_bool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only difference between these is that the former takes an argument `name` which it ignores completely. Still, the callers are quite careful to provide reasonable values for it. Once in-flight topics have landed, we should be able to remove git_config_maybe_bool. In the meantime, document it as deprecated in the technical documentation. While at it, document git_parse_maybe_bool. Signed-off-by: Martin Ågren Signed-off-by: Junio C Hamano --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index 25d798f4c..434a7daf1 100644 --- a/config.c +++ b/config.c @@ -1617,7 +1617,7 @@ int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *de { const char *value; if (!git_configset_get_value(cs, key, &value)) { - *dest = git_config_maybe_bool(key, value); + *dest = git_parse_maybe_bool(value); if (*dest == -1) return -1; return 0; -- cgit v1.2.1