git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: Luben Tuikov <ltuikov@yahoo.com>, Petr Baudis <pasky@suse.cz>,
	Jakub Narebski <jnareb@gmail.com>
Subject: [PATCH] gitweb: Simplify 'opt' parameter validation, add "no merges" feeds
Date: Sat, 28 Jul 2007 16:27:32 +0200	[thread overview]
Message-ID: <11856328582066-git-send-email-jnareb@gmail.com> (raw)

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>
---
This patch could (and probablu should) be split into four separate
patches: simplify 'opt' parameter validation, move 'opt' parameter
to be last in the generated URL, add tests for 'opt' parameter, and
add an example of using 'opt' parameter in the form of feeds without
merges.  But I wanted to avoid generating micro-commits.

This patch is based on 'master'.

 gitweb/gitweb.perl                     |   17 ++++++++++++-----
 t/t9500-gitweb-standalone-no-errors.sh |   28 ++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index b381692..668be42 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -436,12 +436,11 @@ my %allowed_options = (
 
 our @extra_options = $cgi->param('opt');
 if (defined @extra_options) {
-	foreach(@extra_options)
-	{
-		if (not grep(/^$_$/, keys %allowed_options)) {
+	foreach my $opt (@extra_options) {
+		if (not exists $allowed_options{$opt}) {
 			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");
 		}
 	}
@@ -598,7 +597,6 @@ sub href(%) {
 		action => "a",
 		file_name => "f",
 		file_parent => "fp",
-		extra_options => "opt",
 		hash => "h",
 		hash_parent => "hp",
 		hash_base => "hb",
@@ -608,6 +606,7 @@ sub href(%) {
 		searchtext => "s",
 		searchtype => "st",
 		snapshot_format => "sf",
+		extra_options => "opt",
 	);
 	my %mapping = @mapping;
 
@@ -2267,9 +2266,17 @@ EOF
 		printf('<link rel="alternate" title="%s log RSS feed" '.
 		       'href="%s" type="application/rss+xml" />'."\n",
 		       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" '.
 		       'href="%s" type="application/atom+xml" />'."\n",
 		       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 {
 		printf('<link rel="alternate" title="%s projects list" '.
 		       'href="%s" type="text/plain; charset=utf-8"/>'."\n",
diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh
index d948724..fa32598 100755
--- a/t/t9500-gitweb-standalone-no-errors.sh
+++ b/t/t9500-gitweb-standalone-no-errors.sh
@@ -521,4 +521,32 @@ test_expect_success \
 	'gitweb_run "p=.git;a=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
-- 
1.5.2.4

             reply	other threads:[~2007-07-28 14:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-28 14:27 Jakub Narebski [this message]
2007-07-29  1:48 ` [PATCH] gitweb: Simplify 'opt' parameter validation, add "no merges" feeds Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11856328582066-git-send-email-jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=ltuikov@yahoo.com \
    --cc=pasky@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).