Move the code that generates the repository and section snippets
of html into their own helper functions.  This is for code reuse
in a later patch in this series.

This also moves some dependencies from the context out into
the caller instead of in the section of code moved.

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

diff --git a/ui-repolist.c b/ui-repolist.c
index 6b751d2..38a42c7 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -277,6 +277,58 @@ struct repolist_ctx {
        const char *last_section;
 };
 
+static void html_section(struct cgit_repo *repo, int columns)
+{
+       htmlf("<tr class='nohover'><td colspan='%d' class='reposection'>",
+               columns);
+       cgit_open_filter(ctx.cfg.section_filter);
+       html_txt(repo->section);
+       cgit_close_filter(ctx.cfg.section_filter);
+       html("</td></tr>");
+}
+
+static void html_repository(struct cgit_repo *repo, bool sorted)
+{
+       bool is_toplevel;
+
+       is_toplevel = (NULL != repo->section && '\0' != repo->section[0]);
+       htmlf("<tr><td class='%s'>",
+               (!sorted && is_toplevel) ? "sublevel-repo" : "toplevel-repo");
+       cgit_summary_link(repo->name, repo->name, NULL, NULL);
+       html("</td><td>");
+       html_link_open(cgit_repourl(repo->url), NULL, NULL);
+       html_ntxt(ctx.cfg.max_repodesc_len, repo->desc);
+       html_link_close();
+       html("</td><td>");
+       if (ctx.cfg.enable_index_owner) {
+               if (repo->owner_filter) {
+                       cgit_open_filter(repo->owner_filter);
+                       html_txt(repo->owner);
+                       cgit_close_filter(repo->owner_filter);
+               } else {
+                       html("<a href='");
+                       html_attr(cgit_currenturl());
+                       html("?q=");
+                       html_url_arg(repo->owner);
+                       html("'>");
+                       html_txt(repo->owner);
+                       html("</a>");
+               }
+               html("</td><td>");
+       }
+       print_modtime(repo);
+       html("</td>");
+       if (ctx.cfg.enable_index_links) {
+               html("<td>");
+               cgit_summary_link("summary", NULL, "button", NULL);
+               cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
+                               0, NULL, NULL, ctx.qry.showmsg, 0);
+               cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
+               html("</td>");
+       }
+       html("</tr>\n");
+}
+
 void cgit_print_repolist(void)
 {
        struct repolist_ctx repolist_ctx;
@@ -330,49 +382,10 @@ void cgit_print_repolist(void)
                    (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'>",
-                             c->columns);
-                       cgit_open_filter(ctx.cfg.section_filter);
-                       html_txt(c->section);
-                       cgit_close_filter(ctx.cfg.section_filter);
-                       html("</td></tr>");
+                       html_section(ctx.repo, c->columns);
                        c->last_section = c->section;
                }
-               htmlf("<tr><td class='%s'>",
-                     !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);
-               html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc);
-               html_link_close();
-               html("</td><td>");
-               if (ctx.cfg.enable_index_owner) {
-                       if (ctx.repo->owner_filter) {
-                               cgit_open_filter(ctx.repo->owner_filter);
-                               html_txt(ctx.repo->owner);
-                               cgit_close_filter(ctx.repo->owner_filter);
-                       } else {
-                               html("<a href='");
-                               html_attr(cgit_currenturl());
-                               html("?q=");
-                               html_url_arg(ctx.repo->owner);
-                               html("'>");
-                               html_txt(ctx.repo->owner);
-                               html("</a>");
-                       }
-                       html("</td><td>");
-               }
-               print_modtime(ctx.repo);
-               html("</td>");
-               if (ctx.cfg.enable_index_links) {
-                       html("<td>");
-                       cgit_summary_link("summary", NULL, "button", NULL);
-                       cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
-                                     0, NULL, NULL, ctx.qry.showmsg, 0);
-                       cgit_tree_link("tree", NULL, "button", NULL, NULL, 
NULL);
-                       html("</td>");
-               }
-               html("</tr>\n");
+               html_repository(ctx.repo, repolist_ctx.sorted);
        }
        html("</table>");
        if (repolist_ctx.hits > ctx.cfg.max_repo_count)
-- 
2.4.9

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

Reply via email to