threads / patch / 5287

patchgitweb: Show project's git URL on summary page

Subject: [PATCH] gitweb: Show project's git URL on summary page

## tl;dr

10 messages between Aug 15, 2006 and Aug 17, 2006. Diffs are folded; open one to read it.

replies: 9people: 4as markdown or json

Jakub Narebski· Aug 15, 2006, 18:03 UTC · lore

Add support for showing multiple clone/fetch git URLs for project on a summary page. URL for project is created from base URL and project name.

For example for XMMS2 project (xmms.se) the git base URL would be git://git.xmms.se/xmms2.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This probably could be combined with Aneesh Kumar patches 
  "[PATCH] gitweb: Add support for cloneurl."
  "[PATCH] gitweb: Support multiple clone urls"
which reads from clone/fetch URLs from $GIT_DIR/cloneurl file,
i.e. from $projectroot/$project/cloneurl file.  Default would be to
use base URL from @git_base_url_list, and if there is cloneurl file
for a project, use it instead.
I'm not so sure of benefits of yet another way to provide
clone/fetch URL, namely Yasushi SHOJI
  "[PATCH] gitweb: configurable home link string"
This patch is port (with improvements) of Sham Chukoury patch
  "Show project tree git url on summary page" (8e327dfbd)
for gitweb-xmms2. Should I add below line to commit message?
Signed-off-by: Sham Chukoury <eleusis@xmms.org>
 Makefile           |    2 ++
 gitweb/gitweb.perl |   18 ++++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
Show changes to 2 files +18 −2

Makefile, gitweb/gitweb.perl

diff --git a/Makefile b/Makefile
index a538710..ae77d99 100644
--- a/Makefile
+++ b/Makefile
@@ -125,6 +125,7 @@ # default configuration for gitweb
 GITWEB_CONFIG = gitweb_config.perl
 GITWEB_SITENAME =
 GITWEB_PROJECTROOT = /pub/git
+GITWEB_BASE_URL =
 GITWEB_LIST =
 GITWEB_HOMETEXT = indextext.html
 GITWEB_CSS = gitweb.css
@@ -619,6 +620,7 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
 	    -e 's|++GITWEB_CONFIG++|$(GITWEB_CONFIG)|g' \
 	    -e 's|++GITWEB_SITENAME++|$(GITWEB_SITENAME)|g' \
 	    -e 's|++GITWEB_PROJECTROOT++|$(GITWEB_PROJECTROOT)|g' \
+	    -e 's|++GITWEB_BASE_URL++|$(GITWEB_BASE_URL)|g' \
 	    -e 's|++GITWEB_LIST++|$(GITWEB_LIST)|g' \
 	    -e 's|++GITWEB_HOMETEXT++|$(GITWEB_HOMETEXT)|g' \
 	    -e 's|++GITWEB_CSS++|$(GITWEB_CSS)|g' \
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index ab28caa..6dcf6a2 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -51,6 +51,10 @@ our $logo = "++GITWEB_LOGO++";
 # source of projects list
 our $projects_list = "++GITWEB_LIST++";
 
+# list of git base URLs used for URL to where fetch project from,
+# i.e. full URL is "$git_base_url/$project"
+our @git_base_url_list = ("++GIT_BASE_URL++");
+
 # default blob_plain mimetype and default charset for text/plain blob
 our $default_blob_plain_mimetype = 'text/plain';
 our $default_text_plain_charset  = undef;
@@ -1665,8 +1669,18 @@ sub git_summary {
 	print "<table cellspacing=\"0\">\n" .
 	      "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
 	      "<tr><td>owner</td><td>$owner</td></tr>\n" .
-	      "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
-	      "</table>\n";
+	      "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
+	my $is_first_url = 1;
+	foreach my $git_base_url (@git_base_url_list) {
+		next unless $git_base_url; # skip empty/zerolength URLs
+		print "<tr><td>";
+		if ($is_first_url) {
+			print "URL";
+			$is_first_url = 0;
+		}
+		print "</td><td>$git_base_url/$project</td></tr>\n";
+	}
+	print "</table>\n";
 
 	open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project)
 		or die_error(undef, "Open git-rev-list failed");
-- 
1.4.1.1
David Rientjes· Aug 15, 2006, 18:43 UTC · re: Jakub Narebski · lore

Re: [PATCH] gitweb: Show project's git URL on summary page

