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

Re: [PATCH] builtin/config.c: don't print a newline with --color

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 2, 2019, 12:34 UTC
Message-ID
<CAPig+cQWCSVqXyOmBC9Wn-Ew79H0yGPRJxRiLCMNJjNOUu2yPw@mail.gmail.com>
In-Reply-To
<b5ca6391fd0273fb7d6b92bc5ada96df93bc5cf2.1551487219.git.me@ttaylorr.com>
On Fri, Mar 1, 2019 at 7:41 PM Taylor Blau <me@ttaylorr.com> wrote:
Show 5 quoted lines
> [...]
> In this case, printing a terminating newline is not desirable. Callers
> may want to print out such a configuration variable in a sub-shell in
> order to color something else, in which case they certainly don't want a
> newline.
It's extra confusing considering that this:
    color=$(git config --get --type=color foo.color)
    echo "${color}hello" >output
works as expected since $(...) swallows the newline, whereas, the case you cite:
    (
    git config --get --type=color foo.color &&
    echo hello
    ) >output
does not.

Illustrating the problem in the commit message by using example code like the above might (or might not) help the reader understand the issue more easily. (I had to read the prose description of the problem a couple times to properly understand it.) Not necessarily worth a re-roll.

Show 10 quoted lines
> To do what callers expect, only print a newline when the type is not
> 'color', and print the escape sequence itself for an exact comparison.
>
> Signed-off-by: Taylor Blau <me@ttaylorr.com>
> ---
> diff --git a/builtin/config.c b/builtin/config.c
> @@ -258,7 +258,8 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
> -       strbuf_addch(buf, term);
> +       if (type != TYPE_COLOR)
> +               strbuf_addch(buf, term);

The reasoning for this conditional is sufficiently subtle that it might deserve an in-code comment (though, perhaps is not worth a re-roll).

Previous: Taylor BlauNext: Johannes Schindelin
Message 2 of 18 in “builtin/config.c: don't print a newline with --color”
  1. builtin/config.c: don't print a newline with --colorTaylor Blau, Mar 2, 2019
  2. Eric SunshineMar 2, 2019
  3. Johannes SchindelinMar 2, 2019
  4. Jeff KingMar 3, 2019
  5. Johannes SchindelinMar 5, 2019
  6. Taylor BlauMar 6, 2019
  7. Junio C HamanoMar 3, 2019
  8. Jeff KingMar 3, 2019
  9. Junio C HamanoMar 4, 2019
  10. Junio C HamanoMar 4, 2019
  11. Jeff KingMar 5, 2019
  12. Junio C HamanoMar 5, 2019
  13. Taylor BlauMar 6, 2019
  14. Junio C HamanoMar 7, 2019
  15. Jeff KingMar 7, 2019
  16. Documentation/config: note trailing newline with --type=colorTaylor Blau, Mar 6, 2019
  17. Jeff KingMar 7, 2019
  18. Junio C HamanoMar 7, 2019

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.