List for cgit developers and users
 help / color / mirror / Atom feed
From: petr.vorel at gmail.com (Petr Vorel)
Subject: [PATCH v5 1/1] ui-shared: allow to split the repository link
Date: Thu, 12 May 2016 17:44:12 +0200	[thread overview]
Message-ID: <1463067852-22123-1-git-send-email-petr.vorel@gmail.com> (raw)

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



             reply	other threads:[~2016-05-12 15:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-12 15:44 petr.vorel [this message]
2016-06-06 11:20 ` petr.vorel
2016-08-29 23:11 ` petr.vorel
2016-08-30  2:55   ` Jason
2016-11-23  4:15 ` Jason
2016-11-24 17:32   ` petr.vorel
2016-11-24 17:42     ` Jason
2016-11-24 19:14       ` john
2016-11-27  6:51         ` petr.vorel

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=1463067852-22123-1-git-send-email-petr.vorel@gmail.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).