[PATCH v4 13/16] ui-shared: deduplicate some code in repolink

Andy Green andy at warmcat.com
Wed Jun 20 12:13:04 CEST 2018


8 lines of code are duplicated in repolink, clean it
so the common code appears once

Signed-off-by: Andy Green <andy at warmcat.com>
Reviewed-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c |   26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/ui-shared.c b/ui-shared.c
index d2985c8..21bbded 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -241,28 +241,22 @@ static char *repolink(const char *title, const char *class, const char *page,
 	if (ctx.cfg.virtual_root) {
 		html_url_path(ctx.cfg.virtual_root);
 		html_url_path(ctx.repo->url);
-		if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
-			html("/");
-		if (page) {
-			html_url_path(page);
-			html("/");
-			if (path)
-				html_url_path(path);
-		}
 	} else {
 		html_url_path(ctx.cfg.script_name);
 		html("?url=");
 		html_url_arg(ctx.repo->url);
-		if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
-			html("/");
-		if (page) {
-			html_url_arg(page);
-			html("/");
-			if (path)
-				html_url_arg(path);
-		}
 		delim = "&";
 	}
+
+	if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
+		html("/");
+	if (page) {
+		html_url_arg(page);
+		html("/");
+		if (path)
+			html_url_arg(path);
+	}
+
 	if (head && ctx.repo->defbranch && strcmp(head, ctx.repo->defbranch)) {
 		html(delim);
 		html("h=");



More information about the CGit mailing list