Re: Runaway sed memory use in test on older sed+glibc (was "Re: [PATCH v6 1/3] test: add helper functions for git-bundle")
- From
Jiang Xin <worldhello.net@gmail.com>
- Date
- Jun 1, 2021, 09:42 UTC
- Message-ID
- <CANYiYbG1vVqN-De0n2Ukexh0Jn8e_b2G1CPv24T1fbYgyhKjfg@mail.gmail.com>
- In-Reply-To
- <87tumol4tg.fsf@evledraar.gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> 于2021年5月27日周四 下午8:49写道:
Show 5 quoted lines
>
> But no, the issue as it turns out is not Perl v.s. Sed, it's that
> there's some bug in the shellscript / tooling version (happens with both
> dash 0.5.7-4 and bash 4.3-11+deb8u2 on that box) where those expansions
> like ${A%${A#??????0?}} resolve to nothing.That's the root cause. It can be reproduced by running the following test script:
``` #!/bin/sh # test script: test.sh
test_commit_setvar () {
var=$1 &&
oid=1234567890123456789012345678901234567890 &&
eval $var=$oid
}test_commit_setvar A echo "A: $A" echo "Abbrev of A: ${A%${A#???????}}" ```
By running different version of dash, we can see that dash 0.5.7 fail the test:
``` $ /opt/dash/0.5.11/bin/dash test.sh A: 1234567890123456789012345678901234567890 Abbrev of A: 1234567
$ /opt/dash/0.5.7/bin/dash test.sh A: 1234567890123456789012345678901234567890 Abbrev of A: ```
This issue can be fixed using the following example:
``` #!/bin/sh
test_commit_setvar () {
var=$1 &&
oid=1234567890123456789012345678901234567890 &&
suffix=${oid#???????} &&
oid=${oid%$suffix} &&
eval $var=$oid
}test_commit_setvar A echo "Abbrev of A: $A" ```
Show 6 quoted lines
> Anyway, looking at this whole test file with fresh eyes this pattern > seems very strange. You duplicated most of test_commit with this > test_commit_setvar. It's a bit more verbosity but why not just use: > > test_commit ... > A=$(git rev-parse HEAD)
The function "test_commit()" in "test-lib-function.sh" always creates tags and it cannot make merge commit. So I rewrite a new function which reuse the scaffold of "test_commit".
BTW, sorry for the late reply, will send patch later.
-- Jiang Xin