In a future commit, we'll be adding some additional shell-related
handling which logically belongs to the subprocess package. To avoid an
import loop, move the ShellQuote function and its required variable from
the tools package to the subprocess package. Update the only caller of
this function.
This commit contains no functional change.
In certain cases, such as the GIT_SSH_COMMAND environment variable,
we'll need to pass data to the shell. Since some of our arguments
contain spaces, we'll need to quote those values. Introduce a function
to quote strings so that they're suitable for the shell. For
simplicity's sake, assume anything beyond identifier characters, dot, at
sign, and hyphen-minus needs to be quoted and use single quotes for
doing so. Handle single quotes in a string in the same way as Git does.
If a quote is empty on its own, i.e., '', match an empty string. Otherwise, if
the quote is empty and inside another set of balanced quotes, treat it as-is,
i.e., "foo """ matches []string{"foo \"\""}.