MCPcopy Create free account
hub / github.com/git/git / create_diagnostics_archive

Function create_diagnostics_archive

diagnose.c:181–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179}
180
181int 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);

Callers 2

cmd_bugreportFunction · 0.85
cmd_diagnoseFunction · 0.85

Calls 15

error_errnoFunction · 0.85
xopenFunction · 0.85
init_zip_archiverFunction · 0.85
strvec_pushlFunction · 0.85
strbuf_addstrFunction · 0.85
get_version_infoFunction · 0.85
strbuf_addfFunction · 0.85
get_disk_infoFunction · 0.85
write_or_dieFunction · 0.85
strvec_pushfFunction · 0.85
dir_file_statsFunction · 0.85
odb_for_each_alternateFunction · 0.85

Tested by

no test coverage detected