# ls-tree -z patch makes %(path) verbatim, with debate over test contents

_With -z, ls-tree --format has C-quoted %(path) since 2022, contrary to its documentation and to ls-files --format._

Section: Patches. Edition of 2026-11-19. Written by an AI editor from the thread "[PATCH] ls-tree: do not quote %(path) with -z" (6 messages): https://gitlist.dev/t/66875

Noam Cohen reports that git ls-tree is documented to print filenames verbatim with -z. Since 455923e0a1, which introduced --format, the %(path) placeholder has always been C-quoted. The patch outputs it verbatim when -z is given, as git ls-files --format already does.

The second version builds a path containing a double quote using git mktree, which keeps the test within US-ASCII and independent of the filesystem. It also forces core.quotePath=true.

Junio C Hamano said forcing core.quotePath was what he had in mind, but that avoiding non-ASCII bytes is not a requirement. He said tests that use such bytes are much better than none, and the point is only to avoid platform anomalies. He called the code change trivially correct.

Noam replied that the only ASCII bytes quote_c_style() quotes are control characters, DEL, double quote and backslash. Windows does not allow most of these in filenames, and DEL felt too obscure. He noted that a test_commit-based setup is simpler than mktree and that other tests already use non-ASCII paths. He asked whether to drop the test or add a similar one for ls-files --format. Junio observed that the ls-files --format commit documents -z but added no test for --format="%(path)" with -z.

A third version has since been posted.
