{"thread":{"id":"2308","subject":"[PATCH] Gitweb: Per-head rss feeds and per-project opml.","startedAt":"2005-11-02T02:03:11Z","lastAt":"2005-11-02T02:03:23Z","messageCount":2,"participants":["Penny Leach"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"10982","messageId":"11308969914190-git-send-email-penny@catalyst.net.nz","threadId":"2308","inReplyTo":null,"subject":"[PATCH] Gitweb: Per-head rss feeds and per-project opml.","fromName":"Penny Leach","fromEmail":"penny@catalyst.net.nz","sentAt":"2005-11-02T02:03:11Z","receivedAt":"2005-11-02T02:03:11Z","isPatch":true,"sender":{"key":"penny@catalyst.net.nz","avatar":null},"body":"Signed-off-by: Penny Leach <penny@catalyst.net.nz>\n\n\n---\n\n gitweb.cgi |  104 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------\n 1 files changed, 91 insertions(+), 13 deletions(-)\n\nad295087a0969c6816d6acf57f39053666327f2e\ndiff --git a/gitweb.cgi b/gitweb.cgi\n--- a/gitweb.cgi\n+++ b/gitweb.cgi\n@@ -52,12 +52,18 @@ if (defined $action) {\n \tif ($action eq \"git-logo.png\") {\n \t\tgit_logo();\n \t\texit;\n-\t} elsif ($action eq \"opml\") {\n-\t\tgit_opml();\n-\t\texit;\n \t}\n }\n \n+my $show_rss = 0;\n+my $show_opml = 0;\n+if (!defined($action) || $action eq 'summary' || $action eq 'heads' || $action eq 'log' || $action eq 'shortlog') {\n+    $show_rss = 1;\n+}\n+if (!defined($action) || $action eq 'summary') {\n+    $show_opml = 1;\n+}\n+\n my $order = $cgi->param('o');\n if (defined $order) {\n \tif ($order =~ m/[^0-9a-zA-Z_]/) {\n@@ -80,11 +86,17 @@ if (defined $project) {\n \t\tundef $project;\n \t\tdie_error(undef, \"No such project.\");\n \t}\n-\t$rss_link = \"<link rel=\\\"alternate\\\" title=\\\"$project log\\\" href=\\\"$my_uri?p=$project;a=rss\\\" type=\\\"application/rss+xml\\\"/>\";\n+\t\n+\tif ($show_rss) {\n+\t    $rss_link = \"<link rel=\\\"alternate\\\" title=\\\"$project log\\\" href=\\\"$my_uri?p=$project;a=rss\\\" type=\\\"application/rss+xml\\\"/>\";\n+\t}\n+\n \t$ENV{'GIT_DIR'} = \"$projectroot/$project\";\n } else {\n-\tgit_project_list();\n-\texit;\n+        if (!defined($action)) {\n+\t    git_project_list();\n+\t    exit;\n+\t}\n }\n \n my $file_name = $cgi->param('f');\n@@ -96,11 +108,16 @@ if (defined $file_name) {\n }\n \n my $hash = $cgi->param('h');\n+my $rsshead;\n if (defined $hash) {\n \t$hash = validate_input($hash);\n \tif (!defined($hash)) {\n \t\tdie_error(undef, \"Invalid hash parameter.\");\n \t}\n+\tif ($show_rss) { #override it\n+\t        $rss_link = \"<link rel=\\\"alternate\\\" title=\\\"$project#$hash log\\\" href=\\\"$my_uri?p=$project;a=rss;h=$hash\\\" type=\\\"application/rss+xml\\\"/>\";\n+\t}\n+\t$rsshead = $hash;\n }\n \n my $hash_parent = $cgi->param('hp');\n@@ -202,6 +219,10 @@ if (!defined $action || $action eq \"summ\n } elsif ($action eq \"tag\") {\n \tgit_tag();\n \texit;\n+# moved to here so $project gets validated first\n+} elsif ($action eq \"opml\") {\n+\tgit_opml();\n+\texit;\n } else {\n \tundef $action;\n \tdie_error(undef, \"Unknown action.\");\n@@ -280,6 +301,13 @@ a.rss_logo {\n \tcolor:#ffffff; background-color:#ff6600;\n \tfont-weight:bold; font-family:sans-serif; font-size:10px;\n \ttext-align:center; text-decoration:none;\n+        margin:2px;\n+}\n+a.rss_logo_small {\n+    border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;\n+    color:#ffffff; background-color:#ff6600;\n+    font-weight:bold; font-family:sans-serif; font-size:10px;\n+    text-align:center; text-decoration:none;\n }\n a.rss_logo:hover { background-color:#ee5500; }\n </style>\n@@ -327,9 +355,21 @@ sub git_footer_html {\n \t\tif (defined $descr) {\n \t\t\tprint \"<div class=\\\"page_footer_text\\\">\" . escapeHTML($descr) . \"</div>\\n\";\n \t\t}\n-\t\tprint $cgi->a({-href => \"$my_uri?p=$project;a=rss\", -class => \"rss_logo\"}, \"RSS\") . \"\\n\";\n+\t\tif ($show_rss) {\n+\t\t        if (defined($rsshead)) {\n+  \t\t\t        print $cgi->a({-href => \"$my_uri?p=$project;a=rss;h=$rsshead\", -class => \"rss_logo\"}, \"RSS\") . \"\\n\";\n+  \t\t        }  else {\n+\t\t\t\tprint $cgi->a({-href => \"$my_uri?p=$project;a=rss\", -class => \"rss_logo\"}, \"RSS\") . \"\\n\";\n+\t\t\t}\n+\t\t}\n+\t\tif ($show_opml) {\n+\t\t\tprint $cgi->a({-href => \"$my_uri?p=$project;a=opml\", -class => \"rss_logo\"}, \"OPML\") . \"\\n\";\n+\t\t}\n+\n \t} else {\n-\t\tprint $cgi->a({-href => \"$my_uri?a=opml\", -class => \"rss_logo\"}, \"OPML\") . \"\\n\";\n+\t        if ($show_opml) {\n+\t\t    \tprint $cgi->a({-href => \"$my_uri?a=opml\", -class => \"rss_logo\"}, \"OPML\") . \"\\n\";\n+\t\t}\n \t}\n \tprint \"</div>\\n\" .\n \t      \"</body>\\n\" .\n@@ -864,6 +904,7 @@ sub git_project_list {\n \t\t      $cgi->a({-href => \"$my_uri?p=$pr->{'path'};a=summary\"}, \"summary\") .\n \t\t      \" | \" . $cgi->a({-href => \"$my_uri?p=$pr->{'path'};a=shortlog\"}, \"shortlog\") .\n \t\t      \" | \" . $cgi->a({-href => \"$my_uri?p=$pr->{'path'};a=log\"}, \"log\") .\n+\t\t      \" | \" . $cgi->a({-href => \"$my_uri?p=$pr->{'path'};a=opml\", -class => \"rss_logo_small\"}, \"OPML\") . \n \t\t      \"</td>\\n\" .\n \t\t      \"</tr>\\n\";\n \t}\n@@ -1095,6 +1136,7 @@ sub git_summary {\n \t\t\t\t      \"<td class=\\\"link\\\">\" .\n \t\t\t\t      $cgi->a({-href => \"$my_uri?p=$project;a=shortlog;h=$tag{'name'}\"}, \"shortlog\") .\n \t\t\t\t      \" | \" . $cgi->a({-href => \"$my_uri?p=$project;a=log;h=$tag{'name'}\"}, \"log\") .\n+\t\t\t\t      \" | \" . $cgi->a({-href => \"$my_uri?p=$project;a=rss;h=$tag{'name'}\", -class => \"rss_logo_small\"}, \"RSS\") .\n \t\t\t\t      \"</td>\\n\" .\n \t\t\t\t      \"</tr>\";\n \t\t\t} else {\n@@ -1240,6 +1282,7 @@ sub git_heads {\n \t\t\t      \"<td class=\\\"link\\\">\" .\n \t\t\t      $cgi->a({-href => \"$my_uri?p=$project;a=shortlog;h=$tag{'name'}\"}, \"shortlog\") .\n \t\t\t      \" | \" . $cgi->a({-href => \"$my_uri?p=$project;a=log;h=$tag{'name'}\"}, \"log\") .\n+\t\t\t      \" | \" . $cgi->a({-href => \"$my_uri?p=$project;a=rss;h=$tag{'name'}\", -class => \"rss_logo_small\"}, \"RSS\") . \n \t\t\t      \"</td>\\n\" .\n \t\t\t      \"</tr>\";\n \t\t}\n@@ -1428,16 +1471,31 @@ sub git_tree {\n \n sub git_rss {\n \t# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ\n-\topen my $fd, \"-|\", \"$gitbin/git-rev-list --max-count=150 \" . git_read_hash(\"$project/HEAD\") or die_error(undef, \"Open failed.\");\n+        my $read_hash;\n+\tif (!defined($hash)) {\n+\t    $read_hash = git_read_hash(\"$project/HEAD\");\n+\t} else {\n+\t    $read_hash = $hash; \n+\t}\n+\n+\topen my $fd, \"-|\", \"$gitbin/git-rev-list --max-count=150 $read_hash \" or die_error(undef, \"Open failed.\");\n \tmy (@revlist) = map { chomp; $_ } <$fd>;\n \tclose $fd or die_error(undef, \"Reading rev-list failed.\");\n \tprint $cgi->header(-type => 'text/xml', -charset => 'utf-8');\n \tprint \"<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?>\\n\".\n \t      \"<rss version=\\\"2.0\\\" xmlns:content=\\\"http://purl.org/rss/1.0/modules/content/\\\">\\n\";\n \tprint \"<channel>\\n\";\n-\tprint \"<title>$project</title>\\n\".\n-\t      \"<link>\" . escapeHTML(\"$my_url?p=$project;a=summary\") . \"</link>\\n\".\n-\t      \"<description>$project log</description>\\n\".\n+\tmy $title = $project;\n+\tmy $link = escapeHTML(\"$my_url?p=$project;a=summary\");\n+\tmy $description = \"$project log\";\n+\tif (defined($hash)) {\n+\t    $title .= \"#$hash\";\n+\t    $link  .= escapeHTML(\";h=$hash\");\n+\t    $description = $project.\"#\".$hash.\" log\";\n+\t}\n+\tprint \"<title>$title</title>\\n\".\n+\t      \"<link>$link</link>\\n\".\n+\t      \"<description>$description</description>\\n\".\n \t      \"<language>en</language>\\n\";\n \n \tfor (my $i = 0; $i <= $#revlist; $i++) {\n@@ -1482,7 +1540,13 @@ sub git_rss {\n }\n \n sub git_opml {\n-\tmy @list = git_read_projects();\n+\tmy @list;\n+\t\n+\tif (defined($project)) {\n+\t    @list = ( { 'path' => $project } );\n+\t} else {\n+\t    @list = git_read_projects();\n+\t}\n \n \tprint $cgi->header(-type => 'text/xml', -charset => 'utf-8');\n \tprint \"<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?>\\n\".\n@@ -1509,6 +1573,20 @@ sub git_opml {\n \t\tmy $rss =  \"$my_url?p=$proj{'path'};a=rss\";\n \t\tmy $html =  \"$my_url?p=$proj{'path'};a=summary\";\n \t\tprint \"<outline type=\\\"rss\\\" text=\\\"$path\\\" title=\\\"$path\\\" xmlUrl=\\\"$rss\\\" htmlUrl=\\\"$html\\\"/>\\n\";\n+\t\t\n+\t\t$project = $proj{'path'};\n+\t\tmy $taglist = git_read_refs('refs/heads');\n+\n+\t\tif (defined @$taglist) {\n+\t\t    foreach my $entry (@$taglist) {\n+                        my %tag = %$entry;\n+\t\t\tmy $path = escapeHTML(chop_str($proj{'path'}.'#'.$tag{'name'},25,5));\n+\t\t\tmy $rss = \"$my_url?p=$proj{'path'};h=$tag{'name'};a=rss\";\n+\t\t\tmy $html = \"$my_url?p=$proj{'path'};h=$tag{'name'};a=summary\";\n+\t\t\tprint \"<outline type=\\\"rss\\\" text=\\\"$path\\\" title=\\\"$path\\\" xmlUrl=\\\"$rss\\\" htmlUrl=\\\"$html\\\"/>\\n\";\n+\t\t    }\n+                }\n+\t\t\n \t}\n \tprint \"</outline>\\n\".\n \t      \"</body>\\n\".\n"},{"id":"10983","messageId":"43681E6B.6030608@catalyst.net.nz","threadId":"2308","inReplyTo":"11308969914190-git-send-email-penny@catalyst.net.nz","subject":"Re: [PATCH] Gitweb: Per-head rss feeds and per-project opml.","fromName":"Penny Leach","fromEmail":"penny@catalyst.net.nz","sentAt":"2005-11-02T02:03:23Z","receivedAt":"2005-11-02T02:03:23Z","isPatch":true,"sender":{"key":"penny@catalyst.net.nz","avatar":null},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nSorry, I should have said that this can be seen here:\n\nhttp://locke.catalyst.net.nz/gitweb\n\n\nPenny Leach wrote:\n> Signed-off-by: Penny Leach <penny@catalyst.net.nz>\n\n\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.2 (GNU/Linux)\nComment: Using GnuPG with Debian - http://enigmail.mozdev.org\n\niD8DBQFDaB5rGHUSCqMOwisRAntNAJ9bt4VgMCcK6LVTSPt8Hr2KuRCq6ACgq26o\nDneB+AI6jlPLabIL0Bikm3o=\n=4rH6\n-----END PGP SIGNATURE-----\n"}]}