]> git.ipfire.org Git - thirdparty/git.git/commit
ls-tree: fix expansion of repeated %(path)
authorRené Scharfe <l.s.r@web.de>
Sat, 14 Jan 2023 14:37:53 +0000 (15:37 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 15 Jan 2023 03:22:26 +0000 (19:22 -0800)
commit16fb5c54bd91c9714e12c6d742e5a6fd81459b71
tree0247f5b7dfa8a6ffa4bf13f7801ba420545da6f3
parent455923e0a152420054ad74f1af36336d5fa7be75
ls-tree: fix expansion of repeated %(path)

expand_show_tree() borrows the base strbuf given to us by read_tree() to
build the full path of the current entry when handling %(path).  Only
its indirect caller, show_tree_fmt(), removes the added entry name.
That works fine as long as %(path) is only included once in the format
string, but accumulates duplicates if it's repeated:

   $ git ls-tree --format='%(path) %(path) %(path)' HEAD M*
   Makefile MakefileMakefile MakefileMakefileMakefile

Reset the length after each use to get the same expansion every time;
here's the behavior with this patch:

   $ ./git ls-tree --format='%(path) %(path) %(path)' HEAD M*
   Makefile Makefile Makefile

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/ls-tree.c
t/t3104-ls-tree-format.sh