X-Git-Url: https://git.cameronkatri.com/cgit.git/blobdiff_plain/ed5bd30ebe6921dd22948a3f33a314283f043606..143e65252c1c842774bc5a601d5faef97ca6c886:/ui-stats.c diff --git a/ui-stats.c b/ui-stats.c index 28b794f..74ce0f7 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -9,8 +9,6 @@ #define SZ_FMT "%zu" #endif -#define MONTHS 6 - struct authorstat { long total; struct string_list list; @@ -127,7 +125,7 @@ static char *pretty_year(struct tm *tm) return fmt("%d", tm->tm_year + 1900); } -struct cgit_period periods[] = { +static const struct cgit_period periods[] = { {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week}, {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month}, {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter}, @@ -138,7 +136,7 @@ struct cgit_period periods[] = { * and update the period pointer to the correcsponding struct. * If no matching code is found, return 0. */ -int cgit_find_stats_period(const char *expr, struct cgit_period **period) +int cgit_find_stats_period(const char *expr, const struct cgit_period **period) { int i; char code = '\0'; @@ -167,7 +165,7 @@ const char *cgit_find_stats_periodname(int idx) } static void add_commit(struct string_list *authors, struct commit *commit, - struct cgit_period *period) + const struct cgit_period *period) { struct commitinfo *info; struct string_list_item *author, *item; @@ -211,13 +209,12 @@ static int cmp_total_commits(const void *a1, const void *a2) /* Walk the commit DAG and collect number of commits per author per * timeperiod into a nested string_list collection. */ -static struct string_list collect_stats(struct cgit_context *ctx, - struct cgit_period *period) +static struct string_list collect_stats(const struct cgit_period *period) { struct string_list authors; struct rev_info rev; struct commit *commit; - const char *argv[] = {NULL, ctx->qry.head, NULL, NULL, NULL, NULL}; + const char *argv[] = {NULL, ctx.qry.head, NULL, NULL, NULL, NULL}; int argc = 3; time_t now; long i; @@ -231,9 +228,9 @@ static struct string_list collect_stats(struct cgit_context *ctx, period->dec(tm); strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm); argv[2] = xstrdup(fmt("--since=%s", tmp)); - if (ctx->qry.path) { + if (ctx.qry.path) { argv[3] = "--"; - argv[4] = ctx->qry.path; + argv[4] = ctx.qry.path; argc += 2; } init_revisions(&rev, NULL); @@ -247,8 +244,9 @@ static struct string_list collect_stats(struct cgit_context *ctx, memset(&authors, 0, sizeof(authors)); while ((commit = get_revision(&rev)) != NULL) { add_commit(&authors, commit, period); - free(commit->buffer); + free_commit_buffer(commit); free_commit_list(commit->parents); + commit->parents = NULL; } return authors; } @@ -258,7 +256,7 @@ static void print_combined_authorrow(struct string_list *authors, int from, const char *leftclass, const char *centerclass, const char *rightclass, - struct cgit_period *period) + const struct cgit_period *period) { struct string_list_item *author; struct authorstat *authorstat; @@ -297,7 +295,7 @@ static void print_combined_authorrow(struct string_list *authors, int from, } static void print_authors(struct string_list *authors, int top, - struct cgit_period *period) + const struct cgit_period *period) { struct string_list_item *author; struct authorstat *authorstat; @@ -362,42 +360,45 @@ static void print_authors(struct string_list *authors, int top, * for each author is another string_list which is used to calculate the * number of commits per time-interval. */ -void cgit_show_stats(struct cgit_context *ctx) +void cgit_show_stats(void) { struct string_list authors; - struct cgit_period *period; + const struct cgit_period *period; int top, i; const char *code = "w"; - if (ctx->qry.period) - code = ctx->qry.period; + if (ctx.qry.period) + code = ctx.qry.period; i = cgit_find_stats_period(code, &period); if (!i) { - cgit_print_error("Unknown statistics type: %c", code[0]); + cgit_print_error_page(404, "Not found", + "Unknown statistics type: %c", code[0]); return; } - if (i > ctx->repo->max_stats) { - cgit_print_error("Statistics type disabled: %s", period->name); + if (i > ctx.repo->max_stats) { + cgit_print_error_page(400, "Bad request", + "Statistics type disabled: %s", period->name); return; } - authors = collect_stats(ctx, period); + authors = collect_stats(period); qsort(authors.items, authors.nr, sizeof(struct string_list_item), cmp_total_commits); - top = ctx->qry.ofs; + top = ctx.qry.ofs; if (!top) top = 10; + cgit_print_layout_start(); html("