Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Move the stats period struct into ui-stats.c
Diffstat (limited to 'source')
-rw-r--r--source/ui-stats.c30
-rw-r--r--source/ui-stats.h25
2 files changed, 27 insertions, 28 deletions
diff --git a/source/ui-stats.c b/source/ui-stats.c
index 6da24ad..24a6e53 100644
--- a/source/ui-stats.c
+++ b/source/ui-stats.c
@@ -17,6 +17,24 @@
#define DEFAULT_AUTHOR_ROWS 10
+// How many periods the page shows side by side.
+#define PERIOD_COLUMNS 4
+
+struct cgit_period {
+ const char code;
+ const char *name;
+
+ // Move a tm back to the first day of the period it falls in.
+ void (*trunc)(struct tm *tm);
+
+ // Step a truncated tm n whole periods, back when n is negative.
+ void (*step)(struct tm *tm, int n);
+
+ // Label the period a tm falls in. The buffer is reused, so a caller
+ // that keeps a label copies it.
+ char *(*pretty)(struct tm *tm);
+};
+
// One author's share of the window. periods is keyed by the label of a period,
// with the commit count stored in the util field itself rather than behind
// another allocation.
@@ -116,10 +134,10 @@ static char *pretty_year(struct tm *tm)
// The order runs from the finest window to the coarsest, because a repository
// caps the page by storing an index into this table as its max-stats.
static const struct cgit_period periods[] = {
- {'w', "week", 4, trunc_week, step_week, pretty_week},
- {'m', "month", 4, trunc_month, step_month, pretty_month},
- {'q', "quarter", 4, trunc_quarter, step_quarter, pretty_quarter},
- {'y', "year", 4, trunc_year, step_year, pretty_year},
+ {'w', "week", trunc_week, step_week, pretty_week},
+ {'m', "month", trunc_month, step_month, pretty_month},
+ {'q', "quarter", trunc_quarter, step_quarter, pretty_quarter},
+ {'y', "year", trunc_year, step_year, pretty_year},
};
static void window_start(const struct cgit_period *period, struct tm *tm)
@@ -137,7 +155,7 @@ static void window_start(const struct cgit_period *period, struct tm *tm)
tm->tm_hour = 0;
tm->tm_min = 0;
tm->tm_sec = 0;
- for (i = 1; i < period->count; i++)
+ for (i = 1; i < PERIOD_COLUMNS; i++)
period->step(tm, -1);
}
@@ -252,7 +270,7 @@ static struct string_list build_period_labels(const struct cgit_period *period)
int i;
window_start(period, &tm);
- for (i = 0; i < period->count; i++) {
+ for (i = 0; i < PERIOD_COLUMNS; i++) {
string_list_append(&labels, period->pretty(&tm));
period->step(&tm, 1);
}
diff --git a/source/ui-stats.h b/source/ui-stats.h
index 1cd0b9d..3479732 100644
--- a/source/ui-stats.h
+++ b/source/ui-stats.h
@@ -1,32 +1,13 @@
/*
* The statistics page, which counts commits per author over a window of
- * recent weeks, months, quarters or years. The windows are described here
- * rather than inside the page, because cgit.c resolves a repository's
- * max-stats setting against the same set.
+ * recent weeks, months, quarters or years, and the period lookups that cgit.c
+ * resolves a max-stats setting with.
*/
#ifndef CGIT_UI_STATS_H
#define CGIT_UI_STATS_H
-#include "cgit.h"
-
-struct cgit_period {
- const char code;
- const char *name;
-
- // How many periods a page shows side by side.
- int count;
-
- // Move a tm back to the first day of the period it falls in.
- void (*trunc)(struct tm *tm);
-
- // Step a truncated tm n whole periods, back when n is negative.
- void (*step)(struct tm *tm, int n);
-
- // Label the period a tm falls in. The buffer is reused, so a caller
- // that keeps a label copies it.
- char *(*pretty)(struct tm *tm);
-};
+struct cgit_period;
/*
* Look a period up by its one letter code or by its full name, storing the