On Tue, 15 Aug 2006, Jakub Narebski wrote:
Show 37 quoted lines
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index ab28caa..6dcf6a2 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -51,6 +51,10 @@ our $logo = "++GITWEB_LOGO++";
>  # source of projects list
>  our $projects_list = "++GITWEB_LIST++";
>  
> +# list of git base URLs used for URL to where fetch project from,
> +# i.e. full URL is "$git_base_url/$project"
> +our @git_base_url_list = ("++GIT_BASE_URL++");
> +
>  # default blob_plain mimetype and default charset for text/plain blob
>  our $default_blob_plain_mimetype = 'text/plain';
>  our $default_text_plain_charset  = undef;
> @@ -1665,8 +1669,18 @@ sub git_summary {
>  	print "<table cellspacing=\"0\">\n" .
>  	      "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
>  	      "<tr><td>owner</td><td>$owner</td></tr>\n" .
> -	      "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
> -	      "</table>\n";
> +	      "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
> +	my $is_first_url = 1;
> +	foreach my $git_base_url (@git_base_url_list) {
> +		next unless $git_base_url; # skip empty/zerolength URLs
> +		print "<tr><td>";
> +		if ($is_first_url) {
> +			print "URL";
> +			$is_first_url = 0;
> +		}
> +		print "</td><td>$git_base_url/$project</td></tr>\n";
> +	}
> +	print "</table>\n";
>  
>  	open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project)
>  		or die_error(undef, "Open git-rev-list failed");
> 
Isn't it faster to do this (over 1.4.2):
Show changes to gitweb/gitweb.perl +9 −3
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index b5b89de..82b246d 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -53,6 +53,7 @@ our $logo = "++GITWEB_LOGO++";
 
 # source of projects list
 our $projects_list = "++GITWEB_LIST++";
+our @git_base_url_list = ("++GIT_BASE_URL++");
 
 # default blob_plain mimetype and default charset for text/plain blob
 our $default_blob_plain_mimetype = 'text/plain';
@@ -1668,8 +1669,14 @@ sub git_summary {
 	print "<table cellspacing=\"0\">\n" .
 	      "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
 	      "<tr><td>owner</td><td>$owner</td></tr>\n" .
-	      "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
-	      "</table>\n";
+	      "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
+	my $url_tag = "URL";
+	foreach my $git_base_url (@git_base_url_list) {
+		next unless $git_base_url;
+		print "<tr><td>$url_tag</td><td>$git_base_url/$project</td></tr>\n";
+		$url_tag = "";
+	}
+	print "</table>\n";
 
 	open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project)
 		or die_error(undef, "Open git-rev-list failed");
--

All the series of prints in this script could also probably more elegantly be 
written in the form:

print <<"(END HTML)";
	<table cellspacing="0">
		...
	</table>
	<tr><td>last change</td><td>$cd{'rfc2822'}</td><tr>
	...
(END HTML)

and then all the escape characters around quotes aren't needed.

		David
Jakub Narebski· Aug 15, 2006, 19:32 UTC · re: David Rientjes · lore

Re: [PATCH] gitweb: Show project's git URL on summary page

On 8/15/06, David Rientjes <rientjes@google.com> wrote:
> On Tue, 15 Aug 2006, Jakub Narebski wrote:
Show 18 quoted lines
> > +     my $is_first_url = 1;
> > +     foreach my $git_base_url (@git_base_url_list) {
> > +             next unless $git_base_url; # skip empty/zerolength URLs
> > +             print "<tr><td>";
> > +             if ($is_first_url) {
> > +                     print "URL";
> > +                     $is_first_url = 0;
> > +             }
> > +             print "</td><td>$git_base_url/$project</td></tr>\n";
> > +     }
>
> Isn't it faster to do this (over 1.4.2):
> +       my $url_tag = "URL";
> +       foreach my $git_base_url (@git_base_url_list) {
> +               next unless $git_base_url;
> +               print "<tr><td>$url_tag</td><td>$git_base_url/$project</td></tr>\n";
> +               $url_tag = "";
> +       }
Yes, it is undobtedly better.
Acked-by: Jakub Narebski <jnareb@gmail.com>
-- 
Jakub Narebski
Jakub Narebski· Aug 15, 2006, 21:03 UTC · re: Jakub Narebski · lore

[PATCH (revised)] gitweb: Show project's git URL on summary page

>From 31e4de9f22a3b17d4ad0ac800132e4e1a0a15006 Mon Sep 17 00:00:00 2001
From: David Rientjes <rientjes@google.com>
Date: Tue, 15 Aug 2006 11:43:04 -0700
Subject: [PATCH] gitweb: Show project's git URL on summary page

Add support for showing multiple clone/fetch git URLs for project on a summary page. URL for project is created from base URL and project name.

For example for XMMS2 project (xmms.se) the git base URL would be git://git.xmms.se/xmms2.

With corrections from David Rientjes <rientjes@google.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 Makefile           |    2 ++
 gitweb/gitweb.perl |   14 ++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)
Show changes to 2 files +14 −2

Makefile, gitweb/gitweb.perl

