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

Re: git-grep's "-z" option misbehaves in subdirectory

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 16, 2020, 20:07 UTC
Message-ID
<xmqq1ronyz1s.fsf@gitster.c.googlers.com>
In-Reply-To
<CAHd-oW4NK3E2umq9OXXW9TUyLKQwWN4R-b1KKK117tWPc=K7aw@mail.gmail.com>
Matheus Tavares Bernardino <matheus.bernardino@usp.br> writes:
Show 14 quoted lines
> Note that, differently from other Git commands, "-z" doesn't affect
> quoting/escaping in git-grep. For example, while git-ls-files' man
> page says:
>
> -z
>       \0 line termination on output **and do not quote filenames**.
>
> The git-grep one only says:
>
> -z, --null
>       Output \0 instead of the character that normally follows a file name.
>
> Indeed, this inconsistency might be a little confusing. The reason for
> it may be ...

Let me lift the need for speculation ;-) It was a simple oversight when the documentation was writte, and those "add relative with quoting" were bugs that not many people thought of testing with -z output mode. It is unfortunate, but it happens that things fall into cracks without anybody noticing X-<.

The reason why we quote paths in output from various commands without -z is to make them machine parseable; there is no reason to quote if \0 delimiting is used as no paths contain NUL byte in it.

> 1.  Make git-grep more consistent with other Git commands by always
> quoting/escaping unusual pathnames (relative or not), unless "-z" is
> given or core.quotePath is set to "false".
This is the only sensible way forward, I would think.
Previous: Matheus Tavares BernardinoNext: Matheus Tavares
Message 5 of 13 in “git-grep's "-z" option misbehaves in subdirectory”
  1. Greg HurrellApr 13, 2020
  2. Junio C HamanoApr 13, 2020
  3. Matheus Tavares, Apr 14, 2020
  4. Matheus Tavares BernardinoApr 16, 2020
  5. Junio C HamanoApr 16, 2020
  6. grep: follow conventions for printing paths w/ unusual charsMatheus Tavares, Apr 17, 2020
  7. Junio C HamanoApr 17, 2020
  8. Matheus Tavares BernardinoApr 17, 2020
  9. Junio C HamanoApr 17, 2020
  10. Johannes SchindelinApr 18, 2020
  11. Johannes SchindelinApr 18, 2020
  12. Matheus Tavares BernardinoApr 19, 2020
  13. grep: follow conventions for printing paths w/ unusual charsMatheus Tavares, Apr 19, 2020

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.