|
13 | 13 | #include "packfile.h" |
14 | 14 | #include "parse-options.h" |
15 | 15 | #include "write-or-die.h" |
| 16 | +#include "config.h" |
16 | 17 |
|
17 | 18 | struct archive_dir { |
18 | 19 | const char *path; |
@@ -72,6 +73,39 @@ static int dir_file_stats(struct object_directory *object_dir, void *data) |
72 | 73 | return 0; |
73 | 74 | } |
74 | 75 |
|
| 76 | +static void dir_stats(struct strbuf *buf, const char *path) |
| 77 | +{ |
| 78 | + DIR *dir = opendir(path); |
| 79 | + struct dirent *e; |
| 80 | + struct stat e_stat; |
| 81 | + struct strbuf file_path = STRBUF_INIT; |
| 82 | + size_t base_path_len; |
| 83 | + |
| 84 | + if (!dir) |
| 85 | + return; |
| 86 | + |
| 87 | + strbuf_addstr(buf, "Contents of "); |
| 88 | + strbuf_add_absolute_path(buf, path); |
| 89 | + strbuf_addstr(buf, ":\n"); |
| 90 | + |
| 91 | + strbuf_add_absolute_path(&file_path, path); |
| 92 | + strbuf_addch(&file_path, '/'); |
| 93 | + base_path_len = file_path.len; |
| 94 | + |
| 95 | + while ((e = readdir(dir)) != NULL) |
| 96 | + if (!is_dot_or_dotdot(e->d_name) && e->d_type == DT_REG) { |
| 97 | + strbuf_setlen(&file_path, base_path_len); |
| 98 | + strbuf_addstr(&file_path, e->d_name); |
| 99 | + if (!stat(file_path.buf, &e_stat)) |
| 100 | + strbuf_addf(buf, "%-70s %16"PRIuMAX"\n", |
| 101 | + e->d_name, |
| 102 | + (uintmax_t)e_stat.st_size); |
| 103 | + } |
| 104 | + |
| 105 | + strbuf_release(&file_path); |
| 106 | + closedir(dir); |
| 107 | +} |
| 108 | + |
75 | 109 | static int count_files(struct strbuf *path) |
76 | 110 | { |
77 | 111 | DIR *dir = opendir(path->buf); |
@@ -184,7 +218,8 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode) |
184 | 218 | struct strvec archiver_args = STRVEC_INIT; |
185 | 219 | char **argv_copy = NULL; |
186 | 220 | int stdout_fd = -1, archiver_fd = -1; |
187 | | - struct strbuf buf = STRBUF_INIT; |
| 221 | + char *cache_server_url = NULL, *shared_cache = NULL; |
| 222 | + struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT; |
188 | 223 | int res; |
189 | 224 | struct archive_dir archive_dirs[] = { |
190 | 225 | { ".git", 0 }, |
@@ -219,6 +254,13 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode) |
219 | 254 | get_version_info(&buf, 1); |
220 | 255 |
|
221 | 256 | strbuf_addf(&buf, "Repository root: %s\n", the_repository->worktree); |
| 257 | + |
| 258 | + git_config_get_string("gvfs.cache-server", &cache_server_url); |
| 259 | + git_config_get_string("gvfs.sharedCache", &shared_cache); |
| 260 | + strbuf_addf(&buf, "Cache Server: %s\nLocal Cache: %s\n\n", |
| 261 | + cache_server_url ? cache_server_url : "None", |
| 262 | + shared_cache ? shared_cache : "None"); |
| 263 | + |
222 | 264 | get_disk_info(&buf); |
223 | 265 | write_or_die(stdout_fd, buf.buf, buf.len); |
224 | 266 | strvec_pushf(&archiver_args, |
@@ -249,6 +291,52 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode) |
249 | 291 | } |
250 | 292 | } |
251 | 293 |
|
| 294 | + if (shared_cache) { |
| 295 | + size_t path_len; |
| 296 | + |
| 297 | + strbuf_reset(&buf); |
| 298 | + strbuf_addf(&path, "%s/pack", shared_cache); |
| 299 | + strbuf_reset(&buf); |
| 300 | + strbuf_addstr(&buf, "--add-virtual-file=packs-cached.txt:"); |
| 301 | + dir_stats(&buf, path.buf); |
| 302 | + strvec_push(&archiver_args, buf.buf); |
| 303 | + |
| 304 | + strbuf_reset(&buf); |
| 305 | + strbuf_addstr(&buf, "--add-virtual-file=objects-cached.txt:"); |
| 306 | + loose_objs_stats(&buf, shared_cache); |
| 307 | + strvec_push(&archiver_args, buf.buf); |
| 308 | + |
| 309 | + strbuf_reset(&path); |
| 310 | + strbuf_addf(&path, "%s/info", shared_cache); |
| 311 | + path_len = path.len; |
| 312 | + |
| 313 | + if (is_directory(path.buf)) { |
| 314 | + DIR *dir = opendir(path.buf); |
| 315 | + struct dirent *e; |
| 316 | + |
| 317 | + while ((e = readdir(dir))) { |
| 318 | + if (!strcmp(".", e->d_name) || !strcmp("..", e->d_name)) |
| 319 | + continue; |
| 320 | + if (e->d_type == DT_DIR) |
| 321 | + continue; |
| 322 | + |
| 323 | + strbuf_reset(&buf); |
| 324 | + strbuf_addf(&buf, "--add-virtual-file=info/%s:", e->d_name); |
| 325 | + |
| 326 | + strbuf_setlen(&path, path_len); |
| 327 | + strbuf_addch(&path, '/'); |
| 328 | + strbuf_addstr(&path, e->d_name); |
| 329 | + |
| 330 | + if (strbuf_read_file(&buf, path.buf, 0) < 0) { |
| 331 | + res = error_errno(_("could not read '%s'"), path.buf); |
| 332 | + goto diagnose_cleanup; |
| 333 | + } |
| 334 | + strvec_push(&archiver_args, buf.buf); |
| 335 | + } |
| 336 | + closedir(dir); |
| 337 | + } |
| 338 | + } |
| 339 | + |
252 | 340 | strvec_pushl(&archiver_args, "--prefix=", |
253 | 341 | oid_to_hex(the_hash_algo->empty_tree), "--", NULL); |
254 | 342 |
|
@@ -276,6 +364,8 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode) |
276 | 364 | free(argv_copy); |
277 | 365 | strvec_clear(&archiver_args); |
278 | 366 | strbuf_release(&buf); |
| 367 | + free(cache_server_url); |
| 368 | + free(shared_cache); |
279 | 369 |
|
280 | 370 | return res; |
281 | 371 | } |
0 commit comments