* [PATCH] t8002-blame: simplify padding generation in blank boundary tests
@ 2025-01-11 23:11 Jan Palus
2025-01-13 12:36 ` Patrick Steinhardt
0 siblings, 1 reply; 6+ messages in thread
From: Jan Palus @ 2025-01-11 23:11 UTC (permalink / raw)
To: git; +Cc: Patrick Steinhardt, Jan Palus
Fixes compatibility with mksh as well:
$ mksh -c 'printf "%0.s" ""'
printf: %0.s: invalid conversion specification
Fixes: e7fb2ca945 ("builtin/blame: fix out-of-bounds write with blank boundary commits")
Signed-off-by: Jan Palus <jpalus@fastmail.com>
---
t/t8002-blame.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index 1ad039e123..e98993276a 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -138,7 +138,7 @@ test_expect_success 'blame --abbrev -b truncates the blank boundary' '
# Note that `--abbrev=` always gets incremented by 1, which is why we
# expect 11 leading spaces and not 10.
cat >expect <<-EOF &&
- $(printf "%0.s " $(test_seq 11)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
+ $(printf "%11s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
EOF
git blame -b --abbrev=10 ^HEAD -- abbrev.t >actual &&
test_cmp expect actual
@@ -146,7 +146,7 @@ test_expect_success 'blame --abbrev -b truncates the blank boundary' '
test_expect_success 'blame with excessive --abbrev and -b culls to hash length' '
cat >expect <<-EOF &&
- $(printf "%0.s " $(test_seq $hexsz)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
+ $(printf "%${hexsz}s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
EOF
git blame -b --abbrev=9000 ^HEAD -- abbrev.t >actual &&
test_cmp expect actual
--
2.48.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] t8002-blame: simplify padding generation in blank boundary tests
2025-01-11 23:11 [PATCH] t8002-blame: simplify padding generation in blank boundary tests Jan Palus
@ 2025-01-13 12:36 ` Patrick Steinhardt
2025-01-13 15:15 ` Junio C Hamano
0 siblings, 1 reply; 6+ messages in thread
From: Patrick Steinhardt @ 2025-01-13 12:36 UTC (permalink / raw)
To: Jan Palus; +Cc: git
On Sun, Jan 12, 2025 at 12:11:07AM +0100, Jan Palus wrote:
> Fixes compatibility with mksh as well:
> $ mksh -c 'printf "%0.s" ""'
> printf: %0.s: invalid conversion specification
>
> Fixes: e7fb2ca945 ("builtin/blame: fix out-of-bounds write with blank boundary commits")
We don't typically use Fixes tags in our project, but instead embed the
commit into the commit message with `git log --format=reference -1`
together with a description.
The subject can also be adjusted a bit: we use to just write the test
number, and the important aspect is not that we simplify the padding
generation, but that we make it more portable.
So, my suggestion would be:
t8002: fix unportable printf formatting directives
In e7fb2ca945 (builtin/blame: fix out-of-bounds write with blank
boundary commits, 2025-01-10), we have introduced two new tests that
expect a certain amount of padding. This padding is generated via
printf using the "%0.s" formatting directive. That directive is
non-portable and not understood by for example mksh, breaking these
tests on platforms using that shell.
Fix this issue by using "%${N}s" instead, which is already being
used in t5300 and thus portable enough for us.
> Signed-off-by: Jan Palus <jpalus@fastmail.com>
> ---
> t/t8002-blame.sh | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
> index 1ad039e123..e98993276a 100755
> --- a/t/t8002-blame.sh
> +++ b/t/t8002-blame.sh
> @@ -138,7 +138,7 @@ test_expect_success 'blame --abbrev -b truncates the blank boundary' '
> # Note that `--abbrev=` always gets incremented by 1, which is why we
> # expect 11 leading spaces and not 10.
> cat >expect <<-EOF &&
> - $(printf "%0.s " $(test_seq 11)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
> + $(printf "%11s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
> EOF
> git blame -b --abbrev=10 ^HEAD -- abbrev.t >actual &&
> test_cmp expect actual
Okay, makes sense. And as mentioned, we already have such a use of
printf in t5300, so it should be portable enough for our use case.
Thanks!
Patrick
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] t8002-blame: simplify padding generation in blank boundary tests
2025-01-13 12:36 ` Patrick Steinhardt
@ 2025-01-13 15:15 ` Junio C Hamano
2025-01-18 1:09 ` Junio C Hamano
0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2025-01-13 15:15 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Jan Palus, git
Patrick Steinhardt <ps@pks.im> writes:
> On Sun, Jan 12, 2025 at 12:11:07AM +0100, Jan Palus wrote:
>> Fixes compatibility with mksh as well:
>> $ mksh -c 'printf "%0.s" ""'
>> printf: %0.s: invalid conversion specification
>>
>> Fixes: e7fb2ca945 ("builtin/blame: fix out-of-bounds write with blank boundary commits")
>
> We don't typically use Fixes tags in our project, but instead embed the
> commit into the commit message with `git log --format=reference -1`
> together with a description.
>
> The subject can also be adjusted a bit: we use to just write the test
> number, and the important aspect is not that we simplify the padding
> generation, but that we make it more portable.
>
> So, my suggestion would be:
>
> t8002: fix unportable printf formatting directives
>
> In e7fb2ca945 (builtin/blame: fix out-of-bounds write with blank
> boundary commits, 2025-01-10), we have introduced two new tests that
> expect a certain amount of padding. This padding is generated via
> printf using the "%0.s" formatting directive. That directive is
> non-portable and not understood by for example mksh, breaking these
> tests on platforms using that shell.
>
> Fix this issue by using "%${N}s" instead, which is already being
> used in t5300 and thus portable enough for us.
Is "%.0s" really not portable, or is it just mksh
being a bit lacking?
"That directive non-portable ..." -> "Some implementations (e.g.
one that is built into mksh) does not support the precision to be 0
(i.e. "%.0" before the "s" conversion)"
Other than that, your version is easy to read and understand.
>> - $(printf "%0.s " $(test_seq 11)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
>> + $(printf "%11s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
>> EOF
>> git blame -b --abbrev=10 ^HEAD -- abbrev.t >actual &&
>> test_cmp expect actual
>
> Okay, makes sense. And as mentioned, we already have such a use of
> printf in t5300, so it should be portable enough for our use case.
Thanks for reviewing, and thanks, Jan, for noticing and fixing.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] t8002-blame: simplify padding generation in blank boundary tests
2025-01-13 15:15 ` Junio C Hamano
@ 2025-01-18 1:09 ` Junio C Hamano
2025-01-20 10:47 ` Jan Palus
0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2025-01-18 1:09 UTC (permalink / raw)
To: Jan Palus; +Cc: Patrick Steinhardt, git
Junio C Hamano <gitster@pobox.com> writes:
>> So, my suggestion would be:
>>
>> t8002: fix unportable printf formatting directives
>>
>> In e7fb2ca945 (builtin/blame: fix out-of-bounds write with blank
>> boundary commits, 2025-01-10), we have introduced two new tests that
>> expect a certain amount of padding. This padding is generated via
>> printf using the "%0.s" formatting directive. That directive is
>> non-portable and not understood by for example mksh, breaking these
>> tests on platforms using that shell.
>>
>> Fix this issue by using "%${N}s" instead, which is already being
>> used in t5300 and thus portable enough for us.
>
> Is "%.0s" really not portable, or is it just mksh
> being a bit lacking?
>
> "That directive non-portable ..." -> "Some implementations (e.g.
> one that is built into mksh) does not support the precision to be 0
> (i.e. "%.0" before the "s" conversion)"
>
> Other than that, your version is easy to read and understand.
>
>>> - $(printf "%0.s " $(test_seq 11)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
>>> + $(printf "%11s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
>>> EOF
>>> git blame -b --abbrev=10 ^HEAD -- abbrev.t >actual &&
>>> test_cmp expect actual
>>
>> Okay, makes sense. And as mentioned, we already have such a use of
>> printf in t5300, so it should be portable enough for our use case.
>
> Thanks for reviewing, and thanks, Jan, for noticing and fixing.
Sorry, as Jan is not a list regular, perhaps I should have
communicated more carefully when I said "Thanks".
The above message from me with "Thanks" does not mean that the patch
is now settled. There are suggested improvements pending that needs
to be incorporated before the patch becomes acceptable to our tree.
Anybody can help that "further polishing as suggested" step, and
when the patch is left in limbo for too long, I might step in to do
it myself (when I have no other better things to do), but it is
customary around here that the original patch submitter does so.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] t8002-blame: simplify padding generation in blank boundary tests
2025-01-18 1:09 ` Junio C Hamano
@ 2025-01-20 10:47 ` Jan Palus
2025-01-21 20:10 ` Junio C Hamano
0 siblings, 1 reply; 6+ messages in thread
From: Jan Palus @ 2025-01-20 10:47 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Patrick Steinhardt, git
On 17.01.2025 17:09, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
> >> So, my suggestion would be:
> >>
> >> t8002: fix unportable printf formatting directives
> >>
> >> In e7fb2ca945 (builtin/blame: fix out-of-bounds write with blank
> >> boundary commits, 2025-01-10), we have introduced two new tests that
> >> expect a certain amount of padding. This padding is generated via
> >> printf using the "%0.s" formatting directive. That directive is
> >> non-portable and not understood by for example mksh, breaking these
> >> tests on platforms using that shell.
> >>
> >> Fix this issue by using "%${N}s" instead, which is already being
> >> used in t5300 and thus portable enough for us.
> >
> > Is "%.0s" really not portable, or is it just mksh
> > being a bit lacking?
Contrary to other shells mksh does not have printf builtin:
$ mksh -c 'type printf'
printf is a tracked alias for /bin/printf
so it uses printf from coreutils. This version however interprets "0"
as a flag marking "s"/"c" conversion specifiers as not allowed:
https://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/printf.c;h=2a73bb7fed892347eafb40f497ce5080f511fc9b;hb=v9.6#l586
> > "That directive non-portable ..." -> "Some implementations (e.g.
> > one that is built into mksh) does not support the precision to be 0
> > (i.e. "%.0" before the "s" conversion)"
> >
> > Other than that, your version is easy to read and understand.
Note that original version was "%0.s" in which there is some ambiguity
whether "0" is a flag or field width and not "%.0s" in which "0" indeed
would mean precision.
> >>> - $(printf "%0.s " $(test_seq 11)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
> >>> + $(printf "%11s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
> >>> EOF
> >>> git blame -b --abbrev=10 ^HEAD -- abbrev.t >actual &&
> >>> test_cmp expect actual
> >>
> >> Okay, makes sense. And as mentioned, we already have such a use of
> >> printf in t5300, so it should be portable enough for our use case.
> >
> > Thanks for reviewing, and thanks, Jan, for noticing and fixing.
>
> Sorry, as Jan is not a list regular, perhaps I should have
> communicated more carefully when I said "Thanks".
>
> The above message from me with "Thanks" does not mean that the patch
> is now settled. There are suggested improvements pending that needs
> to be incorporated before the patch becomes acceptable to our tree.
>
> Anybody can help that "further polishing as suggested" step, and
> when the patch is left in limbo for too long, I might step in to do
> it myself (when I have no other better things to do), but it is
> customary around here that the original patch submitter does so.
I was about to follow-up but didn't find time. Sorry it took so long.
I will post v2 shortly.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] t8002-blame: simplify padding generation in blank boundary tests
2025-01-20 10:47 ` Jan Palus
@ 2025-01-21 20:10 ` Junio C Hamano
0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2025-01-21 20:10 UTC (permalink / raw)
To: Jan Palus; +Cc: Patrick Steinhardt, git
Jan Palus <jpalus@fastmail.com> writes:
> Note that original version was "%0.s" in which there is some ambiguity
> whether "0" is a flag or field width and not "%.0s" in which "0" indeed
> would mean precision.
Ah, I missed that part. Also thanks for filling in the "printf from
coreutils is the one that has issues with the code".
>> Anybody can help that "further polishing as suggested" step, and
>> when the patch is left in limbo for too long, I might step in to do
>> it myself (when I have no other better things to do), but it is
>> customary around here that the original patch submitter does so.
>
> I was about to follow-up but didn't find time. Sorry it took so long.
> I will post v2 shortly.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-01-21 20:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-11 23:11 [PATCH] t8002-blame: simplify padding generation in blank boundary tests Jan Palus
2025-01-13 12:36 ` Patrick Steinhardt
2025-01-13 15:15 ` Junio C Hamano
2025-01-18 1:09 ` Junio C Hamano
2025-01-20 10:47 ` Jan Palus
2025-01-21 20:10 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).