Re: [PATCH/RFC 1/2] git-sh-i18n--envsubst: our own envsubst(1) for eval_gettext()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 3, 2011 at 01:14, Junio C Hamano <gitster@xxxxxxxxx> wrote:
> Ãvar ArnfjÃrà Bjarmason Â<avarab@xxxxxxxxx> writes:
>
>> In a previous incarnation of the gettext series I implemented the
>> eval_gettext() fallback like this:
>>
>> Â Â eval_gettext() {
>> Â Â Â Â gettext_out=$(gettext "$1")
>> Â Â Â Â gettext_eval="printf '%s' \"$gettext_out\""
>> Â Â Â Â printf "%s" "`eval \"$gettext_eval\"`"
>> Â Â }
>>
>> This was clever, but would incorrectly handle cases where the variable
>> being interpolated contained spaces. E.g.:
>>
>> Â Â cmd="git foo"; eval_gettext "command: \$cmd"
>>
>> Would emit "command: gitfoo", instead of the correct "command: git
>> foo".
>
> Hmm, are you sure you got your quoting right?
>
> Â Â$ cat >1.sh <<\EOF
> Â Â#!/bin/sh
> Â Âgettext () {
> Â Â Â Â Â Âcase "$1" in
> Â Â Â Â Â Â'command: $cmd') echo 'dcomman: $cmd' ;;
> Â Â Â Â Â Â*) echo "GETTEXT POISON" ;;
> Â Â Â Â Â Âesac
> Â Â}
>
> Â Âeval_gettext() {
> Â Â Â Â Â Âgettext_out=$(gettext "$1") &&
> Â Â Â Â Â Âgettext_eval="printf '%s' \"$gettext_out\"" &&
> Â Â Â Â Â Âgettext_cmd=$(eval "$gettext_eval") &&
> Â Â Â Â Â Âprintf "%s" "$gettext_cmd"
> Â Â}
>
> Â Âcmd="git foo"
> Â Âeval_gettext "command: \$cmd"
> Â ÂEOF
> Â Â$ sh -x 1.sh
> Â Â+ cmd='git foo'
> Â Â+ eval_gettext 'command: $cmd'
> Â Â++ gettext 'command: $cmd'
> Â Â++ case "$1" in
> Â Â++ echo 'dcomman: $cmd'
> Â Â+ gettext_out='dcomman: $cmd'
> Â Â+ gettext_eval='printf '\''%s'\'' "dcomman: $cmd"'
> Â Â++ eval 'printf '\''%s'\'' "dcomman: $cmd"'
> Â Â+++ printf %s 'dcomman: git foo'
> Â Â+ gettext_cmd='dcomman: git foo'
> Â Â+ printf %s 'dcomman: git foo'
> Â Âdcomman: git foo
>
> Am I grossly missing something from what you are trying to do here?

(CC-ing the list again, so there's a record of this in the mail
archive).

Your eval_gettext() is better, but it still fails in cases where the
string contains "'s. E.g.:

    test_expect_success C_LOCALE_OUTPUT 'eval_gettext: our
eval_gettext() fallback can interpolate variables with spaces in them'
'
        cmdline="git am" &&
        export cmdline;
        printf "When you have resolved this problem run \"git am
--resolved\"." >expect &&
        eval_gettext "When you have resolved this problem run
\"\$cmdline --resolved\"." >actual
        test_cmp expect actual
    '

If this were just:

    test_expect_success C_LOCALE_OUTPUT 'eval_gettext: our
eval_gettext() fallback can interpolate variables with spaces in them'
'
        cmdline="git am" &&
        export cmdline;
        printf "When you have resolved this problem run git am
--resolved." >expect &&
        eval_gettext "When you have resolved this problem run
\$cmdline --resolved." >actual
        test_cmp expect actual
    '

Your version would work.

Maybe there's some portable version of doing this that works with
variables with spaces mixed with quotes. But unless someone can point
it out I'll submit a series with git-sh-i18n--envsubst and tests
demonstrating why it's needed soon.q
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]