[PATCH] Gitweb: Per-head rss feeds and per-project opml.

From: Penny Leach <penny@catalyst.net.nz>
Date: 2005-11-02 13:03:11
Signed-off-by: Penny Leach <penny@catalyst.net.nz>


---

 gitweb.cgi |  104 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 91 insertions(+), 13 deletions(-)

ad295087a0969c6816d6acf57f39053666327f2e
diff --git a/gitweb.cgi b/gitweb.cgi
--- a/gitweb.cgi
+++ b/gitweb.cgi
@@ -52,12 +52,18 @@ if (defined $action) {
 	if ($action eq "git-logo.png") {
 		git_logo();
 		exit;
-	} elsif ($action eq "opml") {
-		git_opml();
-		exit;
 	}
 }
 
+my $show_rss = 0;
+my $show_opml = 0;
+if (!defined($action) || $action eq 'summary' || $action eq 'heads' || $action eq 'log' || $action eq 'shortlog') {
+    $show_rss = 1;
+}
+if (!defined($action) || $action eq 'summary') {
+    $show_opml = 1;
+}
+
 my $order = $cgi->param('o');
 if (defined $order) {
 	if ($order =~ m/[^0-9a-zA-Z_]/) {
@@ -80,11 +86,17 @@ if (defined $project) {
 		undef $project;
 		die_error(undef, "No such project.");
 	}
-	$rss_link = "<link rel=\"alternate\" title=\"$project log\" href=\"$my_uri?p=$project;a=rss\" type=\"application/rss+xml\"/>";
+	
+	if ($show_rss) {
+	    $rss_link = "<link rel=\"alternate\" title=\"$project log\" href=\"$my_uri?p=$project;a=rss\" type=\"application/rss+xml\"/>";
+	}
+
 	$ENV{'GIT_DIR'} = "$projectroot/$project";
 } else {
-	git_project_list();
-	exit;
+        if (!defined($action)) {
+	    git_project_list();
+	    exit;
+	}
 }
 
 my $file_name = $cgi->param('f');
@@ -96,11 +108,16 @@ if (defined $file_name) {
 }
 
 my $hash = $cgi->param('h');
+my $rsshead;
 if (defined $hash) {
 	$hash = validate_input($hash);
 	if (!defined($hash)) {
 		die_error(undef, "Invalid hash parameter.");
 	}
+	if ($show_rss) { #override it
+	        $rss_link = "<link rel=\"alternate\" title=\"$project#$hash log\" href=\"$my_uri?p=$project;a=rss;h=$hash\" type=\"application/rss+xml\"/>";
+	}
+	$rsshead = $hash;
 }
 
 my $hash_parent = $cgi->param('hp');
@@ -202,6 +219,10 @@ if (!defined $action || $action eq "summ
 } elsif ($action eq "tag") {
 	git_tag();
 	exit;
+# moved to here so $project gets validated first
+} elsif ($action eq "opml") {
+	git_opml();
+	exit;
 } else {
 	undef $action;
 	die_error(undef, "Unknown action.");
@@ -280,6 +301,13 @@ a.rss_logo {
 	color:#ffffff; background-color:#ff6600;
 	font-weight:bold; font-family:sans-serif; font-size:10px;
 	text-align:center; text-decoration:none;
+        margin:2px;
+}
+a.rss_logo_small {
+    border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
+    color:#ffffff; background-color:#ff6600;
+    font-weight:bold; font-family:sans-serif; font-size:10px;
+    text-align:center; text-decoration:none;
 }
 a.rss_logo:hover { background-color:#ee5500; }
 </style>
@@ -327,9 +355,21 @@ sub git_footer_html {
 		if (defined $descr) {
 			print "<div class=\"page_footer_text\">" . escapeHTML($descr) . "</div>\n";
 		}
-		print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
+		if ($show_rss) {
+		        if (defined($rsshead)) {
+  			        print $cgi->a({-href => "$my_uri?p=$project;a=rss;h=$rsshead", -class => "rss_logo"}, "RSS") . "\n";
+  		        }  else {
+				print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
+			}
+		}
+		if ($show_opml) {
+			print $cgi->a({-href => "$my_uri?p=$project;a=opml", -class => "rss_logo"}, "OPML") . "\n";
+		}
+
 	} else {
-		print $cgi->a({-href => "$my_uri?a=opml", -class => "rss_logo"}, "OPML") . "\n";
+	        if ($show_opml) {
+		    	print $cgi->a({-href => "$my_uri?a=opml", -class => "rss_logo"}, "OPML") . "\n";
+		}
 	}
 	print "</div>\n" .
 	      "</body>\n" .
@@ -864,6 +904,7 @@ sub git_project_list {
 		      $cgi->a({-href => "$my_uri?p=$pr->{'path'};a=summary"}, "summary") .
 		      " | " . $cgi->a({-href => "$my_uri?p=$pr->{'path'};a=shortlog"}, "shortlog") .
 		      " | " . $cgi->a({-href => "$my_uri?p=$pr->{'path'};a=log"}, "log") .
+		      " | " . $cgi->a({-href => "$my_uri?p=$pr->{'path'};a=opml", -class => "rss_logo_small"}, "OPML") . 
 		      "</td>\n" .
 		      "</tr>\n";
 	}
@@ -1095,6 +1136,7 @@ sub git_summary {
 				      "<td class=\"link\">" .
 				      $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
 				      " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'name'}"}, "log") .
+				      " | " . $cgi->a({-href => "$my_uri?p=$project;a=rss;h=$tag{'name'}", -class => "rss_logo_small"}, "RSS") .
 				      "</td>\n" .
 				      "</tr>";
 			} else {
@@ -1240,6 +1282,7 @@ sub git_heads {
 			      "<td class=\"link\">" .
 			      $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
 			      " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'name'}"}, "log") .
+			      " | " . $cgi->a({-href => "$my_uri?p=$project;a=rss;h=$tag{'name'}", -class => "rss_logo_small"}, "RSS") . 
 			      "</td>\n" .
 			      "</tr>";
 		}
