]> git.cameronkatri.com Git - cgit.git/blobdiff - ui-stats.c
global: make 'char *path' const where possible
[cgit.git] / ui-stats.c
index 9cd8247e0c1cc5f117052fa0ba47bc4945d8cd8a..7acd358d0f1ca7a137ae901481ae36b1d3374cfd 100644 (file)
@@ -3,12 +3,6 @@
 #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;
@@ -174,6 +168,7 @@ static void add_commit(struct string_list *authors, struct commit *commit,
        char *tmp;
        struct tm *date;
        time_t t;
+       uintptr_t *counter;
 
        info = cgit_parse_commit(commit);
        tmp = xstrdup(info->author);
@@ -189,9 +184,11 @@ static void add_commit(struct string_list *authors, struct commit *commit,
        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);
 }
@@ -286,7 +283,7 @@ static void print_combined_authorrow(struct string_list *authors, int from,
                        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;
@@ -340,8 +337,8 @@ static void print_authors(struct string_list *authors, int top,
                        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);
@@ -372,11 +369,13 @@ void cgit_show_stats(void)
 
        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);
@@ -387,9 +386,10 @@ void cgit_show_stats(void)
        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) {
@@ -421,5 +421,6 @@ void cgit_show_stats(void)
        }
        html("</h2>");
        print_authors(&authors, top, period);
+       cgit_print_layout_end();
 }