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},
* 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';
}
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;
/* 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_period *period)
+static struct string_list collect_stats(const struct cgit_period *period)
{
struct string_list authors;
struct rev_info rev;
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;
}
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;
}
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;
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";
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);
+ cgit_print_error_page(400, "Bad request",
+ "Statistics type disabled: %s", period->name);
return;
}
authors = collect_stats(period);
if (!top)
top = 10;
+ cgit_print_layout_start();
html("<div class='cgit-panel'>");
html("<b>stat options</b>");
html("<form method='get' action=''>");
}
html("</h2>");
print_authors(&authors, top, period);
+ cgit_print_layout_end();
}