Skip to content

Commit

Permalink
survey: progress on pretty printing overview
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
  • Loading branch information
jeffhostetler committed May 22, 2024
1 parent 27776d1 commit 1f0eeac
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions builtin/survey.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,44 @@ static void fmt_txt_line(struct strbuf *buf, int indent, const char *txt)
strbuf_addch(buf, '\n');
}

static void fmt_ovr_hdr(struct strbuf *buf,
int indent,
const char *label,
const char *count_label,
const char *size_label,
const char *disk_size_label)
{
int column0 = 20;

if (indent)
strbuf_addchars(buf, ' ', indent);

strbuf_addf(buf, "%-*s : %14s : %14s : %14s",
column0 - indent, label,
count_label, size_label, disk_size_label);

strbuf_addch(buf, '\n');
}

static void fmt_ovr_row(struct strbuf *buf,
int indent,
const char *label,
uint64_t count,
uint64_t size,
uint64_t disk_size)
{
int column0 = 20;

if (indent)
strbuf_addchars(buf, ' ', indent);

strbuf_addf(buf, "%-*s : %14"PRIu64" : %14"PRIu64" : %14"PRIu64,
column0 - indent, label,
count, size, disk_size);

strbuf_addch(buf, '\n');
}

static void fmt_ref_row(struct strbuf *buf,
int indent,
const char *label,
Expand Down Expand Up @@ -1410,6 +1448,49 @@ static void pretty_print_survey_hdr(void)
strbuf_release(&buf);
}

static void pretty_print_overview(int indent)
{
struct survey_stats_refs *prs = &survey_stats.refs;

Check failure on line 1453 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

builtin/survey.c:1453:35: unused variable 'prs' [-Werror=unused-variable]

Check failure on line 1453 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

builtin/survey.c:1453:35: unused variable 'prs' [-Werror=unused-variable]

Check failure on line 1453 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

builtin/survey.c:1453:28: unused variable 'prs' [-Werror,-Wunused-variable]

Check failure on line 1453 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

builtin/survey.c:1453:28: unused variable ‘prs’ [-Werror=unused-variable]

Check failure on line 1453 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

builtin/survey.c:1453:35: unused variable ‘prs’ [-Werror=unused-variable]

Check failure on line 1453 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

builtin/survey.c:1453:35: unused variable ‘prs’ [-Werror=unused-variable]

Check failure on line 1453 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu-latest)

builtin/survey.c:1453:28: unused variable 'prs' [-Werror,-Wunused-variable]

Check failure on line 1453 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu-latest)

builtin/survey.c:1453:35: unused variable ‘prs’ [-Werror=unused-variable]

Check failure on line 1453 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu-latest)

builtin/survey.c:1453:28: unused variable 'prs' [-Werror,-Wunused-variable]

Check failure on line 1453 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

builtin/survey.c:1453:28: unused variable ‘prs’ [-Werror=unused-variable]

Check failure on line 1453 in builtin/survey.c

View workflow job for this annotation

GitHub Actions / win build

builtin/survey.c:1453:35: unused variable 'prs' [-Werror=unused-variable]
struct survey_stats_commits *psc = &survey_stats.commits;
struct survey_stats_trees *pst = &survey_stats.trees;
struct survey_stats_blobs *psb = &survey_stats.blobs;
struct strbuf buf = STRBUF_INIT;
int indent1 = indent + 4;
int indent2 = indent + 8;
int k;

const char *intro[] = {
"",
"OVERVIEW",
"--------",
"",
NULL
};

k = 0;
while (intro[k])
fmt_txt_line(&buf, indent, intro[k++]);

fmt_txt_line(&buf, indent, "Object Overview by Type");
fmt_ovr_hdr(&buf, indent1, "", "Count", "Size", "Disk Size");

fmt_ovr_row(&buf, indent2, "Commits", psc->base.cnt_seen, psc->base.sum_size, psc->base.sum_disk_size);
fmt_ovr_row(&buf, indent2, "Trees", pst->base.cnt_seen, pst->base.sum_size, pst->base.sum_disk_size);
fmt_ovr_row(&buf, indent2, "Blobs", psb->base.cnt_seen, psb->base.sum_size, psb->base.sum_disk_size);

fmt_ovr_row(&buf, indent1, "Total",
psc->base.cnt_seen + pst->base.cnt_seen + psb->base.cnt_seen,
psc->base.sum_size + pst->base.sum_size + psb->base.sum_size,
psc->base.sum_disk_size + pst->base.sum_disk_size + psb->base.sum_disk_size);

/*
* NEEDSWORK: Do we want anything else in the overview?
*/

fwrite(buf.buf, 1, buf.len, stdout);
strbuf_release(&buf);
}

/*
* Pretty print information on the set of REFS that we examined.
*
Expand Down Expand Up @@ -1595,6 +1676,7 @@ static void pretty_print_blobs(int indent)
static void survey_print_results_pretty(void)
{
pretty_print_survey_hdr();
pretty_print_overview(0);
pretty_print_refs(0);
pretty_print_commits(0);
pretty_print_trees(0);
Expand Down

0 comments on commit 1f0eeac

Please sign in to comment.