"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
Re: regression/cmdline/diff.sh: portability fix
To:
gameoftrees@openbsd.org, Christian Weisgerber <naddy@mips.inka.de>
Date:
Tue, 17 Jan 2023 23:24:36 +0100

Download raw body.

Thread
On 17 January 2023 23:00:15 CET, Omar Polo <op@omarpolo.com> wrote:
>On 2023/01/17 22:32:51 +0100, Christian Weisgerber <naddy@mips.inka.de> wrote:
>> The typeset shell builtin is a ksh(1) feature.  It is not available
>> in a pure POSIX sh(1).  We can use printf(1) to portably perform
>> the same truncation and padding of a string.
>> 
>> ok?
>
>sure, ok op@.  IMHO printf(1) is even more clear than typeset here.
>It's also the only usage of typeset in the regress test.
>
>> diff /home/naddy/got
>> commit - f4e8c21cb2dc6a468bae32a4dcf3a9e18f269527
>> path + /home/naddy/got
>> blob - 34b8116a11c50dad2f634dc6fe4dcea09570a334
>> file + regress/cmdline/diff.sh
>> --- regress/cmdline/diff.sh
>> +++ regress/cmdline/diff.sh
>> @@ -1762,10 +1762,8 @@ EOF
>>  		return 1
>>  	fi
>>  
>> -	typeset -L10 short_alpha_id
>> -	typeset -L10 short_alpha_new_id
>> -	short_alpha_id=$alpha_blobid
>> -	short_alpha_new_id=$alpha_new_blobid
>> +	short_alpha_id=$(printf '%-10.10s' $alpha_blobid)
>> +	short_alpha_new_id=$(printf '%-10.10s' $alpha_new_blobid)
>>  	cat <<EOF >$testroot/stdout.expected
>>  diffstat $alpha_blobid $alpha_new_blobid
>>   M  $short_alpha_id -> $short_alpha_new_id  |  1+  1-
>
>

actually I think it could even be simplified down to printf '%.10s' since the blobid is guaranteed to be longer than 10 chars and no padding can occur.
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.