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