Merge branch 'js/i18n-windows'
authorJunio C Hamano <gitster@pobox.com>
Thu, 30 Jun 2011 00:03:13 +0000 (17:03 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 Jun 2011 00:03:13 +0000 (17:03 -0700)
* js/i18n-windows:
Windows: teach getenv to do a case-sensitive search
mingw.c: move definition of mingw_getenv down
sh-i18n--envsubst: do not crash when no arguments are given

1  2 
compat/mingw.c
sh-i18n--envsubst.c
diff --combined compat/mingw.c
index f6e9ff7762356e099d2fe20fd31359bc0a1f68a2,237a8c0e1f485fec2f0e6f1f1fdbbd1163fb7c89..6ef0cc4f99becd772a6fed1cfe2484a67b3a9000
@@@ -178,7 -178,7 +178,7 @@@ static int ask_yes_no_if_possible(cons
        vsnprintf(question, sizeof(question), format, args);
        va_end(args);
  
-       if ((retry_hook[0] = getenv("GIT_ASK_YESNO"))) {
+       if ((retry_hook[0] = mingw_getenv("GIT_ASK_YESNO"))) {
                retry_hook[1] = question;
                return !run_command_v_opt(retry_hook, 0);
        }
@@@ -599,19 -599,6 +599,6 @@@ char *mingw_getcwd(char *pointer, int l
        return ret;
  }
  
- #undef getenv
- char *mingw_getenv(const char *name)
- {
-       char *result = getenv(name);
-       if (!result && !strcmp(name, "TMPDIR")) {
-               /* on Windows it is TMP and TEMP */
-               result = getenv("TMP");
-               if (!result)
-                       result = getenv("TEMP");
-       }
-       return result;
- }
  /*
   * See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
   * (Parsing C++ Command-Line Arguments)
@@@ -711,7 -698,7 +698,7 @@@ static const char *parse_interpreter(co
   */
  static char **get_path_split(void)
  {
-       char *p, **path, *envpath = getenv("PATH");
+       char *p, **path, *envpath = mingw_getenv("PATH");
        int i, n = 0;
  
        if (!envpath || !*envpath)
@@@ -1128,6 -1115,36 +1115,36 @@@ char **make_augmented_environ(const cha
        return env;
  }
  
+ #undef getenv
+ /*
+  * The system's getenv looks up the name in a case-insensitive manner.
+  * This version tries a case-sensitive lookup and falls back to
+  * case-insensitive if nothing was found.  This is necessary because,
+  * as a prominent example, CMD sets 'Path', but not 'PATH'.
+  * Warning: not thread-safe.
+  */
+ static char *getenv_cs(const char *name)
+ {
+       size_t len = strlen(name);
+       int i = lookup_env(environ, name, len);
+       if (i >= 0)
+               return environ[i] + len + 1;    /* skip past name and '=' */
+       return getenv(name);
+ }
+ char *mingw_getenv(const char *name)
+ {
+       char *result = getenv_cs(name);
+       if (!result && !strcmp(name, "TMPDIR")) {
+               /* on Windows it is TMP and TEMP */
+               result = getenv_cs("TMP");
+               if (!result)
+                       result = getenv_cs("TEMP");
+       }
+       return result;
+ }
  /*
   * Note, this isn't a complete replacement for getaddrinfo. It assumes
   * that service contains a numerical port, or that it is null. It
@@@ -1381,13 -1398,6 +1398,13 @@@ int mingw_setsockopt(int sockfd, int lv
        return setsockopt(s, lvl, optname, (const char*)optval, optlen);
  }
  
 +#undef shutdown
 +int mingw_shutdown(int sockfd, int how)
 +{
 +      SOCKET s = (SOCKET)_get_osfhandle(sockfd);
 +      return shutdown(s, how);
 +}
 +
  #undef listen
  int mingw_listen(int sockfd, int backlog)
  {
diff --combined sh-i18n--envsubst.c
index 9d2e971a275ede8a1365b2a2737452a873586707,81049739b6e9a37e3e745fb0666b2965ad09225e..5ddd6886c85356164e81c477d3a170343bc28049
@@@ -51,6 -51,7 +51,6 @@@
     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
  
  #include <errno.h>
 -#include <getopt.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
@@@ -67,12 -68,13 +67,13 @@@ in
  main (int argc, char *argv[])
  {
    /* Default values for command line options.  */
 -  unsigned short int show_variables = 0;
 +  /* unsigned short int show_variables = 0; */
  
    switch (argc)
        {
        case 1:
          error ("we won't substitute all variables on stdin for you");
+         break;
          /*
          all_variables = 1;
        subst_from_stdin ();
@@@ -87,7 -89,7 +88,7 @@@
          /* git sh-i18n--envsubst --variables '$foo and $bar' */
          if (strcmp(argv[1], "--variables"))
                error ("first argument must be --variables when two are given");
 -        show_variables = 1;
 +        /* show_variables = 1; */
        print_variables (argv[2]);
          break;
        default: