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

Re: [PATCH] config: deprecate using "" as boolean value false.

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 11, 2008, 08:46 UTC
Message-ID
<7vmyq7anji.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<7vskzzaoop.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
> So far I've seen and queued only two usable fixes since that
> [Janitor] request.  Maybe I should have ignored all this
> discussion in this thread and spent my time on doing the
> Janitorial work.

In the thread I mentioned erroring out when a value we expect is missing instead of silently ignoring such a misconfiguration, and I showed an incorrect example of doing so using die().

The caller of the callback reports the line number and the filename upon error. So we should just return an error and let the caller do the more detailed reporting.

With this patch, a misconfiguration:
	[apply]
        	whitespace
will result in:
	$ git apply
        error: Missing value for 'apply.whitespace'
        fatal: bad config file line 29 in .git/config
which is much nicer.
---
 cache.h         |    1 +
 config.c        |    9 +++++++++
 builtin-apply.c |    2 ++
 3 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/cache.h b/cache.h
index 549f4bb..6abcee4 100644
--- a/cache.h
+++ b/cache.h
@@ -589,6 +589,7 @@ extern int git_config_set_multivar(const char *, const char *, const char *, int
 extern int git_config_rename_section(const char *, const char *);
 extern const char *git_etc_gitconfig(void);
 extern int check_repository_format_version(const char *var, const char *value);
+extern int config_error_nonbool(const char *);
 
 #define MAX_GITNAME (1000)
 extern char git_default_email[MAX_GITNAME];
diff --git a/config.c b/config.c
index 498259e..e9a9a6f 100644
--- a/config.c
+++ b/config.c
@@ -1074,3 +1074,12 @@ int git_config_rename_section(const char *old_name, const char *new_name)
 	free(config_filename);
 	return ret;
 }
+
+/*
+ * Call this to report error for your variable that should not
+ * get a boolean value (i.e. "[my] var" means "true").
+ */
+int config_error_nonbool(const char *var)
+{
+	return error("Missing value for '%s'", var);
+}
diff --git a/builtin-apply.c b/builtin-apply.c
index 15432b6..a11b1bb 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2746,6 +2746,8 @@ static int apply_patch(int fd, const char *filename, int inaccurate_eof)
 static int git_apply_config(const char *var, const char *value)
 {
 	if (!strcmp(var, "apply.whitespace")) {
+		if (!value)
+			return config_error_nonbool(var);
 		apply_default_whitespace = xstrdup(value);
 		return 0;
 	}
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 4 in “config: deprecate using "" as boolean value false.”
  1. config: deprecate using "" as boolean value false.Christian Couder, Feb 11, 2008
  2. Junio C HamanoFeb 11, 2008
  3. Junio C HamanoFeb 11, 2008
  4. teach config parsers to diagnose missing valuesJunio C Hamano, Feb 11, 2008

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.