shortlog: make trailer insertion a noop when appropriate
[alt-git.git] / builtin / diagnose.c
blob576e0e8e385c97961eda6292d7db14e55e4169cc
1 #include "builtin.h"
2 #include "parse-options.h"
3 #include "diagnose.h"
5 static const char * const diagnose_usage[] = {
6 N_("git diagnose [-o|--output-directory <path>] [-s|--suffix <format>] [--mode=<mode>]"),
7 NULL
8 };
10 int cmd_diagnose(int argc, const char **argv, const char *prefix)
12 struct strbuf zip_path = STRBUF_INIT;
13 time_t now = time(NULL);
14 struct tm tm;
15 enum diagnose_mode mode = DIAGNOSE_STATS;
16 char *option_output = NULL;
17 char *option_suffix = "%Y-%m-%d-%H%M";
18 char *prefixed_filename;
20 const struct option diagnose_options[] = {
21 OPT_STRING('o', "output-directory", &option_output, N_("path"),
22 N_("specify a destination for the diagnostics archive")),
23 OPT_STRING('s', "suffix", &option_suffix, N_("format"),
24 N_("specify a strftime format suffix for the filename")),
25 OPT_CALLBACK_F(0, "mode", &mode, "(stats|all)",
26 N_("specify the content of the diagnostic archive"),
27 PARSE_OPT_NONEG, option_parse_diagnose),
28 OPT_END()
31 argc = parse_options(argc, argv, prefix, diagnose_options,
32 diagnose_usage, 0);
34 /* Prepare the path to put the result */
35 prefixed_filename = prefix_filename(prefix,
36 option_output ? option_output : "");
37 strbuf_addstr(&zip_path, prefixed_filename);
38 strbuf_complete(&zip_path, '/');
40 strbuf_addstr(&zip_path, "git-diagnostics-");
41 strbuf_addftime(&zip_path, option_suffix, localtime_r(&now, &tm), 0, 0);
42 strbuf_addstr(&zip_path, ".zip");
44 switch (safe_create_leading_directories(zip_path.buf)) {
45 case SCLD_OK:
46 case SCLD_EXISTS:
47 break;
48 default:
49 die_errno(_("could not create leading directories for '%s'"),
50 zip_path.buf);
53 /* Prepare diagnostics */
54 if (create_diagnostics_archive(&zip_path, mode))
55 die_errno(_("unable to create diagnostics archive %s"),
56 zip_path.buf);
58 free(prefixed_filename);
59 strbuf_release(&zip_path);
60 return 0;