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

Re: [PATCH v9] json_writer: new routines to create JSON data

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 12, 2018, 20:49 UTC
Message-ID
<xmqqfu1r91dc.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180612202201.94733-2-git@jeffhostetler.com>
git@jeffhostetler.com writes:
Show 10 quoted lines
> +static void indent_pretty(struct json_writer *jw)
> +{
> +	int k;
> +
> +	if (!jw->pretty)
> +		return;
> +
> +	for (k = 0; k < jw->open_stack.len; k++)
> +		strbuf_addstr(&jw->json, "  ");
> +}
Show 8 quoted lines
> +static void array_common(struct json_writer *jw)
> +{
> +	assert_in_array(jw);
> +	maybe_add_comma(jw);
> +
> +	if (jw->pretty)
> +		strbuf_addch(&jw->json, '\n');
> +	indent_pretty(jw);
Make it
	if (jw->pretty) {
		strbuf_addch(&jw->json, '\n');
		indent_pretty(jw);
	}
and lose "be noop unless jw->pretty" check from the indent function.

Most other codepaths that cares about pretty printing state use that "I check and decide to (or not to) call helpers that unconditionally do" pattern, and the way indent_pretty() is used in the patch stands out like a sore thumb.

Previous: Eric Sunshine
Message 4 of 4 in “json_writer V9”
  1. json_writer V9git@jeffhostetler.com, Jun 12, 2018
  2. json_writer: new routines to create JSON datagit@jeffhostetler.com, Jun 12, 2018
  3. Eric SunshineJun 12, 2018
  4. Junio C HamanoJun 12, 2018

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.