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

Re: [RFC PATCH] quote: make sq_quote_buf_pretty() prettier

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Nov 30, 2026, 16:40 UTC
Message-ID
<311ab1f8-4d1a-43d7-843b-c19e28e51332@gmail.com>
In-Reply-To
<xmqqmrqt3ior.fsf@gitster.g>
On 28/11/2026 00:26, Junio C Hamano wrote:
Show 6 quoted lines
> Phillip Wood <phillip.wood123@gmail.com> writes:
> > I forgot to mention a couple of things.
> >> ... It also adds unnecessary pairs
>> of empty quotes when a string starts or ends with a single quote.
> > "a single quote or an exclamation point."  We can see the example in the
> table you have below, for the entry for 'danger!'.
I'll add that
Show 20 quoted lines
>> +	for (q = p; *q; q++) {
>> +		if (need_bs_quote(*q)) {
>> +			if (brace)
>> +				quote_it = true;
>> +			if (quote_it)
>> +				strbuf_addch(dst, '\'');
>> +			strbuf_add(dst, p, q - p);
>> +			p = q + 1;
>> +			if (quote_it)
>> +				strbuf_addch(dst, '\'');
>> +			strbuf_addch(dst, '\\');
>> +			strbuf_addch(dst, *q);
>> +			if (!brace)
>> +				quote_it = false;
> > When brace > 0, quote_it stays true after emitting the backslash-escaped
> character.
> > If the next character also needs backslash quoting (such as "{a'!b}"),
> or if the string ends right there with an unclosed brace (such as "{!",
> p == q (i.e., an empty segment) but we emit it in a pair of single
> quotes.
Good point
Show 12 quoted lines
> After the loop, here also is an instance of single quote pair around
> potentially an empty segment.  Perhaps a short helper or macro that does
> an equivalent of
> > 	if (p < q) {
> 		if (quote_it)
> 			strbuf_addch(dst, '\'');
> 		strbuf_add(dst, p, q - p);
> 		if (quote_it)
> 			strbuf_addch(dst, '\'');
> 	}		
> > and use it twice (the bs-quote code path needs to be slightly rewritten
> if we wanted to share this piece of code that way)?
That's a good idea
Thanks
Phillip
> >>   }
>>   >>   void sq_quotef(struct strbuf *dst, const char *fmt, ...)
Previous: Junio C HamanoNext: D. Ben Knoble
Message 7 of 10 in “quote: make sq_quote_buf_pretty() prettier”
  1. quote: make sq_quote_buf_pretty() prettierPhillip Wood, Nov 27, 2026
  2. Nahid hasan SagorNov 27, 2026
  3. Phillip WoodNov 30, 2026
  4. Junio C HamanoNov 27, 2026
  5. Phillip WoodNov 30, 2026
  6. Junio C HamanoNov 28, 2026
  7. Phillip WoodNov 30, 2026
  8. D. Ben KnobleNov 30, 2026
  9. Phillip WoodNov 30, 2026
  10. D. Ben KnobleNov 30, 2026

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.