diff --git a/Makefile b/Makefile
index a538710..ae77d99 100644
--- a/Makefile
+++ b/Makefile
@@ -125,6 +125,7 @@ # default configuration for gitweb
 GITWEB_CONFIG = gitweb_config.perl
 GITWEB_SITENAME =
 GITWEB_PROJECTROOT = /pub/git
+GITWEB_BASE_URL =
 GITWEB_LIST =
 GITWEB_HOMETEXT = indextext.html
 GITWEB_CSS = gitweb.css
@@ -619,6 +620,7 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
 	    -e 's|++GITWEB_CONFIG++|$(GITWEB_CONFIG)|g' \
 	    -e 's|++GITWEB_SITENAME++|$(GITWEB_SITENAME)|g' \
 	    -e 's|++GITWEB_PROJECTROOT++|$(GITWEB_PROJECTROOT)|g' \
+	    -e 's|++GITWEB_BASE_URL++|$(GITWEB_BASE_URL)|g' \
 	    -e 's|++GITWEB_LIST++|$(GITWEB_LIST)|g' \
 	    -e 's|++GITWEB_HOMETEXT++|$(GITWEB_HOMETEXT)|g' \
 	    -e 's|++GITWEB_CSS++|$(GITWEB_CSS)|g' \
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index ab28caa..bce3a2a 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -51,6 +51,10 @@ our $logo = "++GITWEB_LOGO++";
 # source of projects list
 our $projects_list = "++GITWEB_LIST++";
 
+# list of git base URLs used for URL to where fetch project from,
+# i.e. full URL is "$git_base_url/$project"
+our @git_base_url_list = ("++GITWEB_BASE_URL++");
+
 # default blob_plain mimetype and default charset for text/plain blob
 our $default_blob_plain_mimetype = 'text/plain';
 our $default_text_plain_charset  = undef;
