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

Re: [PATCH 3/3] wt-status: use "format" function attribute for status_printf

From
Jeff King <peff@peff.net>
Date
Jul 10, 2013, 06:11 UTC
Message-ID
<20130710061115.GA11741@sigill.intra.peff.net>
In-Reply-To
<7vehb7t0zs.fsf@alter.siamese.dyndns.org>
On Tue, Jul 09, 2013 at 10:52:55PM -0700, Junio C Hamano wrote:
Show 17 quoted lines
> > The patch to do it is below, but I actually think an explicit blank-line
> > function like:
> >
> >   status_print_empty_line(s, color);
> >
> > would be more obvious to a reader.
> 
> I noticed that all but one can be dealt with with
> 
>     perl -p -i -e 's/status_printf_ln\((.*), ""\);/status_printf($1, "\\n");/'
> 
> That is,
> 
> -	status_printf_ln(s, GIT_COLOR_NORMAL, "");
> +	status_printf(s, GIT_COLOR_NORMAL, "\n");
> 
> which does not look _too_ bad.

Is that correct, though? The reason we have *_printf_ln in the first place is that we want to do:

  ${color}content${reset}\n

to make sure that the newline does not happen inside the colorization. At least that is why I added color_printf_ln long ago.

It would probably improve the code quite a bit if we could simply feed multi-line strings to status_printf, and have it stick the colorization in the correct spot of each line. And hmm...it kind of looks like status_vprintf already does that. Now I'm puzzled why many of these do not simply include the newline along with the string being printed.

> There is one instance that needs this, though.
> 
> -		status_printf(s, color(WT_STATUS_HEADER, s), "");
> +		status_printf(s, color(WT_STATUS_HEADER, s), "%s", "");

Hmm, yeah. It cannot be combined with the lines following it, either, because they are using different colorization.

If you want to keep refactoring this, I don't mind, but I kind of feel like we are going down a rabbit hole for very little gain.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 14 of 17 in “remote-http: use argv-array”
  1. remote-http: use argv-arrayJunio C Hamano, Jul 9, 2013
  2. Bert WesargJul 9, 2013
  3. Jeff KingJul 9, 2013
  4. Matt KraaiJul 9, 2013
  5. Jeff KingJul 10, 2013
  6. 1/3 add missing "format" function attributesJeff King, Jul 10, 2013
  7. 2/3 use "sentinel" function attribute for variadic listsJeff King, Jul 10, 2013
  8. 3/3 wt-status: use "format" function attribute for status_printfJeff King, Jul 10, 2013
  9. Junio C HamanoJul 10, 2013
  10. Jeff KingJul 10, 2013
  11. Junio C HamanoJul 10, 2013
  12. Jeff KingJul 10, 2013
  13. Junio C HamanoJul 10, 2013
  14. Jeff KingJul 10, 2013
  15. Junio C HamanoJul 10, 2013
  16. Junio C HamanoJul 12, 2013
  17. Jeff KingJul 12, 2013

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.