For a later commit in this series, this logic is common in a couple
of places.  This simplifies the logic a bit instead of having several
nested checks.  Additionally, this patch removes the need for using
"!strcmp(c->section, "")" as this is equivalent to comparing
"'\0' == repo->section[0]".

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

diff --git a/ui-repolist.c b/ui-repolist.c
index 38a42c7..df2dc92 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -329,6 +329,30 @@ static void html_repository(struct cgit_repo *repo, bool 
sorted)
        html("</tr>\n");
 }
 
+static inline bool should_emit_section(struct repolist_ctx *c, struct 
cgit_repo *repo)
+{
+       /* If we're sorted, we will not have a new section emitted. */
+       if (c->sorted)
+               return false;
+
+       /* We need a valid repo section for the rest of the checks */
+       if (NULL == repo->section)
+               return false;
+
+       /* If the section title is blank (e.g. top-level), we never emit
+        * a section heading. */
+       if ('\0' == repo->section[0])
+               return false;
+
+       /* Finally, compare the last section name to the current.  If they're
+        * the same, do not emit a section area. */
+       if (NULL != c->last_section && !strcmp(repo->section, c->last_section))
+               return false;
+
+       c->last_section = repo->section;
+       return true;
+}
+
 void cgit_print_repolist(void)
 {
        struct repolist_ctx repolist_ctx;
@@ -375,16 +399,8 @@ void cgit_print_repolist(void)
                if (c->hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
                        continue;
                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)))) {
+               if (should_emit_section(&repolist_ctx, ctx.repo))
                        html_section(ctx.repo, c->columns);
-                       c->last_section = c->section;
-               }
                html_repository(ctx.repo, repolist_ctx.sorted);
        }
        html("</table>");
-- 
2.4.9

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

Reply via email to