cgit

commit 2e4a41e84029cbfa70c654fe5dfb35747f2dfbba

Author: Jason A. Donenfeld <Jason@zx2c4.com>

Make root handling sane again.

 ui-repolist.c | 2 +-
 ui-shared.c | 24 ++++++++++++------------
 ui-shared.h | 2 +-


diff --git a/ui-repolist.c b/ui-repolist.c
index 12ac1fc1303a3fa3209c6428cfdf686933a1f0a2..e945f6733270f83f654a3204a75edb42a0156f68 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -140,7 +140,7 @@ 	for (i = 0, ofs = 0; ofs < items; i++, ofs = i * pagelen) {
 		class = (ctx.qry.ofs == ofs) ? "current" : NULL;
 		html("<li>");
 		cgit_index_link(fmt("[%d]", i + 1), fmt("Page %d", i + 1),
-				class, search, sort, ofs);
+				class, search, sort, ofs, 0);
 		html("</li>");
 	}
 	html("</ul>");




diff --git a/ui-shared.c b/ui-shared.c
index 838437c46e07b1b632ceb6a915760c07d755f8c0..ff03cb25adf5eeb9ea5a09dc0bbc084921cae5e1 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -147,14 +147,14 @@ 		return ++rv;
 	return rvbuf;
 }
 
-static void site_url(const char *page, const char *search, const char *sort, int ofs)
+static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root)
 {
 	char *delim = "?";
 
-	if (!page)
-		html_attr(cgit_currenturl());
-	else
+	if (always_root || page)
 		html_attr(cgit_rooturl());
+	else
+		html_attr(cgit_currenturl());
 
 	if (page) {
 		htmlf("?p=%s", page);
@@ -179,7 +179,7 @@ 	}
 }
 
 static void site_link(const char *page, const char *name, const char *title,
-		      const char *class, const char *search, const char *sort, int ofs)
+		      const char *class, const char *search, const char *sort, int ofs, int always_root)
 {
 	html("<a");
 	if (title) {
@@ -193,16 +193,16 @@ 		html_attr(class);
 		html("'");
 	}
 	html(" href='");
-	site_url(page, search, sort, ofs);
+	site_url(page, search, sort, ofs, always_root);
 	html("'>");
 	html_txt(name);
 	html("</a>");
 }
 
 void cgit_index_link(const char *name, const char *title, const char *class,
-		     const char *pattern, const char *sort, int ofs)
+		     const char *pattern, const char *sort, int ofs, int always_root)
 {
-	site_link(NULL, name, title, class, pattern, sort, ofs);
+	site_link(NULL, name, title, class, pattern, sort, ofs, always_root);
 }
 
 static char *repolink(const char *title, const char *class, const char *page,
@@ -446,7 +446,7 @@ static void cgit_self_link(char *name, const char *title, const char *class)
 {
 	if (!strcmp(ctx.qry.page, "repolist"))
 		cgit_index_link(name, title, class, ctx.qry.search, ctx.qry.sort,
-				ctx.qry.ofs);
+				ctx.qry.ofs, 1);
 	else if (!strcmp(ctx.qry.page, "summary"))
 		cgit_summary_link(name, title, class, ctx.qry.head);
 	else if (!strcmp(ctx.qry.page, "tag"))
@@ -875,7 +875,7 @@ 	}
 
 	html("<td class='main'>");
 	if (ctx.repo) {
-		cgit_index_link("index", NULL, NULL, NULL, NULL, 0);
+		cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);
 		html(" : ");
 		cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
 		if (ctx.env.authenticated) {
@@ -953,10 +953,10 @@ 		html("'/>\n");
 		html("<input type='submit' value='search'/>\n");
 		html("</form>\n");
 	} else if (ctx.env.authenticated) {
-		site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0);
+		site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1);
 		if (ctx.cfg.root_readme)
 			site_link("about", "about", NULL, hc("about"),
-				  NULL, NULL, 0);
+				  NULL, NULL, 0, 1);
 		html("</td><td class='form'>");
 		html("<form method='get' action='");
 		html_attr(cgit_currenturl());




diff --git a/ui-shared.h b/ui-shared.h
index af78a132c801cd23a4df59e7fd23830e78e77fda..1b8ecb5c19df17e38fd99d836b47a88f0d413ea9 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -15,7 +15,7 @@
 extern void cgit_add_clone_urls(void (*fn)(const char *));
 
 extern void cgit_index_link(const char *name, const char *title,
-			    const char *class, const char *pattern, const char *sort, int ofs);
+			    const char *class, const char *pattern, const char *sort, int ofs, int always_root);
 extern void cgit_summary_link(const char *name, const char *title,
 			      const char *class, const char *head);
 extern void cgit_tag_link(const char *name, const char *title,