#include "html.h"
#include "ui-shared.h"
-#ifdef NO_C99_FORMAT
-#define SZ_FMT "%u"
-#else
-#define SZ_FMT "%zu"
-#endif
-
struct authorstat {
long total;
struct string_list list;
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;
char *tmp;
struct tm *date;
time_t t;
+ uintptr_t *counter;
info = cgit_parse_commit(commit);
tmp = xstrdup(info->author);
period->trunc(date);
tmp = xstrdup(period->pretty(date));
item = string_list_insert(items, tmp);
- if (item->util)
+ counter = (uintptr_t *)&item->util;
+ if (*counter)
free(tmp);
- item->util++;
+ (*counter)++;
+
authorstat->total++;
cgit_free_commitinfo(info);
}
/* 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(commit);
+ free_commit_buffer(the_repository->parsed_objects, 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;
items = &authorstat->list;
date = string_list_lookup(items, tmp);
if (date)
- subtotal += (size_t)date->util;
+ subtotal += (uintptr_t)date->util;
}
htmlf("<td class='%s'>%ld</td>", centerclass, subtotal);
total += subtotal;
}
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;
if (!date)
html("<td>0</td>");
else {
- htmlf("<td>"SZ_FMT"</td>", (size_t)date->util);
- total += (size_t)date->util;
+ htmlf("<td>%lu</td>", (uintptr_t)date->util);
+ total += (uintptr_t)date->util;
}
}
htmlf("<td class='sum'>%ld</td></tr>", total);
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("<form method='get'>");
cgit_add_hidden_formfields(1, 0, "stats");
html("<table><tr><td colspan='2'/></tr>");
if (ctx.repo->max_stats > 1) {
}
html("</h2>");
print_authors(&authors, top, period);
+ cgit_print_layout_end();
}