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