Skip to content

Commit

Permalink
git-sh-i18n--envsubst: our own envsubst(1) for eval_gettext()
Browse files Browse the repository at this point in the history
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.

We need a C helper program because implementing eval_gettext() purely
in shell turned out to be unworkable. Digging through the Git mailing
list archives will reveal two shell implementations of eval_gettext
that are almost good enough, but fail on an edge case which is tested
for in the tests which are part of this patch.

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

Reported-by: Johannes Sixt <j.sixt@viscovery.net>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Ævar Arnfjörð Bjarmason authored and Junio C Hamano committed May 15, 2011
1 parent 4e3aa87 commit ba67aaf
Show file tree
Hide file tree
Showing 5 changed files with 524 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions Documentation/git-sh-i18n--envsubst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 interpolate the variables
passed to the the `eval_gettext` function.

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.

GIT
---
Part of the linkgit:git[1] suite
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,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))

Expand Down
Loading

0 comments on commit ba67aaf

Please sign in to comment.