From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: Ben Knoble <ben.knoble@gmail.com>,
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org, Harald Nordgren <haraldnordgren@gmail.com>,
nahidhasan141400@gmail.com
Subject: Re: [PATCH] config: make the suggested "set" command safe to paste
Date: Thu, 26 Nov 2026 10:26:43 -0800 [thread overview]
Message-ID: <xmqqpkvrmot8.fsf@gitster.g> (raw)
In-Reply-To: <607d6273-14ba-4005-b038-3778ad2812fe@gmail.com> (Phillip Wood's message of "Thu, 26 Nov 2026 14:56:14 +0000")
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.
> 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.
next prev parent reply other threads:[~2026-11-26 18:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 18:54 [PATCH] config: make the suggested "set" command safe to paste Harald Nordgren via GitGitGadget
2026-11-26 12:30 ` Ben Knoble
2026-11-26 14:56 ` Phillip Wood
2026-11-26 15:06 ` Ben Knoble
2026-11-26 18:26 ` Junio C Hamano [this message]
2026-11-26 15:00 ` Phillip Wood
2026-11-28 18:13 ` [PATCH v2] " Harald Nordgren via GitGitGadget
2026-11-29 16:08 ` Phillip Wood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqpkvrmot8.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=ben.knoble@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=haraldnordgren@gmail.com \
--cc=nahidhasan141400@gmail.com \
--cc=phillip.wood123@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox