]> git.cameronkatri.com Git - cgit.git/blobdiff - ui-repolist.c
Merge branch 'snapshot-fixes'
[cgit.git] / ui-repolist.c
index 3f78e28a8677773cb221deb8358417475bca8c56..2324273f8df7cc0a81ee787dd707b3047a4a350a 100644 (file)
@@ -6,6 +6,10 @@
  *   (see COPYING for full license text)
  */
 
+/* This is needed for strcasestr to be defined by <string.h> */
+#define _GNU_SOURCE 1
+#include <string.h>
+
 #include <time.h>
 
 #include "cgit.h"
@@ -19,7 +23,8 @@ time_t read_agefile(char *path)
 
        if (!(f = fopen(path, "r")))
                return -1;
-       fgets(buf, sizeof(buf), f);
+       if (fgets(buf, sizeof(buf), f) == NULL)
+               return -1;
        fclose(f);
        if (parse_date(buf, buf2, sizeof(buf2)))
                return strtoul(buf2, NULL, 10);
@@ -59,6 +64,15 @@ int is_match(struct cgit_repo *repo)
        return 0;
 }
 
+int is_in_url(struct cgit_repo *repo)
+{
+       if (!ctx.qry.url)
+               return 1;
+       if (repo->url && !prefixcmp(repo->url, ctx.qry.url))
+               return 1;
+       return 0;
+}
+
 void print_header(int columns)
 {
        html("<tr class='nohover'>"
@@ -71,6 +85,17 @@ void print_header(int columns)
        html("</tr>\n");
 }
 
+
+void print_pager(int items, int pagelen, char *search)
+{
+       int i;
+       html("<div class='pager'>");
+       for(i = 0; i * pagelen < items; i++)
+               cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL,
+                               search, i * pagelen);
+       html("</div>");
+}
+
 void cgit_print_repolist()
 {
        int i, columns = 4, hits = 0, header = 0;
@@ -90,11 +115,15 @@ void cgit_print_repolist()
        html("<table summary='repository list' class='list nowrap'>");
        for (i=0; i<cgit_repolist.count; i++) {
                ctx.repo = &cgit_repolist.repos[i];
-               if (!is_match(ctx.repo))
+               if (!(is_match(ctx.repo) && is_in_url(ctx.repo)))
+                       continue;
+               hits++;
+               if (hits <= ctx.qry.ofs)
+                       continue;
+               if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
                        continue;
                if (!header++)
                        print_header(columns);
-               hits++;
                if ((last_group == NULL && ctx.repo->group != NULL) ||
                    (last_group != NULL && ctx.repo->group == NULL) ||
                    (last_group != NULL && ctx.repo->group != NULL &&
@@ -107,9 +136,7 @@ void cgit_print_repolist()
                }
                htmlf("<tr><td class='%s'>",
                      ctx.repo->group ? "sublevel-repo" : "toplevel-repo");
-               html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL);
-               html_txt(ctx.repo->name);
-               html_link_close();
+               cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
                html("</td><td>");
                html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL);
                html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc);
@@ -121,9 +148,7 @@ void cgit_print_repolist()
                html("</td>");
                if (ctx.cfg.enable_index_links) {
                        html("<td>");
-                       html_link_open(cgit_repourl(ctx.repo->url),
-                                      NULL, "button");
-                       html("summary</a>");
+                       cgit_summary_link("summary", NULL, "button", NULL);
                        cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
                                      0, NULL, NULL);
                        cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
@@ -134,6 +159,8 @@ void cgit_print_repolist()
        html("</table>");
        if (!hits)
                cgit_print_error("No repositories found");
+       else if (hits > ctx.cfg.max_repo_count)
+               print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search);
        cgit_print_docend();
 }