Skip to content

Commit d2bec2f

Browse files
committed
scalar diagnose: include shared cache info
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 8ee6216 commit d2bec2f

1 file changed

Lines changed: 69 additions & 1 deletion

File tree

diagnose.c

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,39 @@ static unsigned char get_dtype(struct dirent *e, struct strbuf *path)
103103
return dtype;
104104
}
105105

106+
static void dir_stats(struct strbuf *buf, const char *path)
107+
{
108+
DIR *dir = opendir(path);
109+
struct dirent *e;
110+
struct stat e_stat;
111+
struct strbuf file_path = STRBUF_INIT;
112+
size_t base_path_len;
113+
114+
if (!dir)
115+
return;
116+
117+
strbuf_addstr(buf, "Contents of ");
118+
strbuf_add_absolute_path(buf, path);
119+
strbuf_addstr(buf, ":\n");
120+
121+
strbuf_add_absolute_path(&file_path, path);
122+
strbuf_addch(&file_path, '/');
123+
base_path_len = file_path.len;
124+
125+
while ((e = readdir(dir)) != NULL)
126+
if (!is_dot_or_dotdot(e->d_name) && e->d_type == DT_REG) {
127+
strbuf_setlen(&file_path, base_path_len);
128+
strbuf_addstr(&file_path, e->d_name);
129+
if (!stat(file_path.buf, &e_stat))
130+
strbuf_addf(buf, "%-70s %16"PRIuMAX"\n",
131+
e->d_name,
132+
(uintmax_t)e_stat.st_size);
133+
}
134+
135+
strbuf_release(&file_path);
136+
closedir(dir);
137+
}
138+
106139
static int count_files(struct strbuf *path)
107140
{
108141
DIR *dir = opendir(path->buf);
@@ -216,7 +249,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
216249
char **argv_copy = NULL;
217250
int stdout_fd = -1, archiver_fd = -1;
218251
char *cache_server_url = NULL, *shared_cache = NULL;
219-
struct strbuf buf = STRBUF_INIT;
252+
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
220253
int res, i;
221254
struct archive_dir archive_dirs[] = {
222255
{ ".git", 0 },
@@ -288,6 +321,41 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
288321
}
289322
}
290323

324+
if (shared_cache) {
325+
strbuf_reset(&buf);
326+
strbuf_addf(&path, "%s/pack", shared_cache);
327+
strbuf_reset(&buf);
328+
strbuf_addstr(&buf, "--add-virtual-file=packs-cached.txt:");
329+
dir_stats(&buf, path.buf);
330+
strvec_push(&archiver_args, buf.buf);
331+
332+
strbuf_reset(&buf);
333+
strbuf_addstr(&buf, "--add-virtual-file=objects-cached.txt:");
334+
loose_objs_stats(&buf, shared_cache);
335+
strvec_push(&archiver_args, buf.buf);
336+
337+
strbuf_reset(&path);
338+
strbuf_addf(&path, "%s/info", shared_cache);
339+
if (is_directory(path.buf)) {
340+
DIR *dir = opendir(path.buf);
341+
struct dirent *e;
342+
343+
while ((e = readdir(dir))) {
344+
if (!strcmp(".", e->d_name) || !strcmp("..", e->d_name))
345+
continue;
346+
347+
strbuf_reset(&buf);
348+
strbuf_addf(&buf, "--add-virtual-file=info/%s:", e->d_name);
349+
if (strbuf_read_file(&buf, path.buf, 0) < 0) {
350+
res = error_errno(_("could not read '%s'"), path.buf);
351+
goto diagnose_cleanup;
352+
}
353+
strvec_push(&archiver_args, buf.buf);
354+
}
355+
closedir(dir);
356+
}
357+
}
358+
291359
strvec_pushl(&archiver_args, "--prefix=",
292360
oid_to_hex(the_hash_algo->empty_tree), "--", NULL);
293361

0 commit comments

Comments
 (0)