Merge branch 'jk/common-main'

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()
This commit is contained in:
Junio C Hamano
2016-07-19 13:22:19 -07:00
53 changed files with 124 additions and 151 deletions

View File

@ -6,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_relative_dates(const char **argv, struct timeval *now)
{
struct strbuf buf = STRBUF_INIT;
@ -18,13 +18,13 @@ static void show_relative_dates(char **argv, struct timeval *now)
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;
@ -32,7 +32,7 @@ static void show_dates(char **argv, const char *format)
* 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);
@ -41,7 +41,7 @@ static void show_dates(char **argv, const char *format)
}
}
static void parse_dates(char **argv, struct timeval *now)
static void parse_dates(const char **argv, struct timeval *now)
{
struct strbuf result = STRBUF_INIT;
@ -60,7 +60,7 @@ static void parse_dates(char **argv, struct timeval *now)
strbuf_release(&result);
}
static void parse_approxidate(char **argv, struct timeval *now)
static void parse_approxidate(const char **argv, struct timeval *now)
{
for (; *argv; argv++) {
time_t t;
@ -69,7 +69,7 @@ static void parse_approxidate(char **argv, struct timeval *now)
}
}
int main(int argc, char **argv)
int cmd_main(int argc, const char **argv)
{
struct timeval now;
const char *x;