Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Move the stats period struct into ui-stats.c
Diffstat (limited to '')
| -rw-r--r-- | source/ui-stats.c | 30 |
1 file changed, 24 insertions, 6 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); } |
