From: alex@chmrr.net Date: Thu, 26 Aug 2010 20:49:35 GMT Subject: [PATCH] config: Print the delimeter of intuited --bool values under --get-regexp 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 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 --- 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