git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gitweb: support the rel=vcs microformat
@ 2009-01-07  4:25 Joey Hess
  2009-01-07 12:30 ` Giuseppe Bilotta
  2009-01-09 23:49 ` Jakub Narebski
  0 siblings, 2 replies; 22+ messages in thread
From: Joey Hess @ 2009-01-07  4:25 UTC (permalink / raw)
  To: git

The rel=vcs microformat allows a web page to indicate the locations of
repositories related to it in a machine-parseable manner.
(See http://kitenet.net/~joey/rfc/rel-vcs/)

Make gitweb use the microformat in the header of pages it generates,
if it has been configured with project url information in any of the usual
ways.

Since getting the urls can require hitting disk, I avoided putting the
microformat on *every* page gitweb generates. Just put it on the project
summary page, the project list page, and the forks list page.
The first of these already looks up the urls, so adding the microformat was
free. There is a small overhead in including the microformat on the
latter two pages, but getting the project descriptions for those pages
already incurs a similar overhead, and the ability to get every repo url
in one place seems worthwhile.

This changes git_get_project_description() to not check wantarray, and only
return in list context -- the only way it is used AFAICS.

Signed-off-by: Joey Hess <joey@gnu.kitenet.net>
---
 gitweb/gitweb.perl |   38 ++++++++++++++++++++++++++------------
 1 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 99f71b4..3f8a228 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -789,6 +789,9 @@ $git_dir = "$projectroot/$project" if $project;
 our @snapshot_fmts = gitweb_get_feature('snapshot');
 @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
 
+# populated later with git urls for the project
+our @git_url_list;
+
 # dispatch
 if (!defined $action) {
 	if (defined $hash) {
@@ -2100,17 +2103,22 @@ sub git_show_project_tagcloud {
 }
 
 sub git_get_project_url_list {
+	# use per project git URL list in $projectroot/$path/cloneurl
+	# or make project git URL from git base URL and project name
 	my $path = shift;
 
+	my @ret;
+
 	$git_dir = "$projectroot/$path";
-	open my $fd, "$git_dir/cloneurl"
-		or return wantarray ?
-		@{ config_to_multi(git_get_project_config('url')) } :
-		   config_to_multi(git_get_project_config('url'));
-	my @git_project_url_list = map { chomp; $_ } <$fd>;
-	close $fd;
+	if (open my $fd, "$git_dir/cloneurl") {
+		@ret = map { chomp; $_ } <$fd>;
+		close $fd;
+	}
+	else {
+	       @ret = @{ config_to_multi(git_get_project_config('url')) };
+	}
 
-	return wantarray ? @git_project_url_list : \@git_project_url_list;
+	return @ret ? @ret : map { "$_/$project" } @git_base_url_list;
 }
 
 sub git_get_projects_list {
@@ -2953,6 +2961,10 @@ EOF
 		print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
 	}
 
+	foreach my $url (@git_url_list) {
+		print qq{<link rel="vcs" type="git" href="$url" />\n};
+	}
+
 	print "</head>\n" .
 	      "<body>\n";
 
@@ -4380,6 +4392,8 @@ sub git_project_list {
 		die_error(404, "No projects found");
 	}
 
+	@git_url_list = map { git_get_project_url_list($_->{path}) } @list;
+
 	git_header_html();
 	if (-f $home_text) {
 		print "<div class=\"index_include\">\n";
@@ -4400,6 +4414,8 @@ sub git_forks {
 	if (defined $order && $order !~ m/none|project|descr|owner|age/) {
 		die_error(400, "Unknown order parameter");
 	}
+	
+	@git_url_list = map { git_get_project_url_list($_->{path}) } @list;
 
 	my @list = git_get_projects_list($project);
 	if (!@list) {
@@ -4457,6 +4473,8 @@ sub git_summary {
 		@forklist = git_get_projects_list($project);
 	}
 
+	@git_url_list = git_get_project_url_list($project);
+
 	git_header_html();
 	git_print_page_nav('summary','', $head);
 
@@ -4468,12 +4486,8 @@ sub git_summary {
 		print "<tr id=\"metadata_lchange\"><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";
-	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) {
+	foreach my $git_url (@git_url_list) {
 		next unless $git_url;
 		print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
 		$url_tag = "";
-- 
1.5.6.5

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

end of thread, other threads:[~2009-01-10  1:46 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-07  4:25 [PATCH] gitweb: support the rel=vcs microformat Joey Hess
2009-01-07 12:30 ` Giuseppe Bilotta
2009-01-07 15:50   ` Joey Hess
2009-01-07 18:03     ` Giuseppe Bilotta
2009-01-07 18:41       ` Joey Hess
2009-01-10  0:01         ` Jakub Narebski
2009-01-07 18:45       ` Joey Hess
2009-01-07 19:02         ` Joey Hess
2009-01-07 23:24           ` [PATCH] gitweb: support the rel=vcs-* microformat Joey Hess
2009-01-08  7:56             ` Giuseppe Bilotta
2009-01-08 19:54               ` gitweb index performance (Re: [PATCH] gitweb: support the rel=vcs-* microformat) Joey Hess
2009-01-08 23:53                 ` J.H.
2009-01-09  0:16                   ` Miklos Vajna
2009-01-09  0:19                   ` Johannes Schindelin
2009-01-09  0:26                     ` J.H.
2009-01-10  1:44                   ` Jakub Narebski
2009-01-10  1:11                 ` Jakub Narebski
2009-01-10  1:04               ` [PATCH] gitweb: support the rel=vcs-* microformat Jakub Narebski
2009-01-10  0:52             ` Jakub Narebski
2009-01-10  0:03           ` [PATCH] gitweb: support the rel=vcs microformat Jakub Narebski
2009-01-09 23:56   ` Jakub Narebski
2009-01-09 23:49 ` Jakub Narebski

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