Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: "Git List" <git@vger.kernel.org>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH] ls-tree: fix expansion of repeated %(path)
Date: Sat, 14 Jan 2023 08:46:50 -0800	[thread overview]
Message-ID: <xmqqmt6lkqrp.fsf@gitster.g> (raw)
In-Reply-To: <59f0a3f8-2dae-db47-5075-0cf50aada335@web.de> ("René Scharfe"'s message of "Sat, 14 Jan 2023 15:37:53 +0100")

René Scharfe <l.s.r@web.de> writes:

> 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>
> ---
>  builtin/ls-tree.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

I wonder if this was broken from its introduction at 455923e0
(ls-tree: introduce "--format" option, 2022-03-23)?

It seems to be the case.  With the following applied on top of
455923e0, the new test fails as expected, and your patch fixes
the breakage, so I am tempted to squash the tests in ;-)

Thanks.

 t/t3104-ls-tree-format.sh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git c/t/t3104-ls-tree-format.sh w/t/t3104-ls-tree-format.sh
index 7f1eb699d3..7e6c4dc5da 100755
--- c/t/t3104-ls-tree-format.sh
+++ w/t/t3104-ls-tree-format.sh
@@ -37,6 +37,12 @@ test_ls_tree_format () {
 	'
 }
 
+test_expect_success "ls-tree --format='%(path) %(path) %(path)' HEAD top-file" '
+	git ls-tree --format="%(path) %(path) %(path)" HEAD top-file.t >actual &&
+	echo top-file.t top-file.t top-file.t >expect &&
+	test_cmp expect actual
+'
+
 test_ls_tree_format \
 	"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
 	""

  parent reply	other threads:[~2023-01-14 16:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-14 14:37 [PATCH] ls-tree: fix expansion of repeated %(path) René Scharfe
2023-01-14 15:03 ` [BONUS][PATCH] ls-tree: remove dead store and strbuf for quote_c_style() René Scharfe
2023-01-14 16:46 ` Junio C Hamano [this message]
2023-01-14 18:24   ` [PATCH] ls-tree: fix expansion of repeated %(path) René Scharfe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqmt6lkqrp.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox