Git development
 help / color / mirror / Atom feed
* [PATCH] ls-tree: do not quote %(path) with -z
@ 2026-11-18 23:04 Noam Cohen via B4 Relay
  2026-11-18 23:20 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Noam Cohen via B4 Relay @ 2026-11-18 23:04 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Teng Long, Ævar Arnfjörð Bjarmason,
	René Scharfe, Noam Cohen

From: Noam Cohen <noam@noam.me>

With -z, "git ls-tree" is documented to output the filename verbatim,
but since 455923e0a1 (ls-tree: introduce "--format" option,
2022-03-23) the %(path) placeholder of a custom --format is always
C-quoted.

Output it verbatim when -z is given, like "git ls-files --format"
already does.

Signed-off-by: Noam Cohen <noam@noam.me>
---
This makes "ls-tree -z --format" match "ls-files -z --format", which
already outputs %(path) verbatim.
---
 builtin/ls-tree.c         | 5 ++++-
 t/t3104-ls-tree-format.sh | 9 ++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 46edaffc2e..d25bbffcdd 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -130,7 +130,10 @@ static int show_tree_fmt(const struct object_id *oid, struct strbuf *base,
 
 			strbuf_addstr(base, pathname);
 			name = relative_path(base->buf, prefix, &sbuf);
-			quote_c_style(name, &sb, NULL, 0);
+			if (options->null_termination)
+				strbuf_addstr(&sb, name);
+			else
+				quote_c_style(name, &sb, NULL, 0);
 			strbuf_setlen(base, baselen);
 			strbuf_release(&sbuf);
 		} else
diff --git a/t/t3104-ls-tree-format.sh b/t/t3104-ls-tree-format.sh
index a1b2069a25..016c0fd0ff 100755
--- a/t/t3104-ls-tree-format.sh
+++ b/t/t3104-ls-tree-format.sh
@@ -12,7 +12,8 @@ test_expect_success 'ls-tree --format usage' '
 '
 
 test_expect_success 'setup' '
-	setup_basic_ls_tree_data
+	setup_basic_ls_tree_data &&
+	test_commit נעם
 '
 
 test_ls_tree_format () {
@@ -76,4 +77,10 @@ test_ls_tree_format \
 	"--full-tree" \
 	"--full-tree"
 
+test_expect_success 'ls-tree --format with -z does not quote paths' '
+	printf "blob נעם.t\0" >expect &&
+	git ls-tree -z --format="%(objecttype) %(path)" HEAD נעם.t >actual &&
+	test_cmp expect actual
+'
+
 test_done

---
base-commit: 03b41523c576f26ad34085378717a0c1b287470f
change-id: 20261118-ls-tree-format-z-verbatim-path-f5783b61ff8f



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-18 23:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 23:04 [PATCH] ls-tree: do not quote %(path) with -z Noam Cohen via B4 Relay
2026-11-18 23:20 ` Junio C Hamano
2026-11-18 23:45   ` Noam Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox