Thread (83 messages) 83 messages, 3 authors, 2021-01-30

Re: [PATCH 5/7] worktree: `list` escape lock reason in --porcelain

flat view

From: Eric Sunshine <hidden>
Date: 2021-01-06 09:08:38

On Tue, Jan 5, 2021 at 5:29 AM Phillip Wood [off-list ref] wrote:
On 04/01/2021 16:21, Rafael Silva wrote:
quoted
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.
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help