gitweb: Simplify 'opt' parameter validation, add "no merges" feeds
Simplify and make more readable validation of 'opt' (extra options)
parameter, using exists($hash{key}) instead of grepping keys of a hash
for value.
Move 'opt' parameter to be the last (for now) in the URL.
Make use of '--no-merges' extra option ('opt') by adding "no merges"
RSS and Atom feeds to the HTML header. Note that alternate format
links in the RSS and Atom views do not use '--no-merges' option yet!
Adds tests for the 'opt' parameter to t9500-gitweb-standalone-no-errors.sh
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
01ac1e38db
commit
12075103dd
@ -436,12 +436,11 @@ my %allowed_options = (
|
|||||||
|
|
||||||
our @extra_options = $cgi->param('opt');
|
our @extra_options = $cgi->param('opt');
|
||||||
if (defined @extra_options) {
|
if (defined @extra_options) {
|
||||||
foreach(@extra_options)
|
foreach my $opt (@extra_options) {
|
||||||
{
|
if (not exists $allowed_options{$opt}) {
|
||||||
if (not grep(/^$_$/, keys %allowed_options)) {
|
|
||||||
die_error(undef, "Invalid option parameter");
|
die_error(undef, "Invalid option parameter");
|
||||||
}
|
}
|
||||||
if (not grep(/^$action$/, @{$allowed_options{$_}})) {
|
if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
|
||||||
die_error(undef, "Invalid option parameter for this action");
|
die_error(undef, "Invalid option parameter for this action");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -598,7 +597,6 @@ sub href(%) {
|
|||||||
action => "a",
|
action => "a",
|
||||||
file_name => "f",
|
file_name => "f",
|
||||||
file_parent => "fp",
|
file_parent => "fp",
|
||||||
extra_options => "opt",
|
|
||||||
hash => "h",
|
hash => "h",
|
||||||
hash_parent => "hp",
|
hash_parent => "hp",
|
||||||
hash_base => "hb",
|
hash_base => "hb",
|
||||||
@ -608,6 +606,7 @@ sub href(%) {
|
|||||||
searchtext => "s",
|
searchtext => "s",
|
||||||
searchtype => "st",
|
searchtype => "st",
|
||||||
snapshot_format => "sf",
|
snapshot_format => "sf",
|
||||||
|
extra_options => "opt",
|
||||||
);
|
);
|
||||||
my %mapping = @mapping;
|
my %mapping = @mapping;
|
||||||
|
|
||||||
@ -2285,9 +2284,17 @@ EOF
|
|||||||
printf('<link rel="alternate" title="%s log RSS feed" '.
|
printf('<link rel="alternate" title="%s log RSS feed" '.
|
||||||
'href="%s" type="application/rss+xml" />'."\n",
|
'href="%s" type="application/rss+xml" />'."\n",
|
||||||
esc_param($project), href(action=>"rss"));
|
esc_param($project), href(action=>"rss"));
|
||||||
|
printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
|
||||||
|
'href="%s" type="application/rss+xml" />'."\n",
|
||||||
|
esc_param($project), href(action=>"rss",
|
||||||
|
extra_options=>"--no-merges"));
|
||||||
printf('<link rel="alternate" title="%s log Atom feed" '.
|
printf('<link rel="alternate" title="%s log Atom feed" '.
|
||||||
'href="%s" type="application/atom+xml" />'."\n",
|
'href="%s" type="application/atom+xml" />'."\n",
|
||||||
esc_param($project), href(action=>"atom"));
|
esc_param($project), href(action=>"atom"));
|
||||||
|
printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
|
||||||
|
'href="%s" type="application/atom+xml" />'."\n",
|
||||||
|
esc_param($project), href(action=>"atom",
|
||||||
|
extra_options=>"--no-merges"));
|
||||||
} else {
|
} else {
|
||||||
printf('<link rel="alternate" title="%s projects list" '.
|
printf('<link rel="alternate" title="%s projects list" '.
|
||||||
'href="%s" type="text/plain; charset=utf-8"/>'."\n",
|
'href="%s" type="text/plain; charset=utf-8"/>'."\n",
|
||||||
|
|||||||
@ -521,4 +521,32 @@ test_expect_success \
|
|||||||
'gitweb_run "p=.git;a=log"'
|
'gitweb_run "p=.git;a=log"'
|
||||||
test_debug 'cat gitweb.log'
|
test_debug 'cat gitweb.log'
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
# extra options
|
||||||
|
|
||||||
|
test_expect_success \
|
||||||
|
'opt: log --no-merges' \
|
||||||
|
'gitweb_run "p=.git;a=log;opt=--no-merges"'
|
||||||
|
test_debug 'cat gitweb.log'
|
||||||
|
|
||||||
|
test_expect_success \
|
||||||
|
'opt: atom --no-merges' \
|
||||||
|
'gitweb_run "p=.git;a=log;opt=--no-merges"'
|
||||||
|
test_debug 'cat gitweb.log'
|
||||||
|
|
||||||
|
test_expect_success \
|
||||||
|
'opt: "file" history --no-merges' \
|
||||||
|
'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"'
|
||||||
|
test_debug 'cat gitweb.log'
|
||||||
|
|
||||||
|
test_expect_success \
|
||||||
|
'opt: log --no-such-option (invalid option)' \
|
||||||
|
'gitweb_run "p=.git;a=log;opt=--no-such-option"'
|
||||||
|
test_debug 'cat gitweb.log'
|
||||||
|
|
||||||
|
test_expect_success \
|
||||||
|
'opt: tree --no-merges (invalid option for action)' \
|
||||||
|
'gitweb_run "p=.git;a=tree;opt=--no-merges"'
|
||||||
|
test_debug 'cat gitweb.log'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|||||||
Reference in New Issue
Block a user