{"thread":{"id":"12932","subject":"[PATCH] gitweb: Use feed link according to current view","startedAt":"2008-03-31T12:36:47Z","lastAt":"2008-03-31T12:36:47Z","messageCount":1,"participants":["Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"73436","messageId":"200803311436.48745.jnareb@gmail.com","threadId":"12932","inReplyTo":null,"subject":"[PATCH] gitweb: Use feed link according to current view","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-03-31T12:36:47Z","receivedAt":"2008-03-31T12:36:47Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Michael G. Noll said in comments to the \"Switching my code repository\nfrom Subversion (SVN) to git\" article (http://tinyurl.com/37v67l) in\nhis \"My digital moleskine\" blog, that one of the things he is missing\nin gitweb from SVN::Web is an RSS feed with news/information of the\ncurrent view (including RSS feed for single file or directory).\n\nThis is not exactly true, as since refactoring feed generation in\n  \"gitweb: Refactor feed generation, make output prettier, add Atom feed\"\n  commit-af6feeb229110a0fa77a179c2655fca08e72f879\ngitweb can generate feeds (RSS or Atom) for history of a given branch,\nhistory limited to a given directory, or history of a given file.\nNevertheless this required handcrafting the URL to get wanted RSS\nfeed.\n\n\nThis commit makes gitweb select feed links in the HTML header and in\npage footer depending on current view (action).  It is more elaborate,\nand I guess more correct, than simple patch adding $hash ('h')\nparameter to *all* URLs, including feed links, by Jean-Baptiste Quenot\n  Subject: [PATCH] gitweb: Add hash parameter in feed URL when a hash\n           is specified in the current request\n  Message-ID: <ae63f8b50803211138y6355fd11pa64cda50a1f53011@mail.gmail.com>\n\nIf $hash ('h') or $hash_base ('hb') parameter is a branch name\n(i.e. it starts with 'refs/heads/'; all generated URLs use this form\nto discriminate between tags and heads) it is used in feed URLs; if\n$file_name ('f') is defined it is used in feed URLs.  Feed title is\nset according to the kind of web feed: it is either 'log' for generic\nfeed, 'log of <branch>', 'history of <filename>' for generic history\n(using implicit or explicit HEAD, i.e. current branch) or 'history of\n<filename> on <branch>'.\n\nThere are special cases: 'heads' and 'forks' views should use OPML\nproviding list of available feeds; 'tags' probably also should use\nOPML; there is no web feed equivalent to 'search' view.  Currently all\nthose cases fallback to (show) default feed.\n\nCurrently feed can have but one starting point, and does not support\nnegative (exclude) commit arguments.  Therefore for now for *diff\nviews it is chosen that feed follow the \"to\" part: to-name, to-commit\nfor 'blobdiff', 'treediff' and 'commitdiff' views.\n\n\nGenerating parameters for href() for feed link was separated\n(refactored) into get_feed_info() subroutine.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nBcc: Michael G. Noll\n\nThe naming of a feeds (feed titles) could use some improvements,\nbut I've no good idea how.\n\n\n gitweb/gitweb.perl |  110 +++++++++++++++++++++++++++++++++++++++++----------\n 1 files changed, 88 insertions(+), 22 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex ec73cb1..50922bc 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -587,7 +587,7 @@ exit;\n ## ======================================================================\n ## action links\n \n-sub href(%) {\n+sub href (%) {\n \tmy %params = @_;\n \t# default is to use -absolute url() i.e. $my_uri\n \tmy $href = $params{-full} ? $my_url : $my_uri;\n@@ -1443,6 +1443,46 @@ sub format_snapshot_links {\n \t}\n }\n \n+## ......................................................................\n+## functions returning values to be passed, perhaps after some\n+## transformation, to other functions; e.g. returning arguments to href()\n+\n+# returns hash to be passed to href to generate gitweb URL\n+# in -title key it returns description of link\n+sub get_feed_info {\n+\tmy $format = shift || 'Atom';\n+\tmy %res = (action => lc($format));\n+\n+\t# feed links are possible only for project views\n+\treturn unless (defined $project);\n+\t# some views should link to OPML, or to generic project feed,\n+\t# or don't have specific feed yet (so they should use generic)\n+\treturn if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);\n+\n+\tmy $branch;\n+\t# branches refs uses 'refs/heads/' prefix (fullname) to differentiate\n+\t# from tag links; this also makes possible to detect branch links\n+\tif ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||\n+\t    (defined $hash      && $hash      =~ m!^refs/heads/(.*)$!)) {\n+\t\t$branch = $1;\n+\t}\n+\t# find log type for feed description (title)\n+\tmy $type = 'log';\n+\tif (defined $file_name) {\n+\t\t$type  = \"history of $file_name\";\n+\t\t$type .= \"/\" if ($action eq 'tree');\n+\t\t$type .= \" on '$branch'\" if (defined $branch);\n+\t} else {\n+\t\t$type = \"log of $branch\" if (defined $branch);\n+\t}\n+\n+\t$res{-title} = $type;\n+\t$res{'hash'} = (defined $branch ? \"refs/heads/$branch\" : undef);\n+\t$res{'file_name'} = $file_name;\n+\n+\treturn %res;\n+}\n+\n ## ----------------------------------------------------------------------\n ## git utility subroutines, invoking git commands\n \n@@ -2506,30 +2546,49 @@ EOF\n \t\t}\n \t}\n \tif (defined $project) {\n-\t\tprintf('<link rel=\"alternate\" title=\"%s log RSS feed\" '.\n-\t\t       'href=\"%s\" type=\"application/rss+xml\" />'.\"\\n\",\n-\t\t       esc_param($project), href(action=>\"rss\"));\n-\t\tprintf('<link rel=\"alternate\" title=\"%s log RSS feed (no merges)\" '.\n-\t\t       'href=\"%s\" type=\"application/rss+xml\" />'.\"\\n\",\n-\t\t       esc_param($project), href(action=>\"rss\",\n-\t\t                                 extra_options=>\"--no-merges\"));\n-\t\tprintf('<link rel=\"alternate\" title=\"%s log Atom feed\" '.\n-\t\t       'href=\"%s\" type=\"application/atom+xml\" />'.\"\\n\",\n-\t\t       esc_param($project), href(action=>\"atom\"));\n-\t\tprintf('<link rel=\"alternate\" title=\"%s log Atom feed (no merges)\" '.\n-\t\t       'href=\"%s\" type=\"application/atom+xml\" />'.\"\\n\",\n-\t\t       esc_param($project), href(action=>\"atom\",\n-\t\t                                 extra_options=>\"--no-merges\"));\n+\t\tmy %href_params = get_feed_info();\n+\t\tif (!exists $href_params{'-title'}) {\n+\t\t\t$href_params{'-title'} = 'log';\n+\t\t}\n+\n+\t\tforeach my $format qw(RSS Atom) {\n+\t\t\tmy $type = lc($format);\n+\t\t\tmy %link_attr = (\n+\t\t\t\t'-rel' => 'alternate',\n+\t\t\t\t'-title' => \"$project - $href_params{'-title'} - $format feed\",\n+\t\t\t\t'-type' => \"application/$type+xml\"\n+\t\t\t);\n+\n+\t\t\t$href_params{'action'} = $type;\n+\t\t\t$link_attr{'-href'} = href(%href_params);\n+\t\t\tprint \"<link \".\n+\t\t\t      \"rel=\\\"$link_attr{'-rel'}\\\" \".\n+\t\t\t      \"title=\\\"$link_attr{'-title'}\\\" \".\n+\t\t\t      \"href=\\\"$link_attr{'-href'}\\\" \".\n+\t\t\t      \"type=\\\"$link_attr{'-type'}\\\" \".\n+\t\t\t      \"/>\\n\";\n+\n+\t\t\t$href_params{'extra_options'} = '--no-merges';\n+\t\t\t$link_attr{'-href'} = href(%href_params);\n+\t\t\t$link_attr{'-title'} .= ' (no merges)';\n+\t\t\tprint \"<link \".\n+\t\t\t      \"rel=\\\"$link_attr{'-rel'}\\\" \".\n+\t\t\t      \"title=\\\"$link_attr{'-title'}\\\" \".\n+\t\t\t      \"href=\\\"$link_attr{'-href'}\\\" \".\n+\t\t\t      \"type=\\\"$link_attr{'-type'}\\\" \".\n+\t\t\t      \"/>\\n\";\n+\t\t}\n+\n \t} else {\n \t\tprintf('<link rel=\"alternate\" title=\"%s projects list\" '.\n-\t\t       'href=\"%s\" type=\"text/plain; charset=utf-8\"/>'.\"\\n\",\n+\t\t       'href=\"%s\" type=\"text/plain; charset=utf-8\" />'.\"\\n\",\n \t\t       $site_name, href(project=>undef, action=>\"project_index\"));\n \t\tprintf('<link rel=\"alternate\" title=\"%s projects feeds\" '.\n-\t\t       'href=\"%s\" type=\"text/x-opml\"/>'.\"\\n\",\n+\t\t       'href=\"%s\" type=\"text/x-opml\" />'.\"\\n\",\n \t\t       $site_name, href(project=>undef, action=>\"opml\"));\n \t}\n \tif (defined $favicon) {\n-\t\tprint qq(<link rel=\"shortcut icon\" href=\"$favicon\" type=\"image/png\"/>\\n);\n+\t\tprint qq(<link rel=\"shortcut icon\" href=\"$favicon\" type=\"image/png\" />\\n);\n \t}\n \n \tprint \"</head>\\n\" .\n@@ -2603,10 +2662,17 @@ sub git_footer_html {\n \t\tif (defined $descr) {\n \t\t\tprint \"<div class=\\\"page_footer_text\\\">\" . esc_html($descr) . \"</div>\\n\";\n \t\t}\n-\t\tprint $cgi->a({-href => href(action=>\"rss\"),\n-\t\t              -class => \"rss_logo\"}, \"RSS\") . \" \";\n-\t\tprint $cgi->a({-href => href(action=>\"atom\"),\n-\t\t              -class => \"rss_logo\"}, \"Atom\") . \"\\n\";\n+\n+\t\tmy %href_params = get_feed_info();\n+\t\t$href_params{'-title'} ||= 'log';\n+\n+\t\tforeach my $format qw(RSS Atom) {\n+\t\t\t$href_params{'action'} = lc($format);\n+\t\t\tprint $cgi->a({-href => href(%href_params),\n+\t\t\t              -title => \"$href_params{'-title'} $format feed\",\n+\t\t\t              -class => \"rss_logo\"}, $format).\"\\n\";\n+\t\t}\n+\n \t} else {\n \t\tprint $cgi->a({-href => href(project=>undef, action=>\"opml\"),\n \t\t              -class => \"rss_logo\"}, \"OPML\") . \" \";\n-- \n1.5.4.4\n"}]}