{"thread":{"id":"923","subject":"[PATCH] opml output for gitweb","startedAt":"2005-06-13T22:53:47Z","lastAt":"2005-06-13T22:53:47Z","messageCount":1,"participants":["Erik van Konijnenburg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"4922","messageId":"20050614005347.A851@banaan.localdomain","threadId":"923","inReplyTo":null,"subject":"[PATCH] opml output for gitweb","fromName":"Erik van Konijnenburg","fromEmail":"ekonijn@xs4all.nl","sentAt":"2005-06-13T22:53:47Z","receivedAt":"2005-06-13T22:53:47Z","isPatch":true,"sender":{"key":"ekonijn@xs4all.nl","avatar":null},"body":"Gitweb currently has a nice orange thingy at the footer of\nevery page, except for the title page.\n\nThe attached patch addresses that lacuna with an OPML link,\na file format to import and export RSS collections from\nfeed readers.  Using this link, you can subscribe to all\nRSS feeds on a git site in one go.\n\nThe patch was prepared against ftp://ehlo.org/gitweb2.cgi\nand manually edited to undo localisation to my test tree.\nIt's only lightly tested: exporting a feed collection from\ngitweb and importing it in Sage and liferea seems to work.\n\nRegards,\nErik\n\nSigned-off-by: Erik van Konijnenburg <ekonijn@xs4all.nl>\n\n--- /home/konijn/gitweb2.cgi\t2005-06-13 21:58:39.000000000 +0200\n+++ gitweb.cgi\t2005-06-14 00:31:24.000000000 +0200\n@@ -50,6 +50,9 @@\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 } else {\n \t$action = \"summary\";\n@@ -243,7 +246,8 @@\n div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }\n div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }\n div.search { margin:4px 8px; position:absolute; top:56px; right:12px }\n-a.rss_logo { float:right; padding:3px 0px; width:35px; line-height:10px;\n+a.rss_logo {\n+\tfloat:right; padding:3px 0px; width:35px; line-height:10px;\n \tborder:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;\n \tcolor:#ffffff; background-color:#ff6600;\n \tfont-weight:bold; font-family:sans-serif; font-size:10px;\n@@ -289,6 +293,9 @@\n \t\t}\n \t\tprint $cgi->a({-href => \"$my_uri?p=$project;a=rss\", -class => \"rss_logo\"}, \"RSS\") . \"\\n\";\n \t}\n+\telse {\n+\t\tprint $cgi->a({-href => \"$my_uri?a=opml\", -class => \"rss_logo\"}, \"OPML\") . \"\\n\";\n+\t}\n \tprint \"</div>\\n\" .\n \t      \"</body>\\n\" .\n \t      \"</html>\";\n@@ -1197,6 +1204,83 @@\n \tgit_footer_html();\n }\n \n+sub git_opml {\n+\tmy @list;\n+\tif (-d $projects_list) {\n+\t\t# search in directory\n+\t\tmy $dir = $projects_list;\n+\t\topendir my $dh, $dir or return undef;\n+\t\twhile (my $dir = readdir($dh)) {\n+\t\t\tif (-e \"$projectroot/$dir/HEAD\") {\n+\t\t\t\tmy $pr = {\n+\t\t\t\t\tpath => $dir,\n+\t\t\t\t};\n+\t\t\t\tpush @list, $pr\n+\t\t\t}\n+\t\t}\n+\t\tclosedir($dh);\n+\t} elsif (-f $projects_list) {\n+\t\t# read from file(url-encoded):\n+\t\t# 'git%2Fgit.git Linus+Torvalds'\n+\t\t# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'\n+\t\t# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'\n+\t\topen my $fd , $projects_list or return undef;\n+\t\twhile (my $line = <$fd>) {\n+\t\t\tchomp $line;\n+\t\t\tmy ($path, $owner) = split ' ', $line;\n+\t\t\t$path = unescape($path);\n+\t\t\t$owner = unescape($owner);\n+\t\t\tif (!defined $path) {\n+\t\t\t\tnext;\n+\t\t\t}\n+\t\t\tif (-e \"$projectroot/$path/HEAD\") {\n+\t\t\t\tmy $pr = {\n+\t\t\t\t\tpath => $path,\n+\t\t\t\t\towner => $owner,\n+\t\t\t\t};\n+\t\t\t\tpush @list, $pr\n+\t\t\t}\n+\t\t}\n+\t\tclose $fd;\n+\t}\n+\n+\tif (!@list) {\n+\t\tdie_error(undef, \"No project found.\");\n+\t}\n+\t@list = sort {$a->{'path'} cmp $b->{'path'}} @list;\n+\n+\n+\tprint $cgi->header(-type => 'text/xml', -charset => 'utf-8');\n+\tprint \"<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?>\\n\".\n+\t      \"<opml version=\\\"1.0\\\">\\n\".\n+\t      \"<head>\".\n+\t      \"  <title>Git OPML Export</title>\\n\".\n+\t      \"</head>\\n\".\n+\t      \"<body>\\n\".\n+\t      \"  <outline text=\\\"Git RSS Feeds\\\">\\n\";\n+\n+\tforeach my $pr (@list) {\n+\t\tmy %proj = %$pr;\n+\t\tmy $head = git_read_hash(\"$proj{'path'}/HEAD\");\n+\t\tif (!defined $head) {\n+\t\t\tnext;\n+\t\t}\n+\t\t$ENV{'GIT_OBJECT_DIRECTORY'} = \"$projectroot/$proj{'path'}/objects\";\n+\t\tmy %co = git_read_commit($head);\n+\t\tif (!%co) {\n+\t\t\tnext;\n+\t\t}\n+\n+\t\tmy $path = escapeHTML(chop_str($proj{'path'}, 25, 5));\n+\t\tmy $rss =  \"$my_url?p=$proj{'path'};a=rss\";\n+\t\tmy $html =  \"$my_url?p=$proj{'path'};a=log\";\n+\t\tprint \"<outline type=\\\"rss\\\" text=\\\"$path\\\" title=\\\"$path\\\" xmlUrl=\\\"$rss\\\" htmlUrl=\\\"$html\\\"/>\\n\";\n+\t}\n+\tprint \"  </outline>\\n\".\n+\t      \"</body>\\n\".\n+\t      \"</opml>\\n\";\n+}\n+\n sub git_rss {\n \t# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ\n \topen my $fd, \"-|\", \"$gitbin/git-rev-list --max-count=20 \" . git_read_hash(\"$project/HEAD\") or die_error(undef, \"Open failed.\");\n"}]}