From 03d5c688d7f0ed6265dca96fe0f0edf4e8103804 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 13:23:54 -0700 Subject: Print every stats row with one function The cells of the Others row lose the empty class attribute they carried. --- source/ui-stats.c | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'source/ui-stats.c') diff --git a/source/ui-stats.c b/source/ui-stats.c index 6b05c80..6da24ad 100644 --- a/source/ui-stats.c +++ b/source/ui-stats.c @@ -263,9 +263,9 @@ static struct string_list build_period_labels(const struct cgit_period *period) * The run of authors to sum is given as a start and a count rather than as * two indices, so that an empty author list cannot describe a run that wraps. */ -static void print_summary_row(struct string_list *authors, size_t from, size_t count, - const char *label_format, const char *leftclass, const char *centerclass, - const char *rightclass, const struct string_list *labels) +static void print_row(struct string_list *authors, size_t from, size_t count, + const char *name, const char *nameclass, const char *cellclass, + const struct string_list *labels) { struct authorstat *stats; struct string_list_item *bucket; @@ -273,7 +273,9 @@ static void print_summary_row(struct string_list *authors, size_t from, size_t c long total, subtotal; total = 0; - htmlf("%s", leftclass, cgit_fmt(label_format, (long)count)); + htmlf("", nameclass); + html_txt(name); + html(""); for (column = 0; column < labels->nr; column++) { const char *label = labels->items[column].string; @@ -284,18 +286,18 @@ static void print_summary_row(struct string_list *authors, size_t from, size_t c if (bucket) subtotal += (uintptr_t)bucket->util; } - htmlf("%ld", centerclass, subtotal); + if (cellclass) + htmlf("%ld", cellclass, subtotal); + else + htmlf("%ld", subtotal); total += subtotal; } - htmlf("%ld\n", rightclass, total); + htmlf("%ld\n", total); } static void print_authors(struct string_list *authors, int max_rows, const struct string_list *labels) { - struct string_list_item *author, *bucket; - struct authorstat *stats; size_t i, column, rows; - long total; html("\n"); for (column = 0; column < labels->nr; column++) @@ -305,32 +307,14 @@ static void print_authors(struct string_list *authors, int max_rows, const struc // The row count arrives through ofs, which carries -1 for "all". rows = (max_rows <= 0 || (size_t)max_rows > authors->nr) ? authors->nr : (size_t)max_rows; - for (i = 0; i < rows; i++) { - author = &authors->items[i]; - html(""); - stats = author->util; - total = 0; - for (column = 0; column < labels->nr; column++) { - const char *label = labels->items[column].string; - - bucket = string_list_lookup(&stats->periods, label); - if (!bucket) - html(""); - else { - htmlf("", (uintmax_t)(uintptr_t)bucket->util); - total += (uintptr_t)bucket->util; - } - } - htmlf("\n", total); - } + for (i = 0; i < rows; i++) + print_row(authors, i, 1, authors->items[i].string, "left", NULL, labels); if (rows < authors->nr) - print_summary_row(authors, rows, authors->nr - rows, "Others (%ld)", "left", "", "sum", - labels); + print_row(authors, rows, authors->nr - rows, + cgit_fmt("Others (%ld)", (long)(authors->nr - rows)), "left", NULL, labels); - print_summary_row(authors, 0, authors->nr, "Total", "total", "sum", "sum", labels); + print_row(authors, 0, authors->nr, "Total", "total", "sum", labels); html("
Author
"); - html_txt(author->string); - html("0%ju%ld
\n"); } -- cgit 2.11.1