| 179 | } |
| 180 | |
| 181 | int create_diagnostics_archive(struct repository *r, |
| 182 | struct strbuf *zip_path, |
| 183 | enum diagnose_mode mode) |
| 184 | { |
| 185 | struct strvec archiver_args = STRVEC_INIT; |
| 186 | char **argv_copy = NULL; |
| 187 | int stdout_fd = -1, archiver_fd = -1; |
| 188 | struct strbuf buf = STRBUF_INIT; |
| 189 | int res; |
| 190 | struct archive_dir archive_dirs[] = { |
| 191 | { ".git", 0 }, |
| 192 | { ".git/hooks", 0 }, |
| 193 | { ".git/info", 0 }, |
| 194 | { ".git/logs", 1 }, |
| 195 | { ".git/objects/info", 0 } |
| 196 | }; |
| 197 | |
| 198 | if (mode == DIAGNOSE_NONE) { |
| 199 | res = 0; |
| 200 | goto diagnose_cleanup; |
| 201 | } |
| 202 | |
| 203 | stdout_fd = dup(STDOUT_FILENO); |
| 204 | if (stdout_fd < 0) { |
| 205 | res = error_errno(_("could not duplicate stdout")); |
| 206 | goto diagnose_cleanup; |
| 207 | } |
| 208 | |
| 209 | archiver_fd = xopen(zip_path->buf, O_CREAT | O_WRONLY | O_TRUNC, 0666); |
| 210 | if (dup2(archiver_fd, STDOUT_FILENO) < 0) { |
| 211 | res = error_errno(_("could not redirect output")); |
| 212 | goto diagnose_cleanup; |
| 213 | } |
| 214 | |
| 215 | init_zip_archiver(); |
| 216 | strvec_pushl(&archiver_args, "git-diagnose", "--format=zip", NULL); |
| 217 | |
| 218 | strbuf_reset(&buf); |
| 219 | strbuf_addstr(&buf, "Collecting diagnostic info\n\n"); |
| 220 | get_version_info(&buf, 1); |
| 221 | |
| 222 | strbuf_addf(&buf, "Repository root: %s\n", r->worktree); |
| 223 | get_disk_info(&buf); |
| 224 | write_or_die(stdout_fd, buf.buf, buf.len); |
| 225 | strvec_pushf(&archiver_args, |
| 226 | "--add-virtual-file=diagnostics.log:%.*s", |
| 227 | (int)buf.len, buf.buf); |
| 228 | |
| 229 | strbuf_reset(&buf); |
| 230 | strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:"); |
| 231 | dir_file_stats(r->objects->sources, &buf); |
| 232 | odb_for_each_alternate(r->objects, dir_file_stats, &buf); |
| 233 | strvec_push(&archiver_args, buf.buf); |
| 234 | |
| 235 | strbuf_reset(&buf); |
| 236 | strbuf_addstr(&buf, "--add-virtual-file=objects-local.txt:"); |
| 237 | loose_objs_stats(&buf, ".git/objects"); |
| 238 | strvec_push(&archiver_args, buf.buf); |
no test coverage detected