This is in preparation of moving the code that iterates over the
repository list into a walk pattern.  This walk pattern will permit
other views on the repository list more easily, such as a section
only list.

Signed-off-by: Tim Nordell <[email protected]>

diff --git a/ui-repolist.c b/ui-repolist.c
index c240af3..6b751d2 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -269,13 +269,24 @@ static int sort_repolist(char *field)
        return 0;
 }
 
+struct repolist_ctx {
+       int columns;
+       int sorted;
+       int hits;
+       const char *section;
+       const char *last_section;
+};
 
 void cgit_print_repolist(void)
 {
-       int i, columns = 3, hits = 0;
-       char *last_section = NULL;
-       char *section;
-       int sorted = 0;
+       struct repolist_ctx repolist_ctx;
+       struct repolist_ctx *c = &repolist_ctx;
+       int i;
+
+       repolist_ctx.columns      = 3;
+       repolist_ctx.hits         = 0;
+       repolist_ctx.last_section = NULL;
+       repolist_ctx.sorted       = 0;
 
        if (!any_repos_visible()) {
                cgit_print_error_page(404, "Not found", "No repositories 
found");
@@ -283,9 +294,9 @@ void cgit_print_repolist(void)
        }
 
        if (ctx.cfg.enable_index_links)
-               ++columns;
+               ++repolist_ctx.columns;
        if (ctx.cfg.enable_index_owner)
-               ++columns;
+               ++repolist_ctx.columns;
 
        ctx.page.title = ctx.cfg.root_title;
        cgit_print_http_headers();
@@ -296,7 +307,7 @@ void cgit_print_repolist(void)
                html_include(ctx.cfg.index_header);
 
        if (ctx.qry.sort)
-               sorted = sort_repolist(ctx.qry.sort);
+               repolist_ctx.sorted = sort_repolist(ctx.qry.sort);
        else if (ctx.cfg.section_sort)
                sort_repolist("section");
 
@@ -306,29 +317,29 @@ void cgit_print_repolist(void)
                ctx.repo = &cgit_repolist.repos[i];
                if (!is_visible(ctx.repo))
                        continue;
-               hits++;
-               if (hits <= ctx.qry.ofs)
+               c->hits++;
+               if (c->hits <= ctx.qry.ofs)
                        continue;
-               if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
+               if (c->hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
                        continue;
-               section = ctx.repo->section;
-               if (section && !strcmp(section, ""))
-                       section = NULL;
-               if (!sorted &&
-                   ((last_section == NULL && section != NULL) ||
-                   (last_section != NULL && section == NULL) ||
-                   (last_section != NULL && section != NULL &&
-                    strcmp(section, last_section)))) {
+               c->section = ctx.repo->section;
+               if (c->section && !strcmp(c->section, ""))
+                       c->section = NULL;
+               if (!c->sorted &&
+                   ((c->last_section == NULL && c->section != NULL) ||
+                   (repolist_ctx.last_section != NULL && c->section == NULL) ||
+                   (repolist_ctx.last_section != NULL && c->section != NULL &&
+                    strcmp(c->section, c->last_section)))) {
                        htmlf("<tr class='nohover'><td colspan='%d' 
class='reposection'>",
-                             columns);
+                             c->columns);
                        cgit_open_filter(ctx.cfg.section_filter);
-                       html_txt(section);
+                       html_txt(c->section);
                        cgit_close_filter(ctx.cfg.section_filter);
                        html("</td></tr>");
-                       last_section = section;
+                       c->last_section = c->section;
                }
                htmlf("<tr><td class='%s'>",
-                     !sorted && section ? "sublevel-repo" : "toplevel-repo");
+                     !c->sorted && c->section ? "sublevel-repo" : 
"toplevel-repo");
                cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
                html("</td><td>");
                html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL);
@@ -364,8 +375,8 @@ void cgit_print_repolist(void)
                html("</tr>\n");
        }
        html("</table>");
-       if (hits > ctx.cfg.max_repo_count)
-               print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, 
ctx.qry.sort);
+       if (repolist_ctx.hits > ctx.cfg.max_repo_count)
+               print_pager(repolist_ctx.hits, ctx.cfg.max_repo_count, 
ctx.qry.search, ctx.qry.sort);
        cgit_print_docend();
 }
 
-- 
2.4.9

_______________________________________________
CGit mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/cgit

Reply via email to