{"thread":{"id":"9276","subject":"[PATCH] gitweb: Simplify 'opt' parameter validation, add \"no merges\" feeds","startedAt":"2007-07-28T14:27:32Z","lastAt":"2007-07-29T01:48:19Z","messageCount":2,"participants":["Jakub Narebski","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"48908","messageId":"11856328582066-git-send-email-jnareb@gmail.com","threadId":"9276","inReplyTo":null,"subject":"[PATCH] gitweb: Simplify 'opt' parameter validation, add \"no merges\" feeds","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-07-28T14:27:32Z","receivedAt":"2007-07-28T14:27:32Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Simplify and make more readable validation of 'opt' (extra options)\nparameter, using exists($hash{key}) instead of grepping keys of a hash\nfor value.\n\nMove 'opt' parameter to be the last (for now) in the URL.\n\nMake use of '--no-merges' extra option ('opt') by adding \"no merges\"\nRSS and Atom feeds to the HTML header.  Note that alternate format\nlinks in the RSS and Atom views do not use '--no-merges' option yet!\n\nAdds tests for the 'opt' parameter to t9500-gitweb-standalone-no-errors.sh\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nThis patch could (and probablu should) be split into four separate\npatches: simplify 'opt' parameter validation, move 'opt' parameter\nto be last in the generated URL, add tests for 'opt' parameter, and\nadd an example of using 'opt' parameter in the form of feeds without\nmerges.  But I wanted to avoid generating micro-commits.\n\nThis patch is based on 'master'.\n\n gitweb/gitweb.perl                     |   17 ++++++++++++-----\n t/t9500-gitweb-standalone-no-errors.sh |   28 ++++++++++++++++++++++++++++\n 2 files changed, 40 insertions(+), 5 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex b381692..668be42 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -436,12 +436,11 @@ my %allowed_options = (\n \n our @extra_options = $cgi->param('opt');\n if (defined @extra_options) {\n-\tforeach(@extra_options)\n-\t{\n-\t\tif (not grep(/^$_$/, keys %allowed_options)) {\n+\tforeach my $opt (@extra_options) {\n+\t\tif (not exists $allowed_options{$opt}) {\n \t\t\tdie_error(undef, \"Invalid option parameter\");\n \t\t}\n-\t\tif (not grep(/^$action$/, @{$allowed_options{$_}})) {\n+\t\tif (not grep(/^$action$/, @{$allowed_options{$opt}})) {\n \t\t\tdie_error(undef, \"Invalid option parameter for this action\");\n \t\t}\n \t}\n@@ -598,7 +597,6 @@ sub href(%) {\n \t\taction => \"a\",\n \t\tfile_name => \"f\",\n \t\tfile_parent => \"fp\",\n-\t\textra_options => \"opt\",\n \t\thash => \"h\",\n \t\thash_parent => \"hp\",\n \t\thash_base => \"hb\",\n@@ -608,6 +606,7 @@ sub href(%) {\n \t\tsearchtext => \"s\",\n \t\tsearchtype => \"st\",\n \t\tsnapshot_format => \"sf\",\n+\t\textra_options => \"opt\",\n \t);\n \tmy %mapping = @mapping;\n \n@@ -2267,9 +2266,17 @@ EOF\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} else {\n \t\tprintf('<link rel=\"alternate\" title=\"%s projects list\" '.\n \t\t       'href=\"%s\" type=\"text/plain; charset=utf-8\"/>'.\"\\n\",\ndiff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh\nindex d948724..fa32598 100755\n--- a/t/t9500-gitweb-standalone-no-errors.sh\n+++ b/t/t9500-gitweb-standalone-no-errors.sh\n@@ -521,4 +521,32 @@ test_expect_success \\\n \t'gitweb_run \"p=.git;a=log\"'\n test_debug 'cat gitweb.log'\n \n+# ----------------------------------------------------------------------\n+# extra options\n+\n+test_expect_success \\\n+\t'opt: log --no-merges' \\\n+\t'gitweb_run \"p=.git;a=log;opt=--no-merges\"'\n+test_debug 'cat gitweb.log'\n+\n+test_expect_success \\\n+\t'opt: atom --no-merges' \\\n+\t'gitweb_run \"p=.git;a=log;opt=--no-merges\"'\n+test_debug 'cat gitweb.log'\n+\n+test_expect_success \\\n+\t'opt: \"file\" history --no-merges' \\\n+\t'gitweb_run \"p=.git;a=history;f=file;opt=--no-merges\"'\n+test_debug 'cat gitweb.log'\n+\n+test_expect_success \\\n+\t'opt: log --no-such-option (invalid option)' \\\n+\t'gitweb_run \"p=.git;a=log;opt=--no-such-option\"'\n+test_debug 'cat gitweb.log'\n+\n+test_expect_success \\\n+\t'opt: tree --no-merges (invalid option for action)' \\\n+\t'gitweb_run \"p=.git;a=tree;opt=--no-merges\"'\n+test_debug 'cat gitweb.log'\n+\n test_done\n-- \n1.5.2.4\n"},{"id":"48946","messageId":"7vhcnonfoc.fsf@assigned-by-dhcp.cox.net","threadId":"9276","inReplyTo":"11856328582066-git-send-email-jnareb@gmail.com","subject":"Re: [PATCH] gitweb: Simplify 'opt' parameter validation, add \"no merges\" feeds","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-29T01:48:19Z","receivedAt":"2007-07-29T01:48:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This and the submodule stuff look good.  Thanks.\n\nApplied.\n"}]}