List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH v6 1/1] ui-shared: allow to split the repository link
@ 2016-12-06 17:58 petr.vorel
  2017-02-18 17:34 ` john
  0 siblings, 1 reply; 2+ messages in thread
From: petr.vorel @ 2016-12-06 17:58 UTC (permalink / 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".

Signed-off-by: Petr Vorel <petr.vorel at gmail.com>
Cc: "Jason A. Donenfeld" <Jason at zx2c4.com>
Cc: John Keeping <john at keeping.me.uk>
---
Explanation im man page might need to be improved.

Changes v5->v6:
* Remove config variable, as requested by Jason.

Changes v4->v5:
* Rename config variable to split-summary-repo-link

Changes v3->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.

Changes v2->v3:
* New config variable "summary-enable-split-repo-link", minor cleanup.

Changes v1->v2:
* Minor cleanup.
---
 cgitrc.5.txt |  4 +++-
 ui-shared.c  | 27 ++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 9fcf445..500b7ee 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -604,7 +604,9 @@ repo.source-filter::
 
 repo.url::
 	The relative url used to access the repository. This must be the first
-	setting specified for each repo. Default value: none.
+	setting specified for each repo. Unless repo.url is different from
+	repo.name, cgit splits the repository link in the top of repository
+	"summary" view. Default value: none.
 
 
 REPOSITORY-SPECIFIC CGITRC FILE
diff --git a/ui-shared.c b/ui-shared.c
index 2e4fcd9..b4cad55 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -936,7 +936,32 @@ 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 don't split link as
+		 * it wouldn't make sense to split the path.
+		 * */
+		if (!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'>\n");
-- 
2.11.0



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v6 1/1] ui-shared: allow to split the repository link
  2016-12-06 17:58 [PATCH v6 1/1] ui-shared: allow to split the repository link petr.vorel
@ 2017-02-18 17:34 ` john
  0 siblings, 0 replies; 2+ messages in thread
From: john @ 2017-02-18 17:34 UTC (permalink / raw)


On Tue, Dec 06, 2016 at 06:58:04PM +0100, Petr Vorel wrote:
> 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".
> 
> Signed-off-by: Petr Vorel <petr.vorel at gmail.com>
> Cc: "Jason A. Donenfeld" <Jason at zx2c4.com>
> Cc: John Keeping <john at keeping.me.uk>

With one minor nit below,

Reviewed-by: John Keeping <john at keeping.me.uk>

> ---
> Explanation im man page might need to be improved.
> 
> Changes v5->v6:
> * Remove config variable, as requested by Jason.
> 
> Changes v4->v5:
> * Rename config variable to split-summary-repo-link
> 
> Changes v3->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.
> 
> Changes v2->v3:
> * New config variable "summary-enable-split-repo-link", minor cleanup.
> 
> Changes v1->v2:
> * Minor cleanup.
> ---
>  cgitrc.5.txt |  4 +++-
>  ui-shared.c  | 27 ++++++++++++++++++++++++++-
>  2 files changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/cgitrc.5.txt b/cgitrc.5.txt
> index 9fcf445..500b7ee 100644
> --- a/cgitrc.5.txt
> +++ b/cgitrc.5.txt
> @@ -604,7 +604,9 @@ repo.source-filter::
>  
>  repo.url::
>  	The relative url used to access the repository. This must be the first
> -	setting specified for each repo. Default value: none.
> +	setting specified for each repo. Unless repo.url is different from
> +	repo.name, cgit splits the repository link in the top of repository
> +	"summary" view. Default value: none.
>  
>  
>  REPOSITORY-SPECIFIC CGITRC FILE
> diff --git a/ui-shared.c b/ui-shared.c
> index 2e4fcd9..b4cad55 100644
> --- a/ui-shared.c
> +++ b/ui-shared.c
> @@ -936,7 +936,32 @@ 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 don't split link as
> +		 * it wouldn't make sense to split the path.
> +		 * */

Extra "* " before the closing */ here.

> +		if (!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'>\n");
> -- 
> 2.11.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-02-18 17:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-06 17:58 [PATCH v6 1/1] ui-shared: allow to split the repository link petr.vorel
2017-02-18 17:34 ` john

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).