aboutsummaryrefslogtreecommitdiffstats
path: root/ui-stats.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-stats.c')
-rw-r--r--ui-stats.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/ui-stats.c b/ui-stats.c
index 84b247c..bc27308 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -209,13 +209,12 @@ static int cmp_total_commits(const void *a1, const void *a2)
209/* Walk the commit DAG and collect number of commits per author per 209/* Walk the commit DAG and collect number of commits per author per
210 * timeperiod into a nested string_list collection. 210 * timeperiod into a nested string_list collection.
211 */ 211 */
212static struct string_list collect_stats(struct cgit_context *ctx, 212static struct string_list collect_stats(struct cgit_period *period)
213 struct cgit_period *period)
214{ 213{
215 struct string_list authors; 214 struct string_list authors;
216 struct rev_info rev; 215 struct rev_info rev;
217 struct commit *commit; 216 struct commit *commit;
218 const char *argv[] = {NULL, ctx->qry.head, NULL, NULL, NULL, NULL}; 217 const char *argv[] = {NULL, ctx.qry.head, NULL, NULL, NULL, NULL};
219 int argc = 3; 218 int argc = 3;
220 time_t now; 219 time_t now;
221 long i; 220 long i;
@@ -229,9 +228,9 @@ static struct string_list collect_stats(struct cgit_context *ctx,
229 period->dec(tm); 228 period->dec(tm);
230 strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm); 229 strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm);
231 argv[2] = xstrdup(fmt("--since=%s", tmp)); 230 argv[2] = xstrdup(fmt("--since=%s", tmp));
232 if (ctx->qry.path) { 231 if (ctx.qry.path) {
233 argv[3] = "--"; 232 argv[3] = "--";
234 argv[4] = ctx->qry.path; 233 argv[4] = ctx.qry.path;
235 argc += 2; 234 argc += 2;
236 } 235 }
237 init_revisions(&rev, NULL); 236 init_revisions(&rev, NULL);
@@ -360,30 +359,30 @@ static void print_authors(struct string_list *authors, int top,
360 * for each author is another string_list which is used to calculate the 359 * for each author is another string_list which is used to calculate the
361 * number of commits per time-interval. 360 * number of commits per time-interval.
362 */ 361 */
363void cgit_show_stats(struct cgit_context *ctx) 362void cgit_show_stats(void)
364{ 363{
365 struct string_list authors; 364 struct string_list authors;
366 struct cgit_period *period; 365 struct cgit_period *period;
367 int top, i; 366 int top, i;
368 const char *code = "w"; 367 const char *code = "w";
369 368
370 if (ctx->qry.period) 369 if (ctx.qry.period)
371 code = ctx->qry.period; 370 code = ctx.qry.period;
372 371
373 i = cgit_find_stats_period(code, &period); 372 i = cgit_find_stats_period(code, &period);
374 if (!i) { 373 if (!i) {
375 cgit_print_error("Unknown statistics type: %c", code[0]); 374 cgit_print_error("Unknown statistics type: %c", code[0]);
376 return; 375 return;
377 } 376 }
378 if (i > ctx->repo->max_stats) { 377 if (i > ctx.repo->max_stats) {
379 cgit_print_error("Statistics type disabled: %s", period->name); 378 cgit_print_error("Statistics type disabled: %s", period->name);
380 return; 379 return;
381 } 380 }
382 authors = collect_stats(ctx, period); 381 authors = collect_stats(period);
383 qsort(authors.items, authors.nr, sizeof(struct string_list_item), 382 qsort(authors.items, authors.nr, sizeof(struct string_list_item),
384 cmp_total_commits); 383 cmp_total_commits);
385 384
386 top = ctx->qry.ofs; 385 top = ctx.qry.ofs;
387 if (!top) 386 if (!top)
388 top = 10; 387 top = 10;
389 388
@@ -392,10 +391,10 @@ void cgit_show_stats(struct cgit_context *ctx)
392 html("<form method='get' action=''>"); 391 html("<form method='get' action=''>");
393 cgit_add_hidden_formfields(1, 0, "stats"); 392 cgit_add_hidden_formfields(1, 0, "stats");
394 html("<table><tr><td colspan='2'/></tr>"); 393 html("<table><tr><td colspan='2'/></tr>");
395 if (ctx->repo->max_stats > 1) { 394 if (ctx.repo->max_stats > 1) {
396 html("<tr><td class='label'>Period:</td>"); 395 html("<tr><td class='label'>Period:</td>");
397 html("<td class='ctrl'><select name='period' onchange='this.form.submit();'>"); 396 html("<td class='ctrl'><select name='period' onchange='this.form.submit();'>");
398 for (i = 0; i < ctx->repo->max_stats; i++) 397 for (i = 0; i < ctx.repo->max_stats; i++)
399 html_option(fmt("%c", periods[i].code), 398 html_option(fmt("%c", periods[i].code),
400 periods[i].name, fmt("%c", period->code)); 399 periods[i].name, fmt("%c", period->code));
401 html("</select></td></tr>"); 400 html("</select></td></tr>");
@@ -414,9 +413,9 @@ void cgit_show_stats(struct cgit_context *ctx)
414 html("</form>"); 413 html("</form>");
415 html("</div>"); 414 html("</div>");
416 htmlf("<h2>Commits per author per %s", period->name); 415 htmlf("<h2>Commits per author per %s", period->name);
417 if (ctx->qry.path) { 416 if (ctx.qry.path) {
418 html(" (path '"); 417 html(" (path '");
419 html_txt(ctx->qry.path); 418 html_txt(ctx.qry.path);
420 html("')"); 419 html("')");
421 } 420 }
422 html("</h2>"); 421 html("</h2>");