{"thread":{"id":"27349","subject":"[PATCH v2 0/4] i18n: Add shell script translation infrastructure","startedAt":"2011-05-14T13:47:41Z","lastAt":"2011-05-15T03:30:31Z","messageCount":6,"participants":["Ævar Arnfjörð Bjarmason","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":4},"messages":[{"id":"167843","messageId":"1305380865-21339-1-git-send-email-avarab@gmail.com","threadId":"27349","inReplyTo":null,"subject":"[PATCH v2 0/4] i18n: Add shell script translation infrastructure","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2011-05-14T13:47:41Z","receivedAt":"2011-05-14T13:47:41Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"This is v2 of the \"Add shell script translation infrastructure\"\nseries. Changes:\n\n  * The Author & Documentation sections from the documentation are now\n    gone. These should no longer be included, but the patch series\n    preceded that convention.\n\n  * Update the git-sh-i18n.txt and git-sh-i18n--envsubst.txt\n    documentation to accurately reflect what the skeleton fall-through\n    wrappers do.\n\n  * Updated the commit message for \"git-sh-i18n--envsubst: our own\n    envsubst(1) for eval_gettext()\" to not include a lengthy\n    description of failed eval_gettext experiments at Junio's\n    suggestion.\n\nÆvar Arnfjörð Bjarmason (4):\n  git-sh-i18n--envsubst: our own envsubst(1) for eval_gettext()\n  git-sh-i18n.sh: add no-op gettext() and eval_gettext() wrappers\n  git-sh-i18n.sh: add GIT_GETTEXT_POISON support\n  Makefile: add xgettext target for *.sh files\n\n .gitignore                              |    3 +\n Documentation/git-sh-i18n--envsubst.txt |   26 ++\n Documentation/git-sh-i18n.txt           |   42 +++\n Makefile                                |    8 +-\n git-sh-i18n.sh                          |   29 ++\n sh-i18n--envsubst.c                     |  444 +++++++++++++++++++++++++++++++\n t/t0201-gettext-fallbacks.sh            |   51 ++++\n 7 files changed, 602 insertions(+), 1 deletions(-)\n create mode 100644 Documentation/git-sh-i18n--envsubst.txt\n create mode 100644 Documentation/git-sh-i18n.txt\n create mode 100644 git-sh-i18n.sh\n create mode 100644 sh-i18n--envsubst.c\n create mode 100755 t/t0201-gettext-fallbacks.sh\n\n-- \n1.7.4.4\n"},{"id":"167844","messageId":"1305380865-21339-2-git-send-email-avarab@gmail.com","threadId":"27349","inReplyTo":"1305380865-21339-1-git-send-email-avarab@gmail.com","subject":"[PATCH v2 1/4] git-sh-i18n--envsubst: our own envsubst(1) for eval_gettext()","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2011-05-14T13:47:42Z","receivedAt":"2011-05-14T13:47:42Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add a git-sh-i18n--envsubst program which is a stripped-down version\nof the GNU envsubst(1) program that comes with GNU gettext for use in\nthe eval_gettext() fallback.\n\nWe need a C helper program because implementing eval_gettext() purely\nin shell turned out to be unworkable. Digging through the Git mailing\nlist archives will reveal two shell implementations of eval_gettext\nthat are almost good enough, but fail on an edge case which is tested\nfor in the tests which are part of this patch.\n\nThese are the modifications I made to envsubst.c as I turned it into\nsh-i18n--envsubst.c:\n\n * Added our git-compat-util.h header for xrealloc() and friends.\n\n * Removed inclusion of gettext-specific headers.\n\n * Removed most of main() and replaced it with my own. The modified\n   version only does option parsing for --variables. That's all it\n   needs.\n\n * Modified error() invocations to use our error() instead of\n   error(3).\n\n * Replaced the gettext XNMALLOC(n, size) macro with just\n   xmalloc(n). Since XNMALLOC() only allocated char's.\n\n * Removed the string_list_destroy function. It's redundant (also in\n   the upstream code).\n\n * Replaced the use of stdbool.h (a C99 header) by doing the following\n   replacements on the code:\n\n    * s/bool/unsigned short int/g\n    * s/true/1/g\n    * s/false/0/g\n\nReported-by: Johannes Sixt <j.sixt@viscovery.net>\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .gitignore                              |    2 +\n Documentation/git-sh-i18n--envsubst.txt |   26 ++\n Makefile                                |    1 +\n sh-i18n--envsubst.c                     |  444 +++++++++++++++++++++++++++++++\n t/t0201-gettext-fallbacks.sh            |   51 ++++\n 5 files changed, 524 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/git-sh-i18n--envsubst.txt\n create mode 100644 sh-i18n--envsubst.c\n create mode 100755 t/t0201-gettext-fallbacks.sh\n\ndiff --git a/.gitignore b/.gitignore\nindex 711fce7..1ccf797 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -127,6 +127,8 @@\n /git-rm\n /git-send-email\n /git-send-pack\n+/git-sh-i18n\n+/git-sh-i18n--envsubst\n /git-sh-setup\n /git-shell\n /git-shortlog\ndiff --git a/Documentation/git-sh-i18n--envsubst.txt b/Documentation/git-sh-i18n--envsubst.txt\nnew file mode 100644\nindex 0000000..f5bbf77\n--- /dev/null\n+++ b/Documentation/git-sh-i18n--envsubst.txt\n@@ -0,0 +1,26 @@\n+git-sh-i18n--envsubst(1)\n+========================\n+\n+NAME\n+----\n+git-sh-i18n--envsubst - Git's own envsubst(1) for i18n fallbacks\n+\n+DESCRIPTION\n+-----------\n+\n+This is not a command the end user would want to run.  Ever.\n+This documentation is meant for people who are studying the\n+plumbing scripts and/or are writing new ones.\n+\n+git-sh-i18n--envsubst is Git's stripped-down copy of the GNU\n+`envsubst(1)` program that comes with the GNU gettext package. It's\n+used internally by linkgit:git-sh-i18n[1] to interpolate the variables\n+passed to the the `eval_gettext` function.\n+\n+No promises are made about the interface, or that this\n+program won't disappear without warning in the next version\n+of Git. Don't use it.\n+\n+GIT\n+---\n+Part of the linkgit:git[1] suite\ndiff --git a/Makefile b/Makefile\nindex 320ccc7..56944c6 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -414,6 +414,7 @@ PROGRAM_OBJS += shell.o\n PROGRAM_OBJS += show-index.o\n PROGRAM_OBJS += upload-pack.o\n PROGRAM_OBJS += http-backend.o\n+PROGRAM_OBJS += sh-i18n--envsubst.o\n \n PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))\n \ndiff --git a/sh-i18n--envsubst.c b/sh-i18n--envsubst.c\nnew file mode 100644\nindex 0000000..8db71b1\n--- /dev/null\n+++ b/sh-i18n--envsubst.c\n@@ -0,0 +1,444 @@\n+/*\n+ * sh-i18n--envsubst.c - a stripped-down version of gettext's envsubst(1)\n+ *\n+ * Copyright (C) 2010 Ævar Arnfjörð Bjarmason\n+ *\n+ * This is a modified version of\n+ * 67d0871a8c:gettext-runtime/src/envsubst.c from the gettext.git\n+ * repository. It has been stripped down to only implement the\n+ * envsubst(1) features that we need in the git-sh-i18n fallbacks.\n+ *\n+ * The \"Close standard error\" part in main() is from\n+ * 8dac033df0:gnulib-local/lib/closeout.c. The copyright notices for\n+ * both files are reproduced immediately below.\n+ */\n+\n+#include \"git-compat-util.h\"\n+\n+/* Substitution of environment variables in shell format strings.\n+   Copyright (C) 2003-2007 Free Software Foundation, Inc.\n+   Written by Bruno Haible <bruno@clisp.org>, 2003.\n+\n+   This program is free software; you can redistribute it and/or modify\n+   it under the terms of the GNU General Public License as published by\n+   the Free Software Foundation; either version 2, or (at your option)\n+   any later version.\n+\n+   This program is distributed in the hope that it will be useful,\n+   but WITHOUT ANY WARRANTY; without even the implied warranty of\n+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+   GNU General Public License for more details.\n+\n+   You should have received a copy of the GNU General Public License\n+   along with this program; if not, write to the Free Software Foundation,\n+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */\n+\n+/* closeout.c - close standard output and standard error\n+   Copyright (C) 1998-2007 Free Software Foundation, Inc.\n+\n+   This program is free software; you can redistribute it and/or modify\n+   it under the terms of the GNU General Public License as published by\n+   the Free Software Foundation; either version 2, or (at your option)\n+   any later version.\n+\n+   This program is distributed in the hope that it will be useful,\n+   but WITHOUT ANY WARRANTY; without even the implied warranty of\n+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+   GNU General Public License for more details.\n+\n+   You should have received a copy of the GNU General Public License\n+   along with this program; if not, write to the Free Software Foundation,\n+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */\n+\n+#include <errno.h>\n+#include <getopt.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <string.h>\n+\n+/* If true, substitution shall be performed on all variables.  */\n+static unsigned short int all_variables;\n+\n+/* Forward declaration of local functions.  */\n+static void print_variables (const char *string);\n+static void note_variables (const char *string);\n+static void subst_from_stdin (void);\n+\n+int\n+main (int argc, char *argv[])\n+{\n+  /* Default values for command line options.  */\n+  unsigned short int show_variables = 0;\n+\n+  switch (argc)\n+\t{\n+\tcase 1:\n+\t  error (\"we won't substitute all variables on stdin for you\");\n+\t  /*\n+\t  all_variables = 1;\n+      subst_from_stdin ();\n+\t  */\n+\tcase 2:\n+\t  /* echo '$foo and $bar' | git sh-i18n--envsubst --variables '$foo and $bar' */\n+\t  all_variables = 0;\n+\t  note_variables (argv[1]);\n+      subst_from_stdin ();\n+\t  break;\n+\tcase 3:\n+\t  /* git sh-i18n--envsubst --variables '$foo and $bar' */\n+\t  if (strcmp(argv[1], \"--variables\"))\n+\t\terror (\"first argument must be --variables when two are given\");\n+\t  show_variables = 1;\n+      print_variables (argv[2]);\n+\t  break;\n+\tdefault:\n+\t  error (\"too many arguments\");\n+\t  break;\n+\t}\n+\n+  /* Close standard error.  This is simpler than fwriteerror_no_ebadf, because\n+     upon failure we don't need an errno - all we can do at this point is to\n+     set an exit status.  */\n+  errno = 0;\n+  if (ferror (stderr) || fflush (stderr))\n+    { \n+      fclose (stderr);\n+      exit (EXIT_FAILURE);\n+    }\n+  if (fclose (stderr) && errno != EBADF)\n+    exit (EXIT_FAILURE);\n+\n+  exit (EXIT_SUCCESS);\n+}\n+\n+/* Parse the string and invoke the callback each time a $VARIABLE or\n+   ${VARIABLE} construct is seen, where VARIABLE is a nonempty sequence\n+   of ASCII alphanumeric/underscore characters, starting with an ASCII\n+   alphabetic/underscore character.\n+   We allow only ASCII characters, to avoid dependencies w.r.t. the current\n+   encoding: While \"${\\xe0}\" looks like a variable access in ISO-8859-1\n+   encoding, it doesn't look like one in the BIG5, BIG5-HKSCS, GBK, GB18030,\n+   SHIFT_JIS, JOHAB encodings, because \\xe0\\x7d is a single character in these\n+   encodings.  */\n+static void\n+find_variables (const char *string,\n+\t\tvoid (*callback) (const char *var_ptr, size_t var_len))\n+{\n+  for (; *string != '\\0';)\n+    if (*string++ == '$')\n+      {\n+\tconst char *variable_start;\n+\tconst char *variable_end;\n+\tunsigned short int valid;\n+\tchar c;\n+\n+\tif (*string == '{')\n+\t  string++;\n+\n+\tvariable_start = string;\n+\tc = *string;\n+\tif ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')\n+\t  {\n+\t    do\n+\t      c = *++string;\n+\t    while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')\n+\t\t   || (c >= '0' && c <= '9') || c == '_');\n+\t    variable_end = string;\n+\n+\t    if (variable_start[-1] == '{')\n+\t      {\n+\t\tif (*string == '}')\n+\t\t  {\n+\t\t    string++;\n+\t\t    valid = 1;\n+\t\t  }\n+\t\telse\n+\t\t  valid = 0;\n+\t      }\n+\t    else\n+\t      valid = 1;\n+\n+\t    if (valid)\n+\t      callback (variable_start, variable_end - variable_start);\n+\t  }\n+      }\n+}\n+\n+\n+/* Print a variable to stdout, followed by a newline.  */\n+static void\n+print_variable (const char *var_ptr, size_t var_len)\n+{\n+  fwrite (var_ptr, var_len, 1, stdout);\n+  putchar ('\\n');\n+}\n+\n+/* Print the variables contained in STRING to stdout, each one followed by a\n+   newline.  */\n+static void\n+print_variables (const char *string)\n+{\n+  find_variables (string, &print_variable);\n+}\n+\n+\n+/* Type describing list of immutable strings,\n+   implemented using a dynamic array.  */\n+typedef struct string_list_ty string_list_ty;\n+struct string_list_ty\n+{\n+  const char **item;\n+  size_t nitems;\n+  size_t nitems_max;\n+};\n+\n+/* Initialize an empty list of strings.  */\n+static inline void\n+string_list_init (string_list_ty *slp)\n+{\n+  slp->item = NULL;\n+  slp->nitems = 0;\n+  slp->nitems_max = 0;\n+}\n+\n+/* Append a single string to the end of a list of strings.  */\n+static inline void\n+string_list_append (string_list_ty *slp, const char *s)\n+{\n+  /* Grow the list.  */\n+  if (slp->nitems >= slp->nitems_max)\n+    {\n+      size_t nbytes;\n+\n+      slp->nitems_max = slp->nitems_max * 2 + 4;\n+      nbytes = slp->nitems_max * sizeof (slp->item[0]);\n+      slp->item = (const char **) xrealloc (slp->item, nbytes);\n+    }\n+\n+  /* Add the string to the end of the list.  */\n+  slp->item[slp->nitems++] = s;\n+}\n+\n+/* Compare two strings given by reference.  */\n+static int\n+cmp_string (const void *pstr1, const void *pstr2)\n+{\n+  const char *str1 = *(const char **)pstr1;\n+  const char *str2 = *(const char **)pstr2;\n+\n+  return strcmp (str1, str2);\n+}\n+\n+/* Sort a list of strings.  */\n+static inline void\n+string_list_sort (string_list_ty *slp)\n+{\n+  if (slp->nitems > 0)\n+    qsort (slp->item, slp->nitems, sizeof (slp->item[0]), cmp_string);\n+}\n+\n+/* Test whether a string list contains a given string.  */\n+static inline int\n+string_list_member (const string_list_ty *slp, const char *s)\n+{\n+  size_t j;\n+\n+  for (j = 0; j < slp->nitems; ++j)\n+    if (strcmp (slp->item[j], s) == 0)\n+      return 1;\n+  return 0;\n+}\n+\n+/* Test whether a sorted string list contains a given string.  */\n+static int\n+sorted_string_list_member (const string_list_ty *slp, const char *s)\n+{\n+  size_t j1, j2;\n+\n+  j1 = 0;\n+  j2 = slp->nitems;\n+  if (j2 > 0)\n+    {\n+      /* Binary search.  */\n+      while (j2 - j1 > 1)\n+\t{\n+\t  /* Here we know that if s is in the list, it is at an index j\n+\t     with j1 <= j < j2.  */\n+\t  size_t j = (j1 + j2) >> 1;\n+\t  int result = strcmp (slp->item[j], s);\n+\n+\t  if (result > 0)\n+\t    j2 = j;\n+\t  else if (result == 0)\n+\t    return 1;\n+\t  else\n+\t    j1 = j + 1;\n+\t}\n+      if (j2 > j1)\n+\tif (strcmp (slp->item[j1], s) == 0)\n+\t  return 1;\n+    }\n+  return 0;\n+}\n+\n+\n+/* Set of variables on which to perform substitution.\n+   Used only if !all_variables.  */\n+static string_list_ty variables_set;\n+\n+/* Adds a variable to variables_set.  */\n+static void\n+note_variable (const char *var_ptr, size_t var_len)\n+{\n+  char *string = xmalloc (var_len + 1);\n+  memcpy (string, var_ptr, var_len);\n+  string[var_len] = '\\0';\n+\n+  string_list_append (&variables_set, string);\n+}\n+\n+/* Stores the variables occurring in the string in variables_set.  */\n+static void\n+note_variables (const char *string)\n+{\n+  string_list_init (&variables_set);\n+  find_variables (string, &note_variable);\n+  string_list_sort (&variables_set);\n+}\n+\n+\n+static int\n+do_getc ()\n+{\n+  int c = getc (stdin);\n+\n+  if (c == EOF)\n+    {\n+      if (ferror (stdin))\n+\terror (\"error while reading standard input\");\n+    }\n+\n+  return c;\n+}\n+\n+static inline void\n+do_ungetc (int c)\n+{\n+  if (c != EOF)\n+    ungetc (c, stdin);\n+}\n+\n+/* Copies stdin to stdout, performing substitutions.  */\n+static void\n+subst_from_stdin ()\n+{\n+  static char *buffer;\n+  static size_t bufmax;\n+  static size_t buflen;\n+  int c;\n+\n+  for (;;)\n+    {\n+      c = do_getc ();\n+      if (c == EOF)\n+\tbreak;\n+      /* Look for $VARIABLE or ${VARIABLE}.  */\n+      if (c == '$')\n+\t{\n+\t  unsigned short int opening_brace = 0;\n+\t  unsigned short int closing_brace = 0;\n+\n+\t  c = do_getc ();\n+\t  if (c == '{')\n+\t    {\n+\t      opening_brace = 1;\n+\t      c = do_getc ();\n+\t    }\n+\t  if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')\n+\t    {\n+\t      unsigned short int valid;\n+\n+\t      /* Accumulate the VARIABLE in buffer.  */\n+\t      buflen = 0;\n+\t      do\n+\t\t{\n+\t\t  if (buflen >= bufmax)\n+\t\t    {\n+\t\t      bufmax = 2 * bufmax + 10;\n+\t\t      buffer = xrealloc (buffer, bufmax);\n+\t\t    }\n+\t\t  buffer[buflen++] = c;\n+\n+\t\t  c = do_getc ();\n+\t\t}\n+\t      while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')\n+\t\t     || (c >= '0' && c <= '9') || c == '_');\n+\n+\t      if (opening_brace)\n+\t\t{\n+\t\t  if (c == '}')\n+\t\t    {\n+\t\t      closing_brace = 1;\n+\t\t      valid = 1;\n+\t\t    }\n+\t\t  else\n+\t\t    {\n+\t\t      valid = 0;\n+\t\t      do_ungetc (c);\n+\t\t    }\n+\t\t}\n+\t      else\n+\t\t{\n+\t\t  valid = 1;\n+\t\t  do_ungetc (c);\n+\t\t}\n+\n+\t      if (valid)\n+\t\t{\n+\t\t  /* Terminate the variable in the buffer.  */\n+\t\t  if (buflen >= bufmax)\n+\t\t    {\n+\t\t      bufmax = 2 * bufmax + 10;\n+\t\t      buffer = xrealloc (buffer, bufmax);\n+\t\t    }\n+\t\t  buffer[buflen] = '\\0';\n+\n+\t\t  /* Test whether the variable shall be substituted.  */\n+\t\t  if (!all_variables\n+\t\t      && !sorted_string_list_member (&variables_set, buffer))\n+\t\t    valid = 0;\n+\t\t}\n+\n+\t      if (valid)\n+\t\t{\n+\t\t  /* Substitute the variable's value from the environment.  */\n+\t\t  const char *env_value = getenv (buffer);\n+\n+\t\t  if (env_value != NULL)\n+\t\t    fputs (env_value, stdout);\n+\t\t}\n+\t      else\n+\t\t{\n+\t\t  /* Perform no substitution at all.  Since the buffered input\n+\t\t     contains no other '$' than at the start, we can just\n+\t\t     output all the buffered contents.  */\n+\t\t  putchar ('$');\n+\t\t  if (opening_brace)\n+\t\t    putchar ('{');\n+\t\t  fwrite (buffer, buflen, 1, stdout);\n+\t\t  if (closing_brace)\n+\t\t    putchar ('}');\n+\t\t}\n+\t    }\n+\t  else\n+\t    {\n+\t      do_ungetc (c);\n+\t      putchar ('$');\n+\t      if (opening_brace)\n+\t\tputchar ('{');\n+\t    }\n+\t}\n+      else\n+\tputchar (c);\n+    }\n+}\ndiff --git a/t/t0201-gettext-fallbacks.sh b/t/t0201-gettext-fallbacks.sh\nnew file mode 100755\nindex 0000000..54d98b9\n--- /dev/null\n+++ b/t/t0201-gettext-fallbacks.sh\n@@ -0,0 +1,51 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2010 Ævar Arnfjörð Bjarmason\n+#\n+\n+test_description='Gettext Shell fallbacks'\n+\n+. ./test-lib.sh\n+. \"$GIT_BUILD_DIR\"/git-sh-i18n\n+\n+test_expect_success 'gettext: our gettext() fallback has pass-through semantics' '\n+    printf \"test\" >expect &&\n+    gettext \"test\" >actual &&\n+    test_i18ncmp expect actual &&\n+    printf \"test more words\" >expect &&\n+    gettext \"test more words\" >actual &&\n+    test_i18ncmp expect actual\n+'\n+\n+test_expect_success 'eval_gettext: our eval_gettext() fallback has pass-through semantics' '\n+    printf \"test\" >expect &&\n+    eval_gettext \"test\" >actual &&\n+    test_i18ncmp expect actual &&\n+    printf \"test more words\" >expect &&\n+    eval_gettext \"test more words\" >actual &&\n+    test_i18ncmp expect actual\n+'\n+\n+test_expect_success 'eval_gettext: our eval_gettext() fallback can interpolate variables' '\n+    printf \"test YesPlease\" >expect &&\n+    GIT_INTERNAL_GETTEXT_TEST_FALLBACKS=YesPlease eval_gettext \"test \\$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS\" >actual &&\n+    test_i18ncmp expect actual\n+'\n+\n+test_expect_success 'eval_gettext: our eval_gettext() fallback can interpolate variables with spaces' '\n+    cmdline=\"git am\" &&\n+    export cmdline;\n+    printf \"When you have resolved this problem run git am --resolved.\" >expect &&\n+    eval_gettext \"When you have resolved this problem run \\$cmdline --resolved.\" >actual\n+    test_i18ncmp expect actual\n+'\n+\n+test_expect_success 'eval_gettext: our eval_gettext() fallback can interpolate variables with spaces and quotes' '\n+    cmdline=\"git am\" &&\n+    export cmdline;\n+    printf \"When you have resolved this problem run \\\"git am --resolved\\\".\" >expect &&\n+    eval_gettext \"When you have resolved this problem run \\\"\\$cmdline --resolved\\\".\" >actual\n+    test_i18ncmp expect actual\n+'\n+\n+test_done\n-- \n1.7.4.4\n"},{"id":"167846","messageId":"1305380865-21339-3-git-send-email-avarab@gmail.com","threadId":"27349","inReplyTo":"1305380865-21339-1-git-send-email-avarab@gmail.com","subject":"[PATCH v2 2/4] git-sh-i18n.sh: add no-op gettext() and eval_gettext() wrappers","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2011-05-14T13:47:43Z","receivedAt":"2011-05-14T13:47:43Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add a no-op wrapper library for Git's shell scripts. To split up the\ngettext series I'm first submitting patches to gettextize the source\ntree before I add any of the Makefile and Shell library changes needed\nto actually use them.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .gitignore                    |    1 +\n Documentation/git-sh-i18n.txt |   42 +++++++++++++++++++++++++++++++++++++++++\n Makefile                      |    1 +\n git-sh-i18n.sh                |   17 ++++++++++++++++\n 4 files changed, 61 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/git-sh-i18n.txt\n create mode 100644 git-sh-i18n.sh\n\ndiff --git a/.gitignore b/.gitignore\nindex 1ccf797..4bdb839 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -130,6 +130,7 @@\n /git-sh-i18n\n /git-sh-i18n--envsubst\n /git-sh-setup\n+/git-sh-i18n\n /git-shell\n /git-shortlog\n /git-show\ndiff --git a/Documentation/git-sh-i18n.txt b/Documentation/git-sh-i18n.txt\nnew file mode 100644\nindex 0000000..8b86e5f\n--- /dev/null\n+++ b/Documentation/git-sh-i18n.txt\n@@ -0,0 +1,42 @@\n+git-sh-i18n(1)\n+==============\n+\n+NAME\n+----\n+git-sh-i18n - Git's i18n setup code for shell scripts\n+\n+SYNOPSIS\n+--------\n+'. \"$(git --exec-path)/git-sh-i18n\"'\n+\n+DESCRIPTION\n+-----------\n+\n+This is not a command the end user would want to run.  Ever.\n+This documentation is meant for people who are studying the\n+Porcelain-ish scripts and/or are writing new ones.\n+\n+The 'git sh-i18n scriptlet is designed to be sourced (using\n+`.`) by Git's porcelain programs implemented in shell\n+script. It provides wrappers for the GNU `gettext` and\n+`eval_gettext` functions accessible through the `gettext.sh`\n+script, and provides pass-through fallbacks on systems\n+without GNU gettext.\n+\n+FUNCTIONS\n+---------\n+\n+gettext::\n+\tCurrently a dummy fall-through function implemented as a wrapper\n+\taround `printf(1)`. Will be replaced by a real gettext\n+\timplementation in a later version.\n+    \n+eval_gettext::\n+\tCurrently a dummy fall-through function implemented as a wrapper\n+\taround `printf(1)` with variables expanded by the\n+\tlinkgit:git-sh-i18n--envsubst[1] helper. Will be replaced by a\n+\treal gettext implementation in a later version.\n+\n+GIT\n+---\n+Part of the linkgit:git[1] suite\ndiff --git a/Makefile b/Makefile\nindex 56944c6..854fe69 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -381,6 +381,7 @@ SCRIPT_LIB += git-rebase--am\n SCRIPT_LIB += git-rebase--interactive\n SCRIPT_LIB += git-rebase--merge\n SCRIPT_LIB += git-sh-setup\n+SCRIPT_LIB += git-sh-i18n\n \n SCRIPT_PERL += git-add--interactive.perl\n SCRIPT_PERL += git-difftool.perl\ndiff --git a/git-sh-i18n.sh b/git-sh-i18n.sh\nnew file mode 100644\nindex 0000000..ea05e16\n--- /dev/null\n+++ b/git-sh-i18n.sh\n@@ -0,0 +1,17 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2010 Ævar Arnfjörð Bjarmason\n+#\n+# This is a skeleton no-op implementation of gettext for Git. It'll be\n+# replaced by something that uses gettext.sh in a future patch series.\n+\n+gettext () {\n+\tprintf \"%s\" \"$1\"\n+}\n+\n+eval_gettext () {\n+\tprintf \"%s\" \"$1\" | (\n+\t\texport PATH $(git sh-i18n--envsubst --variables \"$1\");\n+\t\tgit sh-i18n--envsubst \"$1\"\n+\t)\n+}\n-- \n1.7.4.4\n"},{"id":"167847","messageId":"1305380865-21339-4-git-send-email-avarab@gmail.com","threadId":"27349","inReplyTo":"1305380865-21339-1-git-send-email-avarab@gmail.com","subject":"[PATCH v2 3/4] git-sh-i18n.sh: add GIT_GETTEXT_POISON support","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2011-05-14T13:47:44Z","receivedAt":"2011-05-14T13:47:44Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change git-sh-i18n.sh to support the GIT_GETTEXT_POISON environment\nvariable like gettext.c does, this ensures that tests that use\ngit-sh-i18n.sh will fail under GETTEXT_POISON=YesPlease if they rely\non Git's C locale messages without declaring that they do.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n git-sh-i18n.sh |   30 +++++++++++++++++++++---------\n 1 files changed, 21 insertions(+), 9 deletions(-)\n\ndiff --git a/git-sh-i18n.sh b/git-sh-i18n.sh\nindex ea05e16..32ca59d 100644\n--- a/git-sh-i18n.sh\n+++ b/git-sh-i18n.sh\n@@ -5,13 +5,25 @@\n # This is a skeleton no-op implementation of gettext for Git. It'll be\n # replaced by something that uses gettext.sh in a future patch series.\n \n-gettext () {\n-\tprintf \"%s\" \"$1\"\n-}\n+if test -z \"$GIT_GETTEXT_POISON\"\n+then\n+\tgettext () {\n+\t\tprintf \"%s\" \"$1\"\n+\t}\n+\n+\teval_gettext () {\n+\t\tprintf \"%s\" \"$1\" | (\n+\t\t\texport PATH $(git sh-i18n--envsubst --variables \"$1\");\n+\t\t\tgit sh-i18n--envsubst \"$1\"\n+\t\t)\n+\t}\n+else\n+\tgettext () {\n+\t\tprintf \"%s\" \"# GETTEXT POISON #\"\n+\t}\n+\n+\teval_gettext () {\n+\t\tprintf \"%s\" \"# GETTEXT POISON #\"\n+\t}\n+fi\n \n-eval_gettext () {\n-\tprintf \"%s\" \"$1\" | (\n-\t\texport PATH $(git sh-i18n--envsubst --variables \"$1\");\n-\t\tgit sh-i18n--envsubst \"$1\"\n-\t)\n-}\n-- \n1.7.4.4\n"},{"id":"167845","messageId":"1305380865-21339-5-git-send-email-avarab@gmail.com","threadId":"27349","inReplyTo":"1305380865-21339-1-git-send-email-avarab@gmail.com","subject":"[PATCH v2 4/4] Makefile: add xgettext target for *.sh files","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2011-05-14T13:47:45Z","receivedAt":"2011-05-14T13:47:45Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the \"pot\" target to also extract strings from our $(SCRIPT_SH)\nfiles with xgettext(1).\n\nNote that due to Jonathan Nieder's trick of doing \"mv $@+ $@\" at the\nend of the target the \"pot\" target will now warn:\n\n    $ make pot\n        XGETTEXT po/git.pot\n    po/git.pot+: warning: Charset \"CHARSET\" is not a portable encoding name.\n                          Message conversion to user's charset might not work.\n\nThis warnings is emitted because xgettext is writing into a non-*.pot\nfile, it's harmless however. The content that's written out is\nequivalent to what it would be if we were writing directly into an\nexisting POT file with --join-existing.\n\nAs part of this change I've eliminated the && chain between xgettext\ncalls, this is incompatible with $(QUIET_XGETTEXT), if the && is left\nin it'll emit:\n\n    /bin/sh: @echo: not found\n\nSince it's redundant (the Makefile will stop if there's an error) I've\nremoved it altogether.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n Makefile |    6 +++++-\n 1 files changed, 5 insertions(+), 1 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 854fe69..1b1a7e8 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -2039,10 +2039,14 @@ XGETTEXT_FLAGS = \\\n \t--from-code=UTF-8\n XGETTEXT_FLAGS_C = $(XGETTEXT_FLAGS) --language=C \\\n \t--keyword=_ --keyword=N_ --keyword=\"Q_:1,2\"\n+XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell\n LOCALIZED_C := $(C_OBJ:o=c)\n+LOCALIZED_SH := $(SCRIPT_SH)\n \n po/git.pot: $(LOCALIZED_C)\n-\t$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C) && \\\n+\t$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)\n+\t$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_SH) \\\n+\t\t$(LOCALIZED_SH)\n \tmv $@+ $@\n \n pot: po/git.pot\n-- \n1.7.4.4\n"},{"id":"167875","messageId":"7v8vu8r67c.fsf@alter.siamese.dyndns.org","threadId":"27349","inReplyTo":"1305380865-21339-2-git-send-email-avarab@gmail.com","subject":"Re: [PATCH v2 1/4] git-sh-i18n--envsubst: our own envsubst(1) for eval_gettext()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-05-15T03:30:31Z","receivedAt":"2011-05-15T03:30:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n\n> +static int\n> +do_getc ()\n\ndo_getc (void)\n\n> +/* Copies stdin to stdout, performing substitutions.  */\n> +static void\n> +subst_from_stdin ()\n\nsubst_from_stdin (void)\n\nWill update these again and queue.\nThanks.\n"}]}