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>
Jakub Narebski committed
Jul 28, 2007 at 16:27 UTC
12075103ddc9a061cf6f3b04feb206123bb78e2f
2 files changed
+40
-5
gitweb/gitweb.perl
+12
-5
@@ -436,12 +436,11 @@ my %allowed_options = (
436
437
our @extra_options = $cgi->param('opt');
438
if (defined @extra_options) {
439
- foreach(@extra_options)
440
- {
441
- if (not grep(/^$_$/, keys %allowed_options)) {
439
+ foreach my $opt (@extra_options) {
440
+ if (not exists $allowed_options{$opt}) {
441
die_error(undef, "Invalid option parameter");
442
}
444
- if (not grep(/^$action$/, @{$allowed_options{$_}})) {
443
+ if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
444
die_error(undef, "Invalid option parameter for this action");
445
}
446
}
@@ -598,7 +597,6 @@ sub href(%) {
597
action => "a",
598
file_name => "f",
599
file_parent => "fp",
601
- extra_options => "opt",
600
hash => "h",
601
hash_parent => "hp",
602
hash_base => "hb",
@@ -608,6 +606,7 @@ sub href(%) {
606
searchtext => "s",
607
searchtype => "st",
608
snapshot_format => "sf",
609
+ extra_options => "opt",
610
);
611
my %mapping = @mapping;
612
@@ -2285,9 +2284,17 @@ EOF
2284
printf('<link rel="alternate" title="%s log RSS feed" '.
2285
'href="%s" type="application/rss+xml" />'."\n",
2286
esc_param($project), href(action=>"rss"));
2287
+ printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2288
+ 'href="%s" type="application/rss+xml" />'."\n",
2289
+ esc_param($project), href(action=>"rss",
2290
+ extra_options=>"--no-merges"));
2291
printf('<link rel="alternate" title="%s log Atom feed" '.
2292
'href="%s" type="application/atom+xml" />'."\n",
2293
esc_param($project), href(action=>"atom"));
2294
+ printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2295
+ 'href="%s" type="application/atom+xml" />'."\n",
2296
+ esc_param($project), href(action=>"atom",
2297
+ extra_options=>"--no-merges"));
2298
} else {
2299
printf('<link rel="alternate" title="%s projects list" '.
2300
'href="%s" type="text/plain; charset=utf-8"/>'."\n",
t/t9500-gitweb-standalone-no-errors.sh
+28
@@ -521,4 +521,32 @@ test_expect_success \
521
'gitweb_run "p=.git;a=log"'
522
test_debug 'cat gitweb.log'
523
524
+# ----------------------------------------------------------------------
525
+# extra options
526
+
527
+test_expect_success \
528
+ 'opt: log --no-merges' \
529
+ 'gitweb_run "p=.git;a=log;opt=--no-merges"'
530
+test_debug 'cat gitweb.log'
531
+
532
+test_expect_success \
533
+ 'opt: atom --no-merges' \
534
+ 'gitweb_run "p=.git;a=log;opt=--no-merges"'
535
+test_debug 'cat gitweb.log'
536
+
537
+test_expect_success \
538
+ 'opt: "file" history --no-merges' \
539
+ 'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"'
540
+test_debug 'cat gitweb.log'
541
+
542
+test_expect_success \
543
+ 'opt: log --no-such-option (invalid option)' \
544
+ 'gitweb_run "p=.git;a=log;opt=--no-such-option"'
545
+test_debug 'cat gitweb.log'
546
+
547
+test_expect_success \
548
+ 'opt: tree --no-merges (invalid option for action)' \
549
+ 'gitweb_run "p=.git;a=tree;opt=--no-merges"'
550
+test_debug 'cat gitweb.log'
551
+
552
test_done