git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/2] git-sh-i18n--envsubst: our own envsubst(1) for eval_gettext()
Date: Sun, 03 Apr 2011 12:05:14 -0700	[thread overview]
Message-ID: <7voc4ncg0l.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: 1301848953-31525-2-git-send-email-avarab@gmail.com

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Add a git-sh-i18n--envsubst program which is a stripped-down version
> of the GNU envsubst(1) program that comes with GNU gettext for use in
> the eval_gettext() fallback, instead of using a clever (but broken)
> printf + eval + printf trick.
>
> 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,...

The incoming string to this function is an arbitrary string and it is
asked to interpolate variables $var in it, without any other restriction
in the string.  If we want to interpolate $var using shell eval, we have
to somehow put it in the dq context, but all other interpolation done
inside dq context would also be applied to the piece of the string by the
eval, including backslashes, $(command substitution--horrors), etc., which
we would have needed to add more quotes to selected places in the string
(read: parse and find what the shell would interpolate ourselves) to
prevent them from happening.

In hindsight, it should have been clear to all of us from day one that
shell eval based approach would have never worked.

I suspect that the use of envsubst (especially the part that gives the
string itself to envsubst) is not quite right.  What if the message wanted
to say something like this?

        Look at $HOME/.gitconfig and find definition for $var variable.

where we want to show $HOME _literally_, while substituting $var for the
name of the variable?  The underlying envsubst allows you to do so by
telling it which the variables are to be substituted.

	s='Look at $HOME/.gitconfig and find definition of $var variable.'
	HOME=/home/junio
        var=core.i18n
        (
        	export HOME var ;# no need for HOME, but just an illustration
		echo "$s" | envsubst '$var'
	)

but eval_gettext interface doesn't seem to be expressive enough to do this;
you would let it scan the whole "$s" and end up substituting $HOME, no?

Perhaps it is not an issue in real life; after all eval_gettext interface
is not something you invented in 5 minutes without thinking deeply, but is
what you plan to use from outside codebase that presumably has seen a wide
use in the field, and it may be just that I am worried too much about an
implausible corner case, but I thought I should bring it up.

Thanks.

  reply	other threads:[~2011-04-03 19:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-03 16:42 [PATCH 0/2] i18n: Shell script translation infrastructure Ævar Arnfjörð Bjarmason
2011-04-03 16:42 ` [PATCH 1/2] git-sh-i18n--envsubst: our own envsubst(1) for eval_gettext() Ævar Arnfjörð Bjarmason
2011-04-03 19:05   ` Junio C Hamano [this message]
2011-04-10 22:43     ` Ævar Arnfjörð Bjarmason
2011-04-03 16:42 ` [PATCH 2/2] git-sh-i18n.sh: add no-op gettext() and eval_gettext() wrappers Ævar Arnfjörð Bjarmason

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7voc4ncg0l.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).