[PATCH v5 1/1] ui-shared: allow to split the repository link

Petr Vorel petr.vorel at gmail.com
Thu May 12 17:44:12 CEST 2016


Teach cgit split the repository link in the top of repository "summary"
view. This emulates the same behaviour as it's in gitweb.

This behaviour is not implemented for repositories which have
"repo.name" set different than "repo.url".

This feature is controlled by a new config variable:
"split-summary-repo-link" (disabled by default).

Signed-off-by: Petr Vorel <petr.vorel at gmail.com>
---
v5: Rename config variable to split-summary-repo-link
v4: Implement suggestions from John Keeping (thanks for them :-)):
* use strchr() instead of strtok_r() and variadic arrays
* use cgit_repourl() and html_*() instead of cgit_summary_link().
* add comment why we compare page.url and page.name
v3: New config variable "summary-enable-split-repo-link", minor cleanup.
v2: Minor cleanup.
---
 cgit.c         |  3 +++
 cgit.h         |  1 +
 cgitrc.5.txt   |  6 ++++++
 tests/setup.sh |  1 +
 ui-shared.c    | 29 ++++++++++++++++++++++++++++-
 5 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/cgit.c b/cgit.c
index fc482be..a133226 100644
--- a/cgit.c
+++ b/cgit.c
@@ -246,6 +246,8 @@ static void config_cb(const char *name, const char *value)
 		ctx.cfg.section_sort = atoi(value);
 	else if (!strcmp(name, "source-filter"))
 		ctx.cfg.source_filter = cgit_new_filter(value, SOURCE);
+	else if (!strcmp(name, "split-summary-repo-link"))
+		ctx.cfg.split_summary_repo_link = atoi(value);
 	else if (!strcmp(name, "summary-log"))
 		ctx.cfg.summary_log = atoi(value);
 	else if (!strcmp(name, "summary-branches"))
@@ -388,6 +390,7 @@ static void prepare_context(void)
 	ctx.cfg.section = "";
 	ctx.cfg.repository_sort = "name";
 	ctx.cfg.section_sort = 1;
+	ctx.cfg.split_summary_repo_link = 0;
 	ctx.cfg.summary_branches = 10;
 	ctx.cfg.summary_log = 10;
 	ctx.cfg.summary_tags = 10;
diff --git a/cgit.h b/cgit.h
index 325432b..bfd1dfb 100644
--- a/cgit.h
+++ b/cgit.h
@@ -254,6 +254,7 @@ struct cgit_config {
 	int section_from_path;
 	int snapshots;
 	int section_sort;
+	int split_summary_repo_link;
 	int summary_branches;
 	int summary_log;
 	int summary_tags;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 2e1912d..a84fc10 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -438,6 +438,12 @@ summary-branches::
 	Specifies the number of branches to display in the repository "summary"
 	view. Default value: "10".
 
+split-summary-repo-link::
+	Flag which, when set to "1", will make cgit split the repository link in
+	the top of repository "summary" view. This emulates the same behaviour as
+	it's in gitweb. This behaviour is not implemented for repositories which
+	have "repo.name" set different than "repo.url". Default value: "0".
+
 summary-log::
 	Specifies the number of log entries to display in the repository
 	"summary" view. Default value: "10".
diff --git a/tests/setup.sh b/tests/setup.sh
index 7590f04..4f445dc 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -109,6 +109,7 @@ enable-log-filecount=1
 enable-log-linecount=1
 summary-log=5
 summary-branches=5
+split-summary-repo-link=0
 summary-tags=5
 clone-url=git://example.org/\$CGIT_REPO_URL.git
 enable-filter-overrides=1
diff --git a/ui-shared.c b/ui-shared.c
index 9a38aa9..e86ea58 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -937,7 +937,34 @@ static void print_header(void)
 	if (ctx.repo) {
 		cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);
 		html(" : ");
-		cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
+
+		/*
+		 * NOTE: If repo.name and repo.url are different, we ignore
+		 * split_summary_repo_link flag and don't split link as it
+		 * wouldn't make sense to split the path.
+		 * */
+		if (ctx.cfg.split_summary_repo_link &&
+			!(strcmp(ctx.repo->name, ctx.repo->url))) {
+			char *name = ctx.repo->name;
+			char *start = name;
+			for (;;) {
+				char *delim = strchr(start, '/');
+				if (delim)
+					*delim = '\0';
+
+				html_link_open(cgit_repourl(name), NULL, NULL);
+				html_ntxt(strlen(start), start);
+				html_link_close();
+
+				if (!delim)
+					break;
+				*delim = '/';
+				html("/");
+				start = delim + 1;
+			}
+		} else
+			cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
+
 		if (ctx.env.authenticated) {
 			html("</td><td class='form'>");
 			html("<form method='get' action=''>\n");
-- 
2.8.1



More information about the CGit mailing list