@@ -1428,16 +1471,31 @@ sub git_tree {
 
 sub git_rss {
 	# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
-	open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
+        my $read_hash;
+	if (!defined($hash)) {
+	    $read_hash = git_read_hash("$project/HEAD");
+	} else {
+	    $read_hash = $hash; 
+	}
+
+	open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 $read_hash " or die_error(undef, "Open failed.");
 	my (@revlist) = map { chomp; $_ } <$fd>;
 	close $fd or die_error(undef, "Reading rev-list failed.");
 	print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
 	print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
 	      "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
 	print "<channel>\n";
-	print "<title>$project</title>\n".
-	      "<link>" . escapeHTML("$my_url?p=$project;a=summary") . "</link>\n".
-	      "<description>$project log</description>\n".
+	my $title = $project;
+	my $link = escapeHTML("$my_url?p=$project;a=summary");
+	my $description = "$project log";
+	if (defined($hash)) {
+	    $title .= "#$hash";
+	    $link  .= escapeHTML(";h=$hash");
+	    $description = $project."#".$hash." log";
+	}
+	print "<title>$title</title>\n".
+	      "<link>$link</link>\n".
+	      "<description>$description</description>\n".
 	      "<language>en</language>\n";
 
 	for (my $i = 0; $i <= $#revlist; $i++) {
@@ -1482,7 +1540,13 @@ sub git_rss {
 }
 
 sub git_opml {
-	my @list = git_read_projects();
+	my @list;
+	
+	if (defined($project)) {
+	    @list = ( { 'path' => $project } );
+	} else {
+	    @list = git_read_projects();
+	}
 
 	print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
 	print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
@@ -1509,6 +1573,20 @@ sub git_opml {
 		my $rss =  "$my_url?p=$proj{'path'};a=rss";
 		my $html =  "$my_url?p=$proj{'path'};a=summary";
 		print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
+		
+		$project = $proj{'path'};
+		my $taglist = git_read_refs('refs/heads');
+
+		if (defined @$taglist) {
+		    foreach my $entry (@$taglist) {
+                        my %tag = %$entry;
+			my $path = escapeHTML(chop_str($proj{'path'}.'#'.$tag{'name'},25,5));
+			my $rss = "$my_url?p=$proj{'path'};h=$tag{'name'};a=rss";
+			my $html = "$my_url?p=$proj{'path'};h=$tag{'name'};a=summary";
+			print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
+		    }
+                }
+		
 	}
 	print "</outline>\n".
 	      "</body>\n".


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Wed Nov 02 13:03:53 2005

This archive was generated by hypermail 2.1.8 : 2005-11-02 13:04:27 EST