git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Jan Palus <jpalus@fastmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] t8002-blame: simplify padding generation in blank boundary tests
Date: Mon, 13 Jan 2025 13:36:34 +0100	[thread overview]
Message-ID: <Z4UIWId7ExLB2gWJ@pks.im> (raw)
In-Reply-To: <20250111231107.2190448-1-jpalus@fastmail.com>

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

  reply	other threads:[~2025-01-13 12:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-11 23:11 [PATCH] t8002-blame: simplify padding generation in blank boundary tests Jan Palus
2025-01-13 12:36 ` Patrick Steinhardt [this message]
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

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=Z4UIWId7ExLB2gWJ@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=jpalus@fastmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).