Re: [PATCH] config: make the suggested "set" command safe to paste
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 26, 2026, 18:26 UTC
- Message-ID
- <xmqqpkvrmot8.fsf@gitster.g>
- In-Reply-To
- <607d6273-14ba-4005-b038-3778ad2812fe@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
> sq_quote_buf_pretty() is intended for that use case, so we already have > a central location for that logic.
FWIW, as the inventor of the sq_quote() family of helper functions, I did NOT know that we were allowed to futz with what the sq_quote_buf_pretty() class of helpers produce without having to worry about machine readability and output stability.
That is even though we prominently document them like this:
These should only be used for human-readable output, as sq_dequote() is not smart enough to dequote it.
Two things that come to mind are (1) we may need to find a way to make it even more prominent, and (2) "smart enough" will become irrelevant once we start aiming to cater to the user's shell, as predictability is what sq_dequote() is about, and compatibility with different "faviourite of the year" shells directly contradicts that goal.
Show 5 quoted lines
> The output could be prettier though, in particular in would be nice to > avoid the redundant pairs of single quotes at the beginning and end of > ''\''hello there'\''' so that it produced \''hello there'\' > instead. "'hello there'" would be even prettier but would take more > work.
Yes, but I am not sure if going _specific_ to a single chosen shell, perhaps via user.shellsyntax = (sh|fish|csh|psh|ksh|...), is a good direction in general. There are folks who script in one and interact in another shell.
And no, going _generic_ to be usable by _any_ shells we care about is a direction I do not think we want to go. If backslash becomes active even inside a pair of single quotes in some but not all shells, then we must avoid inter-shell ambiguity by not using backslash while inside a single-quoted environment, by first closing the currently active single quote, giving a double-backslash (assuming that it is universally accepted as a single backslash character by everybody), and then going back to another single-quoted environment, e.g., "'abc'\\'xyz'", which is the familiar ugliness of our sq_quote() output. That kind of ugly output will be needed to be usable by everybody, but then even though it may be cut-and-paste-able, will it still be understandable?
My pessimistic but practical side is tempted to say that it is a lost cause to aim for cut-and-paste-ready output. Rather, we may be better off if we give output that shows clear boundaries between each "parameter" to "commands", and have the user express that in their chosen shell.
[Footnote]
* 6fb737be5e ([PATCH] Make sq_expand() available as sq_quote()., 2005-07-07) introduced the sq- (stands for single-quote) quote mechanism as an externally available API function. 1fbdab21bb (trace: avoid unnecessary quoting, 2018-01-15) added _pretty() as a "human readable" variant, the first target being the output from tracing.
The principles laid out there for "pretty" are worth noting:
Trace output doesn't necessarily need to be shell-compatible,
but:
- the shell language is a good ballpark for what humans
consider readable (well, humans versed in command line
tools) - the run_command bits can be cut-and-pasted to a shell,
and we'll keep that property - it covers any cases which would make the output
visually ambiguous (e.g., embedded whitespace or quotes)My reference to "clear boundaries" is about the third point.