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

Re: [PATCH] worktree: add -z option for list subcommand

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Feb 28, 2022, 08:35 UTC
Message-ID
<CAPig+cQF3y64bPN8h4XvAYGX-g0LZedh-cAM+JLKdW_DPAWJaw@mail.gmail.com>
In-Reply-To
<xmqqh78mesj6.fsf@gitster.g>
On Fri, Feb 25, 2022 at 12:59 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
> "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:
> > +-z::
> > +     When `--porcelain` is specified with `list` terminate each line with a
> > +     NUL rather than a newline. This makes it possible to parse the output
> > +     when a worktree path contains a newline character.
>
> This makes it sound as if it were impossible.  As the changes this
> patch makes to the documentation and the code indicate, we were
> already doing quote_c_style(), so it is not quite correct to say so.
>
> Perhaps "makes it easier" is more accurate?
>
> Unless the original wasn't using quote_c_style() correctly and
> wasn't quoting its output, that is?

That's the case. It is impossible without this patch since `git worktree list --porcelain` does not call quote_c_style() for the worktree path; it only calls quote_c_style() for the lock reason. Fixing this oversight for the worktree path for non-`-z` mode has potential backward-compatibility concerns. I had argued[1] that we might be able to sell it as a pure bug fix, but Phillip was concerned[2] that it might break existing tooling. (I also share that concern, but to a lesser degree, perhaps, since worktrees with oddball names containing newline or a leading double-quote must be exceedingly rare.)

[1]: https://lore.kernel.org/git/CAPig+cQq_RnanDQ3jHfNz_L58WyzmsUJBhtdrLxa=H0v_io+WA@mail.gmail.com/ [2]: https://lore.kernel.org/git/936f9b7c-6d54-00bc-f136-4cb4c2836eb6@gmail.com/

Show 8 quoted lines
> > +             if (line_terminator) {
> > +                     quote_c_style(reason, &sb, NULL, 0);
> > +                     reason = sb.buf;
> > +             }
> > +             printf("locked %s%c", reason, line_terminator);
>
> OK.  I suspect write_name_quoted() may be a better fit that does not
> require us to have our own strbuf, but this should be OK.
Nice suggestion.
Previous: Junio C HamanoNext: Phillip Wood
Message 3 of 14 in “worktree: add -z option for list subcommand”
  1. worktree: add -z option for list subcommandPhillip Wood via GitGitGadget, Feb 25, 2022
  2. Junio C HamanoFeb 25, 2022
  3. Eric SunshineFeb 28, 2022
  4. Phillip WoodFeb 28, 2022
  5. Junio C HamanoFeb 28, 2022
  6. Phillip WoodFeb 28, 2022
  7. Eric SunshineFeb 28, 2022
  8. Phillip WoodFeb 28, 2022
  9. Jean-Noël AvilaFeb 28, 2022
  10. Phillip WoodFeb 28, 2022
  11. worktree: add -z option for list subcommandPhillip Wood via GitGitGadget, Mar 31, 2022
  12. Junio C HamanoMar 31, 2022
  13. Phillip WoodApr 4, 2022
  14. Eric SunshineMay 11, 2023

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.