]> git.cameronkatri.com Git - cgit.git/blobdiff - ui-stats.c
Add sort parameter to pager of repo list
[cgit.git] / ui-stats.c
index 9fc06d35135dc950fc1ff252b3c754fb2bced7cc..2a0c17460b0894f22e81eea7eacf7693b8d99d54 100644 (file)
@@ -1,10 +1,14 @@
-#include <string-list.h>
-
 #include "cgit.h"
 #include "html.h"
 #include "ui-shared.h"
 #include "ui-stats.h"
 
+#ifdef NO_C99_FORMAT
+#define SZ_FMT "%u"
+#else
+#define SZ_FMT "%zu"
+#endif
+
 #define MONTHS 6
 
 struct authorstat {
@@ -154,6 +158,14 @@ 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)
 {
@@ -167,7 +179,7 @@ static void add_commit(struct string_list *authors, struct commit *commit,
 
        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
@@ -178,7 +190,7 @@ static void add_commit(struct string_list *authors, struct commit *commit,
        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++;
@@ -271,14 +283,14 @@ void print_combined_authorrow(struct string_list *authors, int from, int to,
                        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);
+               htmlf("<td class='%s'>%ld</td>", centerclass, subtotal);
                total += subtotal;
        }
-       htmlf("<td class='%s'>%d</td></tr>", rightclass, total);
+       htmlf("<td class='%s'>%ld</td></tr>", rightclass, total);
 }
 
 void print_authors(struct string_list *authors, int top,
@@ -323,20 +335,20 @@ void print_authors(struct string_list *authors, int top,
                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);
+                               htmlf("<td>"SZ_FMT"</td>", (size_t)date->util);
                                total += (size_t)date->util;
                        }
                }
-               htmlf("<td class='sum'>%d</td></tr>", total);
+               htmlf("<td class='sum'>%ld</td></tr>", total);
        }
 
        if (top < authors->nr)
                print_combined_authorrow(authors, top, authors->nr - 1,
-                       "Others (%d)", "left", "", "sum", period);
+                       "Others (%ld)", "left", "", "sum", period);
 
        print_combined_authorrow(authors, 0, authors->nr - 1, "Total",
                "total", "sum", "sum", period);
@@ -359,7 +371,7 @@ void cgit_show_stats(struct cgit_context *ctx)
 
        i = cgit_find_stats_period(code, &period);
        if (!i) {
-               cgit_print_error(fmt("Unknown statistics type: %c", code));
+               cgit_print_error(fmt("Unknown statistics type: %c", code[0]));
                return;
        }
        if (i > ctx->repo->max_stats) {