Re: [PATCH 5/7] worktree: `list` escape lock reason in --porcelain
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Jan 6, 2021, 09:07 UTC
- Message-ID
- <CAPig+cSy03+n_gSEiWJ4ebU1GFYvmfqeYCqs4_xzV9=5tyMGag@mail.gmail.com>
- In-Reply-To
- <428d16e8-fdb8-a587-6a0b-39c6c50eba99@gmail.com>
On Tue, Jan 5, 2021 at 5:29 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 13 quoted lines
> On 04/01/2021 16:21, Rafael Silva wrote: > > In case the lock reason contains newline characters (i.e: LF or CRLF) > > this will cause the format to break as each line should correspond to > > one attribute. This leads to unwanted behavior, specially as the > > porcelain is intended to be machine-readable. To address this shortcoming > > let's teach "git worktree list" to escape any newline character before > > outputting the locked reason for porcelain format. > > As the porcelain output format cannot handle worktree paths that contain > newlines either I think it would be better to add a `-z` flag which uses > NUL termination as we have for many other commands (diff, ls-files etc). > This would fix the problem forever without having to worry about quoting > each time a new field is added.
Adding a `-z` flag makes sense, but that doesn't mean the existing `--porcelain` is meaningless without it. I see `-z` as a good complement to `--porcelain`.
Yes, we should fix the problem that the existing porcelain output doesn't escape the path, but that can be done as a separate bug fix; it doesn't need to be rolled into this series.
Show 8 quoted lines
> If you really need to quote the lock reason then please use one of the > path quoting routines (probably quote_c_style() or write_name_quoted()) > in quote.c rather than rolling your own - the code below gives the same > output for a string that contains the two characters `\` followed by `n` > as it does for the single character `\n`. People are (hopefully) used to > dequoting our path quoting and there are routines out there to do it (we > have one git Git.pm) using a function in quote.c will allow them to use > those routines here.
I was going to suggest the same. Thanks.