List for cgit developers and users
 help / color / mirror / Atom feed
From: tim.nordell at logicpd.com (Tim Nordell)
Subject: [PATCH v2 3/8] ui-repolist: Create context structure for cgit_print_repolist()
Date: Fri, 4 Mar 2016 17:24:51 -0600	[thread overview]
Message-ID: <1457133901-12998-4-git-send-email-tim.nordell@logicpd.com> (raw)
In-Reply-To: <1457133901-12998-1-git-send-email-tim.nordell@logicpd.com>

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 <tim.nordell at logicpd.com>

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



  parent reply	other threads:[~2016-03-04 23:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-26 20:58 [PATCH 0/3] ui-repolist: Support additional formatting for sections tim.nordell
2016-02-26 20:58 ` [PATCH 1/3] ui-repolist: Add section filter tim.nordell
2016-02-28 12:51   ` john
2016-02-26 20:58 ` [PATCH 2/3] ui-repolist: Restructure internal logic to be more extensible tim.nordell
2016-02-28 13:02   ` john
2016-02-29 20:51     ` tim.nordell
2016-02-26 20:58 ` [PATCH 3/3] ui-repolist: Support a trimmed view when several sections are present tim.nordell
2016-03-04 23:24 ` [PATCH v2 0/8] ui-repolist: Support additional formatting for sections tim.nordell
2016-03-04 23:24   ` [PATCH v2 1/8] ui-repolist: Add section filter tim.nordell
2016-03-04 23:24   ` [PATCH v2 2/8] ui-repolist: Remove conditional around print_header() tim.nordell
2016-03-04 23:24   ` tim.nordell [this message]
2016-03-04 23:24   ` [PATCH v2 4/8] ui-repolist: Move HTML generation into helper functions tim.nordell
2016-03-04 23:29   ` [PATCH v2 5/8] ui-repolist: Factor out logic for emitting a new section heading tim.nordell
2016-03-04 23:30   ` [PATCH v2 6/8] ui-repolist: Remove assignment of section to repolist_ctx tim.nordell
2016-03-04 23:30   ` [PATCH v2 7/8] ui-repolist: Restructure internal logic to be more extensible tim.nordell
2016-03-04 23:30   ` [PATCH v2 8/8] ui-repolist: Support a trimmed view when several sections are present tim.nordell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1457133901-12998-4-git-send-email-tim.nordell@logicpd.com \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).