| 91 | } |
| 92 | |
| 93 | int cmd_bugreport(int argc, |
| 94 | const char **argv, |
| 95 | const char *prefix, |
| 96 | struct repository *repo UNUSED) |
| 97 | { |
| 98 | struct strbuf buffer = STRBUF_INIT; |
| 99 | struct strbuf report_path = STRBUF_INIT; |
| 100 | int report = -1; |
| 101 | time_t now = time(NULL); |
| 102 | struct tm tm; |
| 103 | enum diagnose_mode diagnose = DIAGNOSE_NONE; |
| 104 | char *option_output = NULL; |
| 105 | const char *option_suffix = "%Y-%m-%d-%H%M"; |
| 106 | const char *user_relative_path = NULL; |
| 107 | char *prefixed_filename; |
| 108 | size_t output_path_len; |
| 109 | int ret; |
| 110 | |
| 111 | const struct option bugreport_options[] = { |
| 112 | OPT_CALLBACK_F(0, "diagnose", &diagnose, N_("mode"), |
| 113 | N_("create an additional zip archive of detailed diagnostics (default 'stats')"), |
| 114 | PARSE_OPT_OPTARG, option_parse_diagnose), |
| 115 | OPT_STRING('o', "output-directory", &option_output, N_("path"), |
| 116 | N_("specify a destination for the bugreport file(s)")), |
| 117 | OPT_STRING('s', "suffix", &option_suffix, N_("format"), |
| 118 | N_("specify a strftime format suffix for the filename(s)")), |
| 119 | OPT_END() |
| 120 | }; |
| 121 | |
| 122 | argc = parse_options(argc, argv, prefix, bugreport_options, |
| 123 | bugreport_usage, 0); |
| 124 | |
| 125 | if (argc) { |
| 126 | error(_("unknown argument `%s'"), argv[0]); |
| 127 | usage(bugreport_usage[0]); |
| 128 | } |
| 129 | |
| 130 | /* Prepare the path to put the result */ |
| 131 | prefixed_filename = prefix_filename(prefix, |
| 132 | option_output ? option_output : ""); |
| 133 | strbuf_addstr(&report_path, prefixed_filename); |
| 134 | strbuf_complete(&report_path, '/'); |
| 135 | output_path_len = report_path.len; |
| 136 | |
| 137 | strbuf_addstr(&report_path, "git-bugreport"); |
| 138 | if (option_suffix) { |
| 139 | strbuf_addch(&report_path, '-'); |
| 140 | strbuf_addftime(&report_path, option_suffix, localtime_r(&now, &tm), 0, 0); |
| 141 | } |
| 142 | strbuf_addstr(&report_path, ".txt"); |
| 143 | |
| 144 | switch (safe_create_leading_directories(the_repository, report_path.buf)) { |
| 145 | case SCLD_OK: |
| 146 | case SCLD_EXISTS: |
| 147 | break; |
| 148 | default: |
| 149 | die(_("could not create leading directories for '%s'"), |
| 150 | report_path.buf); |
nothing calls this directly
no test coverage detected