no-op shell script i18n infrastructure
Subsystems (2)
cover no-op shell script i18n infrastructure
While the no-op C patch series is cooking I thought I'd send an RFC for the no-op shellscript infrastructure. So here (as threatened in <[email protected]>[1]) is the infrastructure needed to gettextize the shell script programs.
To quote my previous E-Mail[1] here are the things that are DONE and still need to be done.
Open issues:
* Write documentation for git-sh-i18n.sh and git-sh-i18n--envsubst like we have for git-sh-setup (already in WIP form).
It now has documentation. So this isn't a problem anymore.
* git-sh-i18n--envsubst is still too fat:
$ ldd -r git-sh-i18n--envsubst
linux-vdso.so.1 => (0x00007fffc60fd000)
libz.so.1 => /usr/lib/libz.so.1 (0x00007f25cff9e000)
libcrypto.so.0.9.8 => /usr/lib/libcrypto.so.0.9.8
(0x00007f25cfbfd000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007f25cf9e0000)
libc.so.6 => /lib/libc.so.6 (0x00007f25cf67f000)
libdl.so.2 => /lib/libdl.so.2 (0x00007f25cf47b000)
/lib64/ld-linux-x86-64.so.2 (0x00007f25d01c0000)
It only needs to link to libc, but I didn't find out when I last
checked how to convince the Makefile to only link against
that. Help welcome :)This is still an issue. It needs to link to libgit for xmalloc() and friends, but it doesn't need libz, libcrypto etc.
* Deal with the changes in 92c62a3f4f93432c0c82e3031a9e64e03ba290f7:
$ git --no-pager grep -A1 abomination *.sh
git-pull.sh: # XXX: This is an abomination
git-pull.sh- require_clean_work_tree "pull with
rebase" "Please commit or stash them."
The changes Ramkumar Ramachandra made in 92c62a3f4f, while good, are hard to square with i18n.
I think I'll just leave those bits untranslated for now and deal with them later, since I'm trying to keep this minimal.
This is not part of this RFC series, but I still haven't dealt with it in my branch.
And then there's the issue that unlike the C patches these will not be a no-op that'll be optimized away by the compiler. We'll be calling an external program for displaying messages. While this is a trivial cost on Unix (especially in the context we're using it, i.e. not in tight loops) it's more expensive on Windows.
I don't see any way to deal with that short of implementing some pre-processor, but I think the cost is worth it, but others might disagree of course.
This is still a problem I think. Although there's been some work on this on the MinGW front from what I can gleam from the mailing list.
1. http://www.spinics.net/lists/git/msg151971.html
Ævar Arnfjörð Bjarmason (2):
git-sh-i18n--envsubst: our own envsubst(1) for eval_gettext() git-sh-i18n.sh: add no-op gettext() and eval_gettext() wrappers
.gitignore | 3 + Documentation/git-sh-i18n--envsubst.txt | 36 +++ Documentation/git-sh-i18n.txt | 57 ++++ Makefile | 2 + git-sh-i18n.sh | 17 ++ sh-i18n--envsubst.c | 444 +++++++++++++++++++++++++++++++ 6 files changed, 559 insertions(+), 0 deletions(-) create mode 100644 Documentation/git-sh-i18n--envsubst.txt create mode 100644 Documentation/git-sh-i18n.txt create mode 100644 git-sh-i18n.sh create mode 100644 sh-i18n--envsubst.c
Signature · 1 line
1.7.4.1
PATCH 1/2 git-sh-i18n--envsubst: our own envsubst(1) for eval_gettext()
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, 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". This happened with a message in git-am.sh that used the $cmdline variable.
To work around this, and to improve our variable expansion behavior (eval has security issues) I've imported a stripped-down version of gettext's envsubst(1) program. With it eval_gettext() is implemented like this:
eval_gettext() {
printf "%s" "$1" | (
export PATH $(git sh-i18n--envsubst --variables "$1");
git sh-i18n--envsubst "$1"
)
}These are the modifications I made to envsubst.c as I turned it into sh-i18n--envsubst.c:
* Added our git-compat-util.h header for xrealloc() and friends.
* Removed inclusion of gettext-specific headers.
* Removed most of main() and replaced it with my own. The modified version only does option parsing for --variables. That's all it needs.
* Modified error() invocations to use our error() instead of error(3).
* Replaced the gettext XNMALLOC(n, size) macro with just xmalloc(n). Since XNMALLOC() only allocated char's.
* Removed the string_list_destroy function. It's redundant (also in the upstream code).
* Replaced the use of stdbool.h (a C99 header) by doing the following replacements on the code:
* s/bool/unsigned short int/g
* s/true/1/g
* s/false/0/g
--- .gitignore | 2 + Documentation/git-sh-i18n--envsubst.txt | 36 +++ Makefile | 1 + sh-i18n--envsubst.c | 444 +++++++++++++++++++++++++++++++ 4 files changed, 483 insertions(+), 0 deletions(-) create mode 100644 Documentation/git-sh-i18n--envsubst.txt create mode 100644 sh-i18n--envsubst.c
.gitignore +2 -0
@@ -127,6 +127,8 @@ /git-rm /git-send-email /git-send-pack +/git-sh-i18n +/git-sh-i18n--envsubst /git-sh-setup /git-shell /git-shortlog
Documentation/git-sh-i18n--envsubst.txt new file +36 -0
@@ -0,0 +1,36 @@ +git-sh-i18n--envsubst(1) +======================== + +NAME +---- +git-sh-i18n--envsubst - Git's own envsubst(1) for i18n fallbacks + +DESCRIPTION +----------- + +This is not a command the end user would want to run. Ever. +This documentation is meant for people who are studying the +plumbing scripts and/or are writing new ones. + +git-sh-i18n--envsubst is Git's stripped-down copy of the GNU +`envsubst(1)` program that comes with the GNU gettext +package. It's used internally by linkgit:git-sh-i18n[1] to +provide the `eval_gettext` fallback on Solaris and systems +that don't have a gettext implementation. + +No promises are made about the interface, or that this +program won't disappear without warning in the next version +of Git. Don't use it. + +Author +------ +Written by Ævar Arnfjörð Bjarmason <[email protected]> + +Documentation +-------------- +Documentation by Ævar Arnfjörð Bjarmason and the git-list +<[email protected]>. + +GIT +--- +Part of the linkgit:git[1] suite
Makefile +1 -0
@@ -419,6 +419,7 @@ PROGRAM_OBJS += shell.o PROGRAM_OBJS += show-index.o PROGRAM_OBJS += upload-pack.o PROGRAM_OBJS += http-backend.o +PROGRAM_OBJS += sh-i18n--envsubst.o PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
sh-i18n--envsubst.c new file +444 -0
444 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 2/2 git-sh-i18n.sh: add no-op gettext() and eval_gettext() wrappers
In reply to Ævar Arnfjörð BjarmasonAdd a no-op wrapper library for Git's shell scripts. To split up the gettext series I'm first submitting patches to gettextize the source tree before I add any of the Makefile and Shell library changes needed to actually use them.
---
This documentation doesn't accurately reflect what it does *now*, but what it'll do eventually later in the series.
.gitignore | 1 + Documentation/git-sh-i18n.txt | 57 +++++++++++++++++++++++++++++++++++++++++ Makefile | 1 + git-sh-i18n.sh | 17 ++++++++++++ 4 files changed, 76 insertions(+), 0 deletions(-) create mode 100644 Documentation/git-sh-i18n.txt create mode 100644 git-sh-i18n.sh
.gitignore +1 -0
@@ -130,6 +130,7 @@ /git-sh-i18n /git-sh-i18n--envsubst /git-sh-setup +/git-sh-i18n /git-shell /git-shortlog /git-show
Documentation/git-sh-i18n.txt new file +57 -0
57 lines not on this page · raw message
Makefile +1 -0
@@ -386,6 +386,7 @@ SCRIPT_SH += git-web--browse.sh SCRIPT_LIB += git-mergetool--lib SCRIPT_LIB += git-parse-remote SCRIPT_LIB += git-sh-setup +SCRIPT_LIB += git-sh-i18n SCRIPT_PERL += git-add--interactive.perl SCRIPT_PERL += git-difftool.perl
git-sh-i18n.sh new file +17 -0
@@ -0,0 +1,17 @@ +#!/bin/sh +# +# Copyright (c) 2010 Ævar Arnfjörð Bjarmason +# +# This is a skeleton no-op implementation of gettext for Git. It'll be +# replaced by something that uses gettext.sh in a future patch series. + +gettext () { + printf "%s" "$1" +} + +eval_gettext () { + printf "%s" "$1" | ( + export PATH $(git sh-i18n--envsubst --variables "$1"); + git sh-i18n--envsubst "$1" + ) +}
Signature · 1 line
1.7.4.1
Re: [PATCH/RFC 1/2] git-sh-i18n--envsubst: our own envsubst(1) for eval_gettext()
In reply to a message not in the archiveQuoted 54 lines · Junio C Hamano
Quoted 9 lines · Ævar Arnfjörð Bjarmason
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\"" }Quoted 7 lines
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
Quoted 1 line
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: oureval_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: oureval_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