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

Re: [PATCH] completion: fix incorrect bash/zsh string equality check

From
Robert Estelle <robertestelle@gmail.com>
Date
Oct 25, 2021, 22:20 UTC
Message-ID
<CAMmwyQqSJRgQ+-tFwYSSw2FU9TJ0TbjP-M_1rJSmo7bFpLW76w@mail.gmail.com>
In-Reply-To
<xmqqzgrjglma.fsf@gitster.g>

I considered dropping this patch entirely since this discussion was going so far off the rails for a single-char fix, but I hate to leave things hanging…

Show 6 quoted lines
> When you do not mean pattern matching and want exact matching, even
> if it is guaranteed that the data you pass through the codepath does
> not have pattern to cause the former, hence the distinction between
> [[ x == y ]] and [ x = y ] does not make a difference, that is a
> mere happenstance, and use of [ x = y ] is the correct thing to do
> in such a case.

I think you've misread what's going on here, or might be misremembering the shell quoting rules (which would surprise me!).

My assertion about their equivalence was syntactic: there's no
happenstance or reliance on codepaths whatsoever.
If you write:
  [[ "$x" == "$y" ]]
then it doesn't matter what x and y contain. They're quoted: it's just
a literal string comparison of their values.
Their values can contain quotes, newlines, spaces, asterisks, emoji,
etc. and none of that gets any special interpretation.

Regardless, since they're functionally equivalent, I've pushed up a change to do it the other way and will submit that shortly.

Best, Robert

On Fri, Oct 8, 2021 at 4:09 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 21 quoted lines
>
> Robert Estelle <robertestelle@gmail.com> writes:
>
> > The choice between the two does not affect correctness, it's purely
> > stylistic here. It only would affect correctness for unquoted
> > arguments or extended comparison operators. Those *are* in use
> > elsewhere in this script and force the use of `[[` in those places.
> >
> > Keep in mind also that this is an autocomplete script. Although it's
> > sourced by both bash and zsh, it does not make sense to attempt to
> > make it work for bare POSIX sh.
>
> Nobody is trying to.  It is more for reducing the risk of people
> shooting their foot by cutting and pasting without thinking.
>
> When you do not mean pattern matching and want exact matching, even
> if it is guaranteed that the data you pass through the codepath does
> not have pattern to cause the former, hence the distinction between
> [[ x == y ]] and [ x = y ] does not make a difference, that is a
> mere happenstance, and use of [ x = y ] is the correct thing to do
> in such a case.
Previous: Junio C HamanoNext: Robert Estelle via GitGitGadget
Message 9 of 11 in “completion: fix incorrect bash/zsh string equality check”
  1. completion: fix incorrect bash/zsh string equality checkRobert Estelle via GitGitGadget, Oct 7, 2021
  2. Junio C HamanoOct 8, 2021
  3. brian m. carlsonOct 8, 2021
  4. Robert EstelleOct 8, 2021
  5. Robert EstelleOct 8, 2021
  6. Junio C HamanoOct 8, 2021
  7. Robert EstelleOct 8, 2021
  8. Junio C HamanoOct 8, 2021
  9. Robert EstelleOct 25, 2021
  10. completion: fix incorrect bash/zsh string equality checkRobert Estelle via GitGitGadget, Oct 25, 2021
  11. Junio C HamanoOct 28, 2021

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.