Skip to content

Commit

Permalink
scalar diagnose: include shared cache info
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Nov 3, 2023
1 parent a3c53e9 commit b2a647f
Showing 1 changed file with 80 additions and 1 deletion.
81 changes: 80 additions & 1 deletion diagnose.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,39 @@ static unsigned char get_dtype(struct dirent *e, struct strbuf *path)
return dtype;
}

static void dir_stats(struct strbuf *buf, const char *path)
{
DIR *dir = opendir(path);
struct dirent *e;
struct stat e_stat;
struct strbuf file_path = STRBUF_INIT;
size_t base_path_len;

if (!dir)
return;

strbuf_addstr(buf, "Contents of ");
strbuf_add_absolute_path(buf, path);
strbuf_addstr(buf, ":\n");

strbuf_add_absolute_path(&file_path, path);
strbuf_addch(&file_path, '/');
base_path_len = file_path.len;

while ((e = readdir(dir)) != NULL)
if (!is_dot_or_dotdot(e->d_name) && e->d_type == DT_REG) {
strbuf_setlen(&file_path, base_path_len);
strbuf_addstr(&file_path, e->d_name);
if (!stat(file_path.buf, &e_stat))
strbuf_addf(buf, "%-70s %16"PRIuMAX"\n",
e->d_name,
(uintmax_t)e_stat.st_size);
}

strbuf_release(&file_path);
closedir(dir);
}

static int count_files(struct strbuf *path)
{
DIR *dir = opendir(path->buf);
Expand Down Expand Up @@ -221,7 +254,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
char **argv_copy = NULL;
int stdout_fd = -1, archiver_fd = -1;
char *cache_server_url = NULL, *shared_cache = NULL;
struct strbuf buf = STRBUF_INIT;
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
int res, i;
struct archive_dir archive_dirs[] = {
{ ".git", 0 },
Expand Down Expand Up @@ -293,6 +326,52 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
}
}

if (shared_cache) {
size_t path_len;

strbuf_reset(&buf);
strbuf_addf(&path, "%s/pack", shared_cache);
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-cached.txt:");
dir_stats(&buf, path.buf);
strvec_push(&archiver_args, buf.buf);

strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=objects-cached.txt:");
loose_objs_stats(&buf, shared_cache);
strvec_push(&archiver_args, buf.buf);

strbuf_reset(&path);
strbuf_addf(&path, "%s/info", shared_cache);
path_len = path.len;

if (is_directory(path.buf)) {
DIR *dir = opendir(path.buf);
struct dirent *e;

while ((e = readdir(dir))) {
if (!strcmp(".", e->d_name) || !strcmp("..", e->d_name))
continue;
if (e->d_type == DT_DIR)
continue;

strbuf_reset(&buf);
strbuf_addf(&buf, "--add-virtual-file=info/%s:", e->d_name);

strbuf_setlen(&path, path_len);
strbuf_addch(&path, '/');
strbuf_addstr(&path, e->d_name);

if (strbuf_read_file(&buf, path.buf, 0) < 0) {
res = error_errno(_("could not read '%s'"), path.buf);
goto diagnose_cleanup;
}
strvec_push(&archiver_args, buf.buf);
}
closedir(dir);
}
}

strvec_pushl(&archiver_args, "--prefix=",
oid_to_hex(the_hash_algo->empty_tree), "--", NULL);

Expand Down

0 comments on commit b2a647f

Please sign in to comment.