git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/6] config: make git_{config,parse}_maybe_bool equivalent

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Aug 7, 2017, 18:20 UTC
Message-ID
<74e20299473958b2279ee62d311cbf906b709952.1502128418.git.martin.agren@gmail.com>
In-Reply-To
<cover.1502128418.git.martin.agren@gmail.com>

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>
---
 t/t5534-push-signed.sh |  2 +-
 config.c               | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/t/t5534-push-signed.sh b/t/t5534-push-signed.sh
index 5dce55e1d..1cea758f7 100755
--- a/t/t5534-push-signed.sh
+++ b/t/t5534-push-signed.sh
@@ -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 &&
diff --git a/config.c b/config.c
index 7df57cec0..d87376a5d 100644
--- a/config.c
+++ b/config.c
@@ -946,11 +946,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)
@@ -960,6 +955,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);
-- 
2.14.0.5.g0f7b1ed27
Previous: Martin ÅgrenNext: Martin Ågren
Message 6 of 13 in “clean up parsing of maybe_bool”
  1. 0/6 clean up parsing of maybe_boolMartin Ågren, Aug 7, 2017
  2. 1/6 Doc/git-{push,send-pack}: correct --sign= to --signed=Martin Ågren, Aug 7, 2017
  3. 2/6 t5334: document that git push --signed=1 does not workMartin Ågren, Aug 7, 2017
  4. Junio C HamanoAug 7, 2017
  5. 3/6 config: introduce git_parse_maybe_bool_textMartin Ågren, Aug 7, 2017
  6. 4/6 config: make git_{config,parse}_maybe_bool equivalentMartin Ågren, Aug 7, 2017
  7. 5/6 treewide: deprecate git_config_maybe_bool, use git_parse_maybe_boolMartin Ågren, Aug 7, 2017
  8. 6/6 parse_decoration_style: drop unused argument `var`Martin Ågren, Aug 7, 2017
  9. Stefan BellerAug 7, 2017
  10. Junio C HamanoAug 7, 2017
  11. Martin ÅgrenAug 8, 2017
  12. Junio C HamanoAug 8, 2017
  13. Martin ÅgrenAug 8, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.