Skip to contentSkip to conversation

WIP: git-sh-i18n--envsubst for a correct eval_gettext

WIP RFC/PATCH Ævar Arnfjörð Bjarmason 1 participant 1 message Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

t/t0201-gettext-fallbacks.sh: test for broken eval_gettext

Add a test for the broken eval_gettext() variable interpolation behavior.

git-sh-i18n.sh: use envsubst

WIP: add a git-sh-i18n--envsubst

I can't figure out how to make the Makefile read from git-sh-i18n--envsubst.c and produce git-sh-i18n--envsubst, not git-git-sh-i18n--envsubst.

I also can't see how to make it available to git tests.

If I name it sh-i18n--envsubst.c I'll get linking errors (about xrealloc).
---

Heading out so I thought I'd dump a WIP patch here and ask if anyone knows how to solve this Makefile issue I'm having.

I wanted to call the two programs /{git-sh-i18n.sh,git-sh-i18n--envsubst.c}, but maybe going that route is the wrong thing to do?

 .gitignore                   |    1 +
 Makefile                     |    3 +
 git-sh-i18n--envsubst.c      |  392 ++++++++++++++++++++++++++++++++++++++++++
 git-sh-i18n.sh               |    3 +-
 t/t0201-gettext-fallbacks.sh |   23 +++
 5 files changed, 420 insertions(+), 2 deletions(-)
 create mode 100644 git-sh-i18n--envsubst.c
.gitignore +1 -0
index 80ca718..d2d9ec2 100644
@@ -126,6 +126,7 @@
 /git-send-email
 /git-send-pack
 /git-sh-i18n
+/git-sh-i18n--envsubst
 /git-sh-setup
 /git-shell
 /git-shortlog
Makefile +3 -0
index e1650ba..cdfe6bc 100644
@@ -435,6 +435,7 @@ PROGRAM_OBJS += shell.o
 PROGRAM_OBJS += show-index.o
 PROGRAM_OBJS += upload-pack.o
 PROGRAM_OBJS += http-backend.o
+PROGRAM_OBJS += git-sh-i18n--envsubst.o
 
 PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
 
@@ -2016,6 +2017,8 @@ git-http-fetch$X: revision.o http.o http-walker.o http-fetch.o $(GITLIBS)
 git-http-push$X: revision.o http.o http-push.o $(GITLIBS)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 		$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
+git-sh-i18n--envsubst$X: git-sh-i18n--envsubst.o $(GITLIBS)
+	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^)
 
 $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
 	$(QUIET_LNCP)$(RM) $@ && \
git-sh-i18n--envsubst.c new file +392 -0

392 lines not on this page · raw message

git-sh-i18n.sh +1 -2
index f8dd43a..b3b599a 100644
@@ -55,8 +55,7 @@ then
 		}
 
 		eval_gettext () {
-			gettext_eval="printf '%s' \"$1\""
-			printf "%s" "`eval \"$gettext_eval\"`"
+			printf "%s" "$1" | /home/avar/g/git/git-git-sh-i18n--envsubst
 		}
 	fi
 else
t/t0201-gettext-fallbacks.sh +23 -0
index 7a85d9b..682c602 100755
@@ -46,4 +46,27 @@ test_expect_success NO_GETTEXT_POISON 'eval_gettext: our eval_gettext() fallback
     test_cmp expect actual
 '
 
+test_expect_success NO_GETTEXT_POISON 'eval_gettext: our eval_gettext() fallback can interpolate whitespace variables' '
+    git_am_cmdline="git am" &&
+    export git_am_cmdline &&
+    printf "test git am" >expect &&
+    eval_gettext "test \$git_am_cmdline" >actual &&
+    test_cmp expect actual
+'
+
+test_expect_success NO_GETTEXT_POISON 'eval_gettext: git am $cmdline bug' '
+    cmdline="git am -3" &&
+    export cmdline &&
+    cat >expect <<EOF &&
+When you have resolved this problem run "git am -3 --resolved".
+If you would prefer to skip this patch, instead run "git am -3 --skip".
+To restore the original branch and stop patching run "git am -3 --abort".
+EOF
+    eval_gettext "When you have resolved this problem run \"\$cmdline --resolved\".
+If you would prefer to skip this patch, instead run \"\$cmdline --skip\".
+To restore the original branch and stop patching run \"\$cmdline --abort\"." >actual &&
+    echo >>actual &&
+    test_cmp expect actual
+'
+
 test_done
Signature · 1 line
1.7.3.2.309.g4cea8.dirty