From: Penny Leach Date: Wed, 02 Nov 2005 02:03:11 GMT Subject: [PATCH] Gitweb: Per-head rss feeds and per-project opml. Message-ID: <11308969914190-git-send-email-penny@catalyst.net.nz> Signed-off-by: Penny Leach --- 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 = ""; + + if ($show_rss) { + $rss_link = ""; + } + $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 = ""; + } + $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; } @@ -327,9 +355,21 @@ sub git_footer_html { if (defined $descr) { print "\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 "\n" . "\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") . "\n" . "\n"; } @@ -1095,6 +1136,7 @@ sub git_summary { "" . $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") . "\n" . ""; } else { @@ -1240,6 +1282,7 @@ sub git_heads { "" . $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") . "\n" . ""; } @@ -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 "\n". "\n"; print "\n"; - print "$project\n". - "" . escapeHTML("$my_url?p=$project;a=summary") . "\n". - "$project log\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\n". + "$link\n". + "$description\n". "en\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 "\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 "\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 "\n"; + } + } + } print "\n". "\n".