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