From: Junio C Hamano Date: Fri, 9 Sep 2016 04:35:50 +0000 (-0700) Subject: Merge branch 'jk/common-main' into maint X-Git-Tag: v2.10.1~68 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=faacc8efe503a470c0c549c7949824728d7f1461;p=thirdparty%2Fgit.git Merge branch 'jk/common-main' into maint 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() --- faacc8efe503a470c0c549c7949824728d7f1461 diff --cc compat/mingw.h index ef22cbb05d,1ac9086a82..95e128fcfd --- a/compat/mingw.h +++ b/compat/mingw.h @@@ -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 t/helper/test-date.c index d9ab360909,0f3cfb1721..506054bcd5 --- a/t/helper/test-date.c +++ b/t/helper/test-date.c @@@ -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; @@@ -18,30 -17,7 +18,30 @@@ 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; diff --cc t/helper/test-regex.c index eff26f534f,37b7f06e55..b5ea8a97c5 --- a/t/helper/test-regex.c +++ b/t/helper/test-regex.c @@@ -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 []"); + + 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; }