git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Christian Couder <chriscool@tuxfamily.org>
Cc: Johannes Sixt <j.sixt@viscovery.net>,
	Pierre Habouzit <madcoder@debian.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	git@vger.kernel.org
Subject: Re: [PATCH] config: deprecate using "" as boolean value false.
Date: Mon, 11 Feb 2008 00:46:09 -0800	[thread overview]
Message-ID: <7vmyq7anji.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <7vskzzaoop.fsf@gitster.siamese.dyndns.org> (Junio C. Hamano's message of "Mon, 11 Feb 2008 00:21:26 -0800")

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;
 	}

  reply	other threads:[~2008-02-11  8:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-11  7:22 [PATCH] config: deprecate using "" as boolean value false Christian Couder
2008-02-11  8:21 ` Junio C Hamano
2008-02-11  8:46   ` Junio C Hamano [this message]
2008-02-11  9:22     ` [PATCH] teach config parsers to diagnose missing values Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vmyq7anji.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=j.sixt@viscovery.net \
    --cc=madcoder@debian.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).