@@ -1665,8 +1669,14 @@ sub git_summary {
 	print "<table cellspacing=\"0\">\n" .
 	      "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
 	      "<tr><td>owner</td><td>$owner</td></tr>\n" .
-	      "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
-	      "</table>\n";
+	      "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
+	my $url_tag = "URL";
+	foreach my $git_base_url (@git_base_url_list) {
+		next unless $git_base_url;
+		print "<tr><td>$url_tag</td><td>$git_base_url/$project</td></tr>\n";
+		$url_tag = "";
+	}
+	print "</table>\n";
 
 	open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash($project)
 		or die_error(undef, "Open git-rev-list failed");
-- 
1.4.1.1
David Rientjes· Aug 15, 2006, 21:36 UTC · re: Jakub Narebski · lore

Re: [PATCH (revised)] gitweb: Show project's git URL on summary page

On 8/15/06, Jakub Narebski <jnareb@gmail.com> wrote:
Show 15 quoted lines
> From 31e4de9f22a3b17d4ad0ac800132e4e1a0a15006 Mon Sep 17 00:00:00 2001
> From: David Rientjes <rientjes@google.com>
> Date: Tue, 15 Aug 2006 11:43:04 -0700
> Subject: [PATCH] gitweb: Show project's git URL on summary page
>
> Add support for showing multiple clone/fetch git URLs for project on
> a summary page. URL for project is created from base URL and project
> name.
>
> For example for XMMS2 project (xmms.se) the git base URL would be
> git://git.xmms.se/xmms2.
>
> With corrections from David Rientjes <rientjes@google.com>
>
> Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Aneesh Kumar K.V· Aug 16, 2006, 07:31 UTC · re: Jakub Narebski · lore

Re: [PATCH (revised)] gitweb: Show project's git URL on summary page

Jakub Narebski wrote:
Show 14 quoted lines
> From 31e4de9f22a3b17d4ad0ac800132e4e1a0a15006 Mon Sep 17 00:00:00 2001
> From: David Rientjes <rientjes@google.com>
> Date: Tue, 15 Aug 2006 11:43:04 -0700
> Subject: [PATCH] gitweb: Show project's git URL on summary page
> 
> Add support for showing multiple clone/fetch git URLs for project on
> a summary page. URL for project is created from base URL and project
> name.
> 
> For example for XMMS2 project (xmms.se) the git base URL would be
> git://git.xmms.se/xmms2.
> 
> With corrections from David Rientjes <rientjes@google.com>
>

this can give wrong value is some case with index.aux as projects_list. I have a setup where project details are displayed via gitweb but not reachable via http:// url and some reachable via http:// url.

For the first one only ssh:// based clone mechanism will work and for the other both will work. How do we handle that

-aneesh
Jakub Narebski· Aug 16, 2006, 12:56 UTC · re: Aneesh Kumar K.V · lore

Re: [PATCH (revised)] gitweb: Show project's git URL on summary page

Aneesh Kumar K.V wrote:
Show 6 quoted lines
> this can give wrong value is some case with index.aux as projects_list. 
> I have a setup where project details are displayed via gitweb but not
> reachable via http:// url and some reachable via http:// url. 
> 
> For the first one only ssh:// based clone mechanism will work and for 
> the other both will work. How do we handle that

See my "[PATCH 2/2] gitweb: Add support for per project git URLs" in this thread.

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
Jakub Narebski· Aug 16, 2006, 12:50 UTC · re: Jakub Narebski · lore

[PATCH 2/2] gitweb: Add support for per project git URLs

It is now possible for project to have individual clone/fetch URLs. They are provided in new file 'cloneurl' added below project's $GIT_DIR directory.

If there is no cloneurl file, concatenation of git base URLs with project name is used.

This is merge of Jakub Narebski and David Rientjes
  gitweb: Show project's git URL on summary page
with Aneesh Kumar
  gitweb: Add support for cloneurl.
  gitweb: Support multiple clone urls
patches.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
---
Based on previous patch.
 gitweb/gitweb.perl |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
Show changes to gitweb/gitweb.perl +17 −3
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 37a6284..7c92ac3 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -533,6 +533,16 @@ sub git_get_project_description {
 	return $descr;
 }
 
+sub git_get_project_url_list {
+	my $path = shift;
+
+	open my $fd, "$projectroot/$path/cloneurl" or return undef;
+	my @git_project_url_list = map { chomp; $_ } <$fd>;
+	close $fd;
+
+	return wantarray ? @git_project_url_list : \@git_project_url_list;
+}
+
 sub git_get_projects_list {
 	my @list;
 
@@ -1697,10 +1707,14 @@ sub git_summary {
 	      "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
 	      "<tr><td>owner</td><td>$owner</td></tr>\n" .
 	      "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
+	# use per project git URL list in $projectroot/$project/cloneurl
+	# or make project git URL from git base URL and project name
 	my $url_tag = "URL";
-	foreach my $git_base_url (@git_base_url_list) {
-		next unless $git_base_url;
-		print "<tr><td>$url_tag</td><td>$git_base_url/$project</td></tr>\n";
+	my @url_list = git_get_project_url_list($project);
+	@url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
+	foreach my $git_url (@url_list) {
+		next unless $git_url;
+		print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
 		$url_tag = "";
 	}
 	print "</table>\n";
-- 
1.4.1.1
Junio C Hamano· Aug 16, 2006, 20:40 UTC · re: Jakub Narebski · lore

Re: [PATCH 2/2] gitweb: Add support for per project git URLs

Jakub Narebski <jnareb@gmail.com> writes:
Show 16 quoted lines
> It is now possible for project to have individual clone/fetch URLs.
> They are provided in new file 'cloneurl' added below project's
> $GIT_DIR directory.
>
> If there is no cloneurl file, concatenation of git base URLs with
> project name is used.
>
> This is merge of Jakub Narebski and David Rientjes
>   gitweb: Show project's git URL on summary page
> with Aneesh Kumar
>   gitweb: Add support for cloneurl.
>   gitweb: Support multiple clone urls
> patches.
>
> Signed-off-by: Jakub Narebski <jnareb@gmail.com>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>

I'll take this for now, but we might want to consider moving 'description' and 'cloneurl' information to the config file to prevent cluttering.

        gitweb.description
        gitweb.giturl
The URL is not for cloning only, but also for fetch/pull, right?
Jakub Narebski· Aug 17, 2006, 09:31 UTC · re: Junio C Hamano · lore

Re: [PATCH 2/2] gitweb: Add support for per project git URLs

Junio C Hamano wrote:
Show 27 quoted lines
> Jakub Narebski <jnareb@gmail.com> writes:
> 
>> It is now possible for project to have individual clone/fetch URLs.
>> They are provided in new file 'cloneurl' added below project's
>> $GIT_DIR directory.
>>
>> If there is no cloneurl file, concatenation of git base URLs with
>> project name is used.
>>
>> This is merge of Jakub Narebski and David Rientjes
>>   gitweb: Show project's git URL on summary page
>> with Aneesh Kumar
>>   gitweb: Add support for cloneurl.
>>   gitweb: Support multiple clone urls
>> patches.
>>
>> Signed-off-by: Jakub Narebski <jnareb@gmail.com>
>> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
> 
> I'll take this for now, but we might want to consider moving
> 'description' and 'cloneurl' information to the config file to
> prevent cluttering.
> 
>         gitweb.description
>         gitweb.giturl
> 
> The URL is not for cloning only, but also for fetch/pull, right?

As of now reading text file is faster than invoking git-repo-config... although reimplementing _reading_ part of git-repo-config in Perl should be easy...

cloneurl name is leftover from Aneesh Kumar patch. 
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

← back to recent threads