summaryrefslogtreecommitdiffabout
path: root/ui-stats.c
Side-by-side diff
Diffstat (limited to 'ui-stats.c') (more/less context) (show whitespace changes)
-rw-r--r--ui-stats.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/ui-stats.c b/ui-stats.c
index bdaf9cc..50c2540 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -154,60 +154,60 @@ int cgit_find_stats_period(const char *expr, struct cgit_period **period)
return 0;
}
const char *cgit_find_stats_periodname(int idx)
{
if (idx > 0 && idx < 4)
return periods[idx - 1].name;
else
return "";
}
static void add_commit(struct string_list *authors, struct commit *commit,
struct cgit_period *period)
{
struct commitinfo *info;
struct string_list_item *author, *item;
struct authorstat *authorstat;
struct string_list *items;
char *tmp;
struct tm *date;
time_t t;
info = cgit_parse_commit(commit);
tmp = xstrdup(info->author);
- author = string_list_insert(tmp, authors);
+ author = string_list_insert(authors, tmp);
if (!author->util)
author->util = xcalloc(1, sizeof(struct authorstat));
else
free(tmp);
authorstat = author->util;
items = &authorstat->list;
t = info->committer_date;
date = gmtime(&t);
period->trunc(date);
tmp = xstrdup(period->pretty(date));
- item = string_list_insert(tmp, items);
+ item = string_list_insert(items, tmp);
if (item->util)
free(tmp);
item->util++;
authorstat->total++;
cgit_free_commitinfo(info);
}
static int cmp_total_commits(const void *a1, const void *a2)
{
const struct string_list_item *i1 = a1;
const struct string_list_item *i2 = a2;
const struct authorstat *auth1 = i1->util;
const struct authorstat *auth2 = i2->util;
return auth2->total - auth1->total;
}
/* Walk the commit DAG and collect number of commits per author per
* timeperiod into a nested string_list collection.
*/
struct string_list collect_stats(struct cgit_context *ctx,
struct cgit_period *period)
{
struct string_list authors;
@@ -258,49 +258,49 @@ void print_combined_authorrow(struct string_list *authors, int from, int to,
struct string_list *items;
struct string_list_item *date;
time_t now;
long i, j, total, subtotal;
struct tm *tm;
char *tmp;
time(&now);
tm = gmtime(&now);
period->trunc(tm);
for (i = 1; i < period->count; i++)
period->dec(tm);
total = 0;
htmlf("<tr><td class='%s'>%s</td>", leftclass,
fmt(name, to - from + 1));
for (j = 0; j < period->count; j++) {
tmp = period->pretty(tm);
period->inc(tm);
subtotal = 0;
for (i = from; i <= to; i++) {
author = &authors->items[i];
authorstat = author->util;
items = &authorstat->list;
- date = string_list_lookup(tmp, items);
+ date = string_list_lookup(items, tmp);
if (date)
subtotal += (size_t)date->util;
}
htmlf("<td class='%s'>%d</td>", centerclass, subtotal);
total += subtotal;
}
htmlf("<td class='%s'>%d</td></tr>", rightclass, total);
}
void print_authors(struct string_list *authors, int top,
struct cgit_period *period)
{
struct string_list_item *author;
struct authorstat *authorstat;
struct string_list *items;
struct string_list_item *date;
time_t now;
long i, j, total;
struct tm *tm;
char *tmp;
time(&now);
tm = gmtime(&now);
period->trunc(tm);
@@ -310,49 +310,49 @@ void print_authors(struct string_list *authors, int top,
html("<table class='stats'><tr><th>Author</th>");
for (j = 0; j < period->count; j++) {
tmp = period->pretty(tm);
htmlf("<th>%s</th>", tmp);
period->inc(tm);
}
html("<th>Total</th></tr>\n");
if (top <= 0 || top > authors->nr)
top = authors->nr;
for (i = 0; i < top; i++) {
author = &authors->items[i];
html("<tr><td class='left'>");
html_txt(author->string);
html("</td>");
authorstat = author->util;
items = &authorstat->list;
total = 0;
for (j = 0; j < period->count; j++)
period->dec(tm);
for (j = 0; j < period->count; j++) {
tmp = period->pretty(tm);
period->inc(tm);
- date = string_list_lookup(tmp, items);
+ date = string_list_lookup(items, tmp);
if (!date)
html("<td>0</td>");
else {
htmlf("<td>%d</td>", date->util);
total += (size_t)date->util;
}
}
htmlf("<td class='sum'>%d</td></tr>", total);
}
if (top < authors->nr)
print_combined_authorrow(authors, top, authors->nr - 1,
"Others (%d)", "left", "", "sum", period);
print_combined_authorrow(authors, 0, authors->nr - 1, "Total",
"total", "sum", "sum", period);
html("</table>");
}
/* Create a sorted string_list with one entry per author. The util-field
* 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)