Merge branch 'jk/common-main' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 9 Sep 2016 04:35:50 +0000 (21:35 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 9 Sep 2016 04:35:51 +0000 (21:35 -0700)
There are certain house-keeping tasks that need to be performed at
the very beginning of any Git program, and programs that are not
built-in commands had to do them exactly the same way as "git"
potty does. It was easy to make mistakes in one-off standalone
programs (like test helpers). A common "main()" function that
calls cmd_main() of individual program has been introduced to
make it harder to make mistakes.

* jk/common-main:
mingw: declare main()'s argv as const
common-main: call git_setup_gettext()
common-main: call restore_sigpipe_to_default()
common-main: call sanitize_stdfds()
common-main: call git_extract_argv0_path()
add an extra level of indirection to main()

1  2 
Makefile
compat/mingw.h
daemon.c
http-push.c
t/helper/test-date.c
t/helper/test-regex.c
t/helper/test-run-command.c
t/helper/test-submodule-config.c
upload-pack.c
diff --cc Makefile
Simple merge
diff --cc compat/mingw.h
index ef22cbb05d140a210bd348ea1234fc60cdf09da8,1ac9086a8275341a1a9a66338cc196d6782e7371..95e128fcfd45e98c091256265c7d9bda95ec733f
@@@ -535,10 -532,10 +535,10 @@@ extern CRITICAL_SECTION pinfo_cs
   * A replacement of main() that adds win32 specific initialization.
   */
  
 -void mingw_startup();
 -#define main(c,v) dummy_decl_mingw_main(); \
 +void mingw_startup(void);
 +#define main(c,v) dummy_decl_mingw_main(void); \
  static int mingw_main(c,v); \
- int main(int argc, char **argv) \
+ int main(int argc, const char **argv) \
  { \
        mingw_startup(); \
        return mingw_main(__argc, (void *)__argv); \
diff --cc daemon.c
Simple merge
diff --cc http-push.c
Simple merge
index d9ab3609094df80a1e3afc3d24d8fd158c96e496,0f3cfb1721b641b25267458edce93c9de2f923e2..506054bcd5dfbd76c8aec85382f35794514b9db9
@@@ -6,7 -5,7 +6,7 @@@ static const char *usage_msg = "\n
  "  test-date parse [date]...\n"
  "  test-date approxidate [date]...\n";
  
- static void show_relative_dates(char **argv, struct timeval *now)
 -static void show_dates(const char **argv, struct timeval *now)
++static void show_relative_dates(const char **argv, struct timeval *now)
  {
        struct strbuf buf = STRBUF_INIT;
  
        strbuf_release(&buf);
  }
  
- static void show_dates(char **argv, const char *format)
++static void show_dates(const char **argv, const char *format)
 +{
 +      struct date_mode mode;
 +
 +      parse_date_format(format, &mode);
 +      for (; *argv; argv++) {
-               char *arg = *argv;
++              char *arg;
 +              time_t t;
 +              int tz;
 +
 +              /*
 +               * Do not use our normal timestamp parsing here, as the point
 +               * is to test the formatting code in isolation.
 +               */
-               t = strtol(arg, &arg, 10);
++              t = strtol(*argv, &arg, 10);
 +              while (*arg == ' ')
 +                      arg++;
 +              tz = atoi(arg);
 +
 +              printf("%s -> %s\n", *argv, show_date(t, tz, &mode));
 +      }
 +}
 +
- static void parse_dates(char **argv, struct timeval *now)
+ static void parse_dates(const char **argv, struct timeval *now)
  {
        struct strbuf result = STRBUF_INIT;
  
index eff26f534fc21e3d77bc3d6cf76fce2b5a74e981,37b7f06e552ef51c852f54e70d66c434ca50b6b2..b5ea8a97c54e1737d91dec894c1cc02e1baf64e5
@@@ -33,43 -16,5 +33,43 @@@ static int test_regex_bug(void
        if (m[0].rm_so == 3) /* matches '\n' when it should not */
                die("regex bug confirmed: re-build git with NO_REGEX=1");
  
 -      exit(0);
 +      return 0;
 +}
 +
- int main(int argc, char **argv)
++int cmd_main(int argc, const char **argv)
 +{
 +      const char *pat;
 +      const char *str;
 +      int flags = 0;
 +      regex_t r;
 +      regmatch_t m[1];
 +
 +      if (argc == 2 && !strcmp(argv[1], "--bug"))
 +              return test_regex_bug();
 +      else if (argc < 3)
 +              usage("test-regex --bug\n"
 +                    "test-regex <pattern> <string> [<options>]");
 +
 +      argv++;
 +      pat = *argv++;
 +      str = *argv++;
 +      while (*argv) {
 +              struct reg_flag *rf;
 +              for (rf = reg_flags; rf->name; rf++)
 +                      if (!strcmp(*argv, rf->name)) {
 +                              flags |= rf->flag;
 +                              break;
 +                      }
 +              if (!rf->name)
 +                      die("do not recognize %s", *argv);
 +              argv++;
 +      }
 +      git_setup_gettext();
 +
 +      if (regcomp(&r, pat, flags))
 +              die("failed regcomp() for pattern '%s'", pat);
 +      if (regexec(&r, str, 1, m, 0))
 +              return 1;
 +
 +      return 0;
  }
Simple merge
Simple merge
diff --cc upload-pack.c
Simple merge