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

[PATCH] config: Print the delimeter of intuited --bool values under --get-regexp

From
alex@chmrr.net <alex@chmrr.net>
Date
Aug 26, 2010, 20:49 UTC
Message-ID
<1282855775-22582-1-git-send-email-alex@chmrr.net>
In-Reply-To
<1282844716-30591-1-git-send-email-alex@chmrr.net>
From: Alex Vandiver <alex@chmrr.net>

Keys with no explicit value set may still have values that need to be printed, if used in conjunction with --bool, for example. Defer printing the key-value delimeter until we know what value, if any, we intend to output.

Signed-off-by: Alex Vandiver <alex@chmrr.net>
---

I found a couple tuits under the couch; perhaps something like the following would be correct.

 builtin/config.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/builtin/config.c b/builtin/config.c
index ca4a0db..98fd1ba 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -108,12 +108,9 @@ static int show_config(const char *key_, const char *value_, void *cb)
 	    (do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0)))
 		return 0;
 
-	if (show_keys) {
-		if (value_)
-			printf("%s%c", key_, key_delim);
-		else
-			printf("%s", key_);
-	}
+	if (show_keys)
+		printf("%s", key_);
+
 	if (seen && !do_all)
 		dup_error = 1;
 	if (types == TYPE_INT)
@@ -132,14 +129,21 @@ static int show_config(const char *key_, const char *value_, void *cb)
 		must_free_vptr = 1;
 	}
 	else
-		vptr = value_?value_:"";
+		vptr = value_;
+
+	if (show_keys && vptr)
+		printf("%c", key_delim);
+
 	seen++;
 	if (dup_error) {
 		error("More than one value for the key %s: %s",
 				key_, vptr);
 	}
-	else
+	else if (vptr)
 		printf("%s%c", vptr, term);
+	else
+		printf("%c", term);
+
 	if (must_free_vptr)
 		/* If vptr must be freed, it's a pointer to a
 		 * dynamically allocated buffer, it's safe to cast to
-- 
1.7.2.2.458.g8d9c8
Previous: Alex VandiverNext: Jonathan Nieder
Message 2 of 4 in “Test the interaction of --bool and --get-regexp on a key with no explicit value”
  1. Test the interaction of --bool and --get-regexp on a key with no explicit valueAlex Vandiver, Aug 26, 2010
  2. config: Print the delimeter of intuited --bool values under --get-regexpalex@chmrr.net, Aug 26, 2010
  3. Jonathan NiederAug 27, 2010
  4. Jonathan NiederAug 27, 2010

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.