{"thread":{"id":"66875","subject":"[PATCH] ls-tree: do not quote %(path) with -z","startedAt":"2026-11-18T23:04:37Z","lastAt":"2026-11-19T16:12:37Z","messageCount":6,"participants":["Noam Cohen via B4 Relay","Junio C Hamano","Noam Cohen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"558766","messageId":"20261118-ls-tree-format-z-verbatim-path-v1-1-718987241861@noam.me","threadId":"66875","inReplyTo":null,"subject":"[PATCH] ls-tree: do not quote %(path) with -z","fromName":"Noam Cohen via B4 Relay","fromEmail":"devnull+noam.noam.me@kernel.org","sentAt":"2026-11-18T23:04:37Z","receivedAt":"2026-11-18T23:04:37Z","isPatch":true,"sender":{"key":"name:Noam Cohen","avatar":null},"body":"From: Noam Cohen <noam@noam.me>\n\nWith -z, \"git ls-tree\" is documented to output the filename verbatim,\nbut since 455923e0a1 (ls-tree: introduce \"--format\" option,\n2022-03-23) the %(path) placeholder of a custom --format is always\nC-quoted.\n\nOutput it verbatim when -z is given, like \"git ls-files --format\"\nalready does.\n\nSigned-off-by: Noam Cohen <noam@noam.me>\n---\nThis makes \"ls-tree -z --format\" match \"ls-files -z --format\", which\nalready outputs %(path) verbatim.\n---\n builtin/ls-tree.c         | 5 ++++-\n t/t3104-ls-tree-format.sh | 9 ++++++++-\n 2 files changed, 12 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/ls-tree.c b/builtin/ls-tree.c\nindex 46edaffc2e..d25bbffcdd 100644\n--- a/builtin/ls-tree.c\n+++ b/builtin/ls-tree.c\n@@ -130,7 +130,10 @@ static int show_tree_fmt(const struct object_id *oid, struct strbuf *base,\n \n \t\t\tstrbuf_addstr(base, pathname);\n \t\t\tname = relative_path(base->buf, prefix, &sbuf);\n-\t\t\tquote_c_style(name, &sb, NULL, 0);\n+\t\t\tif (options->null_termination)\n+\t\t\t\tstrbuf_addstr(&sb, name);\n+\t\t\telse\n+\t\t\t\tquote_c_style(name, &sb, NULL, 0);\n \t\t\tstrbuf_setlen(base, baselen);\n \t\t\tstrbuf_release(&sbuf);\n \t\t} else\ndiff --git a/t/t3104-ls-tree-format.sh b/t/t3104-ls-tree-format.sh\nindex a1b2069a25..016c0fd0ff 100755\n--- a/t/t3104-ls-tree-format.sh\n+++ b/t/t3104-ls-tree-format.sh\n@@ -12,7 +12,8 @@ test_expect_success 'ls-tree --format usage' '\n '\n \n test_expect_success 'setup' '\n-\tsetup_basic_ls_tree_data\n+\tsetup_basic_ls_tree_data &&\n+\ttest_commit נעם\n '\n \n test_ls_tree_format () {\n@@ -76,4 +77,10 @@ test_ls_tree_format \\\n \t\"--full-tree\" \\\n \t\"--full-tree\"\n \n+test_expect_success 'ls-tree --format with -z does not quote paths' '\n+\tprintf \"blob נעם.t\\0\" >expect &&\n+\tgit ls-tree -z --format=\"%(objecttype) %(path)\" HEAD נעם.t >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n\n---\nbase-commit: 03b41523c576f26ad34085378717a0c1b287470f\nchange-id: 20261118-ls-tree-format-z-verbatim-path-f5783b61ff8f\n\n\n\n"},{"id":"558768","messageId":"xmqqcxs120c8.fsf@gitster.g","threadId":"66875","inReplyTo":"20261118-ls-tree-format-z-verbatim-path-v1-1-718987241861@noam.me","subject":"Re: [PATCH] ls-tree: do not quote %(path) with -z","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-18T23:20:39Z","receivedAt":"2026-11-18T23:20:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Noam Cohen via B4 Relay <devnull+noam.noam.me@kernel.org> writes:\n\n> From: Noam Cohen <noam@noam.me>\n>\n> With -z, \"git ls-tree\" is documented to output the filename verbatim,\n> but since 455923e0a1 (ls-tree: introduce \"--format\" option,\n> 2022-03-23) the %(path) placeholder of a custom --format is always\n> C-quoted.\n>\n> Output it verbatim when -z is given, like \"git ls-files --format\"\n> already does.\n\nce74de931d (ls-files: introduce \"--format\" option, 2022-07-23) was\nthe one that added --format, and the documentation added by the\ncommit does talk about -z.  But curiously, it does not add any test\nthat exercises --format=\"%(path)\" combined with -z.\n\nThe code change is trivially correct.\n\n>  test_expect_success 'setup' '\n> -\tsetup_basic_ls_tree_data\n> +\tsetup_basic_ls_tree_data &&\n> +\ttest_commit נעם\n>  '\n\nDo we have to really use characters outside US-ASCII?\n\n> @@ -76,4 +77,10 @@ test_ls_tree_format \\\n>  \t\"--full-tree\" \\\n>  \t\"--full-tree\"\n>  \n> +test_expect_success 'ls-tree --format with -z does not quote paths' '\n> +\tprintf \"blob נעם.t\\0\" >expect &&\n> +\tgit ls-tree -z --format=\"%(objecttype) %(path)\" HEAD נעם.t >actual &&\n\nOK, perhaps.\n\n"},{"id":"558770","messageId":"CAJeEYUaJt49oz+Fq7qwWGyB9p=Hibdzd3113FBhbK1RDn3oHug@mail.gmail.com","threadId":"66875","inReplyTo":"xmqqcxs120c8.fsf@gitster.g","subject":"Re: [PATCH] ls-tree: do not quote %(path) with -z","fromName":"Noam Cohen","fromEmail":"noam@noam.me","sentAt":"2026-11-18T23:45:42Z","receivedAt":"2026-11-18T23:45:42Z","isPatch":true,"sender":{"key":"noam@noam.me","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n>>  test_expect_success 'setup' '\n>> -    setup_basic_ls_tree_data\n>> +    setup_basic_ls_tree_data &&\n>> +    test_commit נעם\n>>  '\n>\n> Do we have to really use characters outside US-ASCII?\n\nThe only US-ASCII bytes that quote_c_style() quotes are control\ncharacters, DEL, '\"' and '\\', and Windows does not allow them in\nfilenames, except for DEL, which felt too obscure to rely on.\n\nWe could avoid the filesystem and synthesize the tree with \"git\nmktree\" instead, which is what I had at first, but that made the\ntest noticeably more complicated than a test_commit in the setup.\n\nWe already have tests that use non-ASCII paths, like t3902,\nt4012, and others.\n\nDo you think the test should set core.quotePath explicitly, rather\nthan relying on its default?\n\nAlso, should I just drop the test, or add a similar one for ls-files\n--format?\n\n"},{"id":"558780","messageId":"xmqq8q2p1ulh.fsf@gitster.g","threadId":"66875","inReplyTo":"CAJeEYUaJt49oz+Fq7qwWGyB9p=Hibdzd3113FBhbK1RDn3oHug@mail.gmail.com","subject":"Re: [PATCH] ls-tree: do not quote %(path) with -z","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-19T01:24:42Z","receivedAt":"2026-11-19T01:24:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Noam Cohen <noam@noam.me> writes:\n\n> We could avoid the filesystem and synthesize the tree with \"git\n> mktree\" instead, which is what I had at first, but that made the\n> test noticeably more complicated than a test_commit in the setup.\n\nYeah, that, with forced core.quotePath setting, was what I had in\nmind.\n\nBut it is not a requirement to avoid stepping outside US-ASCII while\nwriting tests.  It is much better to have tests that use bytes from\noutside US-ASCII than not having at all.  It is just that it would\nbe nicer if we do not have to worry about platform anomalies that\ncannot store characters outside US-ASCII range.\n\n\n\n"},{"id":"558781","messageId":"20261119-ls-tree-format-z-verbatim-path-v2-1-c014e4e4c96f@noam.me","threadId":"66875","inReplyTo":"20261118-ls-tree-format-z-verbatim-path-v1-1-718987241861@noam.me","subject":"[PATCH v2] ls-tree: do not quote %(path) with -z","fromName":"Noam Cohen via B4 Relay","fromEmail":"devnull+noam.noam.me@kernel.org","sentAt":"2026-11-19T03:43:01Z","receivedAt":"2026-11-19T03:43:01Z","isPatch":true,"sender":{"key":"name:Noam Cohen","avatar":null},"body":"From: Noam Cohen <noam@noam.me>\n\nWith -z, \"git ls-tree\" is documented to output the filename verbatim,\nbut since 455923e0a1 (ls-tree: introduce \"--format\" option,\n2022-03-23) the %(path) placeholder of a custom --format is always\nC-quoted.\n\nOutput it verbatim when -z is given, like \"git ls-files --format\"\nalready does.\n\nSigned-off-by: Noam Cohen <noam@noam.me>\n---\nThis makes \"ls-tree -z --format\" match \"ls-files -z --format\", which\nalready outputs %(path) verbatim.\n---\nChanges in v2:\n- Use a path with a double quote, built with \"git mktree\", so the test\n  stays within US-ASCII and does not depend on the filesystem.\n- Force core.quotePath=true in the test.\n- Link to v1: https://patch.msgid.link/20261118-ls-tree-format-z-verbatim-path-v1-1-718987241861@noam.me\n---\n builtin/ls-tree.c         | 5 ++++-\n t/t3104-ls-tree-format.sh | 9 +++++++++\n 2 files changed, 13 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/ls-tree.c b/builtin/ls-tree.c\nindex 46edaffc2e..d25bbffcdd 100644\n--- a/builtin/ls-tree.c\n+++ b/builtin/ls-tree.c\n@@ -130,7 +130,10 @@ static int show_tree_fmt(const struct object_id *oid, struct strbuf *base,\n \n \t\t\tstrbuf_addstr(base, pathname);\n \t\t\tname = relative_path(base->buf, prefix, &sbuf);\n-\t\t\tquote_c_style(name, &sb, NULL, 0);\n+\t\t\tif (options->null_termination)\n+\t\t\t\tstrbuf_addstr(&sb, name);\n+\t\t\telse\n+\t\t\t\tquote_c_style(name, &sb, NULL, 0);\n \t\t\tstrbuf_setlen(base, baselen);\n \t\t\tstrbuf_release(&sbuf);\n \t\t} else\ndiff --git a/t/t3104-ls-tree-format.sh b/t/t3104-ls-tree-format.sh\nindex a1b2069a25..0df216909b 100755\n--- a/t/t3104-ls-tree-format.sh\n+++ b/t/t3104-ls-tree-format.sh\n@@ -76,4 +76,13 @@ test_ls_tree_format \\\n \t\"--full-tree\" \\\n \t\"--full-tree\"\n \n+test_expect_success 'ls-tree --format with -z does not quote paths' '\n+\tblob=$(git rev-parse HEAD:top-file.t) &&\n+\ttree=$(printf \"100644 blob $blob\\tdouble\\\"quote\\n\" | git mktree) &&\n+\tprintf \"blob double\\\"quote\\0\" >expect &&\n+\tgit -c core.quotePath=true ls-tree -z \\\n+\t\t--format=\"%(objecttype) %(path)\" $tree >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n\n---\nbase-commit: 03b41523c576f26ad34085378717a0c1b287470f\nchange-id: 20261118-ls-tree-format-z-verbatim-path-f5783b61ff8f\n\n\n\n"},{"id":"558860","messageId":"xmqq4idc2422.fsf@gitster.g","threadId":"66875","inReplyTo":"20261119-ls-tree-format-z-verbatim-path-v2-1-c014e4e4c96f@noam.me","subject":"Re: [PATCH v2] ls-tree: do not quote %(path) with -z","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-19T16:12:37Z","receivedAt":"2026-11-19T16:12:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Noam Cohen via B4 Relay <devnull+noam.noam.me@kernel.org> writes:\n\n> From: Noam Cohen <noam@noam.me>\n>\n> With -z, \"git ls-tree\" is documented to output the filename verbatim,\n> but since 455923e0a1 (ls-tree: introduce \"--format\" option,\n> 2022-03-23) the %(path) placeholder of a custom --format is always\n> C-quoted.\n>\n> Output it verbatim when -z is given, like \"git ls-files --format\"\n> already does.\n> ...\n> -\t\t\tquote_c_style(name, &sb, NULL, 0);\n> +\t\t\tif (options->null_termination)\n> +\t\t\t\tstrbuf_addstr(&sb, name);\n> +\t\t\telse\n> +\t\t\t\tquote_c_style(name, &sb, NULL, 0);\n>  \t\t\tstrbuf_setlen(base, baselen);\n> ...\n> +test_expect_success 'ls-tree --format with -z does not quote paths' '\n> +\tblob=$(git rev-parse HEAD:top-file.t) &&\n> +\ttree=$(printf \"100644 blob $blob\\tdouble\\\"quote\\n\" | git mktree) &&\n> +\tprintf \"blob double\\\"quote\\0\" >expect &&\n> +\tgit -c core.quotePath=true ls-tree -z \\\n> +\t\t--format=\"%(objecttype) %(path)\" $tree >actual &&\n> +\ttest_cmp expect actual\n> +'\n\nEverything looks as expected.  Nicely done.\nWill queue.  Thanks.\n\n\n"}]}