From: "Marcel M. Cary" <marcel@oak.homeunix.org>
To: Jakub Narebski <jnareb@gmail.com>, git@vger.kernel.org
Cc: Petr Baudis <pasky@suse.cz>,
Giuseppe Bilotta <giuseppe.bilotta@gmail.com>,
Francis Galiegue <fge@one2team.net>,
"Marcel M. Cary" <marcel@oak.homeunix.org>
Subject: [RFC PATCH 3/6] gitweb: Allow finer-grained override controls for committags
Date: Tue, 17 Nov 2009 22:22:27 -0800 [thread overview]
Message-ID: <1258525350-5528-4-git-send-email-marcel@oak.homeunix.org> (raw)
In-Reply-To: <1258525350-5528-3-git-send-email-marcel@oak.homeunix.org>
Currently, a site administrator must choose between allowing all or
none of a committag's options to be overridden in the project config.
However, a site admin may wish to permit specifying a bugzilla URL
without risking a maliciously resource hungry regular expression.
Allow the site admin to specify which committag parameters may be
overridden. Preserve the behavior of the original 0 and 1 override
specifications.
Signed-off-by: Marcel M. Cary <marcel@oak.homeunix.org>
---
gitweb/INSTALL | 8 +++++++-
gitweb/gitweb.perl | 24 ++++++++++++++++++------
t/t9502-gitweb-committags.sh | 13 +++++++++++++
3 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/gitweb/INSTALL b/gitweb/INSTALL
index 9081ed8..15c0128 100644
--- a/gitweb/INSTALL
+++ b/gitweb/INSTALL
@@ -133,9 +133,15 @@ adding the following lines to your $GITWEB_CONFIG:
$known_snapshot_formats{'tgz'}{'compressor'} = ['gzip','-6'];
To add a committag to the default list of commit tags, for example to
-enable hyperlinking of bug numbers to a bug tracker for all projects:
+enable hyperlinking of bug numbers to a bug tracker for all projects, while
+allowing each project to choose only the base URL for its bug tracker:
push @{$feature{'committags'}{'default'}}, 'bugzilla';
+ $committags{"bugzilla"}{"override"} = ["url"];
+
+And then let each project configure its bug tracker URL:
+
+ git config gitweb.committag.bugzilla.url 'http://bts.example.com?bug='
Gitweb repositories
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 032b1c5..8f4480e 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -225,11 +225,13 @@ our %avatar_size = (
# will not be processed further.
#
# For any committag, set the 'override' key to 1 to allow individual
-# projects to override entries in the 'options' hash for that tag.
-# For example, to match only commit hashes given in lowercase in one
-# project, add this to the $GITWEB_CONFIG:
+# projects to override any entry in the 'options' hash for that tag.
+# Leave 'override' as 0 to disallow all overriding of all entries.
+# Set 'override' to an array of 'option' key names to allow overriding
+# specific keys. For example, to match only commit hashes given in
+# lowercase in one project, add this to the $GITWEB_CONFIG:
#
-# $committags{'sha1'}{'override'} = 1;
+# $committags{'sha1'}{'override'} = 1; # or ["pattern"]
#
# And in the project's config:
#
@@ -237,7 +239,8 @@ our %avatar_size = (
#
# Some committags have additional options whose interpretation depends
# on the implementation of the 'sub' key. The hyperlink_committag
-# value appends the first captured group to the 'url' option.
+# value appends the first captured group to the 'url' option, for example.
+#
our %committags = (
# Link Git-style hashes to this gitweb
'sha1' => {
@@ -1029,8 +1032,17 @@ sub gitweb_load_project_committags {
$project_config{$ctname}{$option} = $raw_config{$key};
}
foreach my $ctname (keys(%committags)) {
- next if (!$committags{$ctname}{'override'});
+ my $override = $committags{$ctname}{'override'};
+ next if (!$override);
+ my $override_keys = undef;
+ if (ref($override) eq "ARRAY") {
+ $override_keys = {};
+ foreach my $optname (@$override) {
+ $override_keys->{$optname} = 1;
+ }
+ }
foreach my $optname (keys %{$project_config{$ctname}}) {
+ next if ($override_keys && !$override_keys->{$optname});
$committags{$ctname}{'options'}{$optname} =
$project_config{$ctname}{$optname};
}
diff --git a/t/t9502-gitweb-committags.sh b/t/t9502-gitweb-committags.sh
index 718e763..e13ac47 100755
--- a/t/t9502-gitweb-committags.sh
+++ b/t/t9502-gitweb-committags.sh
@@ -68,6 +68,19 @@ test_expect_success 'bugzilla: url overridden but not permitted' '
test_debug 'cat gitweb.log'
test_debug 'grep 1234 gitweb.output'
+echo '$committags{"bugzilla"}{"override"} = ["url"];' >> gitweb_config.perl
+git config gitweb.committag.bugzilla.url 'http://bts.example.com?bug='
+git config gitweb.committag.bugzilla.pattern 'slow DoS regex'
+test_expect_success 'bugzilla: url overridden but regex not permitted' '
+ gitweb_run "p=.git;a=commit;h=HEAD" &&
+ grep -F -q \
+ "Fixes bug <a class=\"text\" href=\"http://bts.example.com?bug=1234\">1234</a> involving" \
+ gitweb.output
+'
+test_debug 'cat gitweb.log'
+test_debug 'grep 1234 gitweb.output'
+git config --unset gitweb.committag.bugzilla.pattern
+
echo '$committags{"bugzilla"}{"override"} = 1;' >> gitweb_config.perl
test_expect_success 'bugzilla: url overridden' '
gitweb_run "p=.git;a=commit;h=HEAD" &&
--
1.6.4.4
next prev parent reply other threads:[~2009-11-18 6:23 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-08 19:07 [RFC] Configuring (future) committags support in gitweb Jakub Narebski
2008-11-08 20:02 ` Francis Galiegue
2008-11-08 22:35 ` Jakub Narebski
2008-11-08 23:27 ` Francis Galiegue
2008-11-09 0:25 ` Jakub Narebski
2009-02-17 15:32 ` [RFC] Configuring (future) committags support in gitweb, especially bug linking Marcel M. Cary
2009-02-18 3:00 ` [PATCH RFC 1/2] gitweb: Fix warnings with override permitted but no repo override Marcel M. Cary
2009-02-18 7:41 ` Giuseppe Bilotta
2009-02-18 8:40 ` Junio C Hamano
2009-02-18 13:09 ` Jakub Narebski
2009-02-18 19:02 ` Junio C Hamano
2009-02-18 3:00 ` [PATCH RFC 2/2] gitweb: Hyperlink multiple git hashes on the same commit message line Marcel M. Cary
2009-02-18 21:55 ` Jakub Narebski
2009-02-20 8:35 ` Junio C Hamano
2009-02-20 11:46 ` Jakub Narebski
2009-02-24 15:38 ` Addresses with full names in patch emails Marcel M. Cary
2009-02-24 15:58 ` Jakub Narebski
2009-02-24 16:33 ` [PATCH RFC 2/2] gitweb: Hyperlink multiple git hashes on the same commit message line Marcel M. Cary
2009-02-18 3:38 ` [RFC] Configuring (future) committags support in gitweb, especially bug linking Jakub Narebski
2009-02-19 17:08 ` Marcel M. Cary
2009-06-19 14:13 ` [RFC PATCH 1/2] gitweb: Hyperlink various committags in commit message with regex Marcel M. Cary
2009-06-22 11:18 ` Jakub Narebski
2009-11-18 6:22 ` [RFC PATCH 0/6] Second round of committag series Marcel M. Cary
2009-11-18 6:22 ` [RFC PATCH 1/6] gitweb: Hyperlink committags in a commit message by regex matching Marcel M. Cary
2009-11-18 6:22 ` [RFC PATCH 2/6] gitweb: Add second-stage matching of bug IDs in bugzilla committag Marcel M. Cary
2009-11-18 6:22 ` Marcel M. Cary [this message]
2009-11-18 6:22 ` [RFC PATCH 4/6] gitweb: Allow committag pattern matches to span multiple lines Marcel M. Cary
2009-11-18 6:22 ` [RFC PATCH 5/6] gitweb: Allow per-repository definition of new committags Marcel M. Cary
2009-11-18 6:22 ` [RFC PATCH 6/6] gitweb: Add _defaults_ keyword for feature lists in project config Marcel M. Cary
2009-11-18 8:20 ` [RFC PATCH 1/6] gitweb: Hyperlink committags in a commit message by regex matching Petr Baudis
2009-11-18 8:26 ` Petr Baudis
2009-11-20 23:24 ` [RFC PATCH 0/6] Second round of committag series Jakub Narebski
2009-06-19 14:13 ` [RFC PATCH 2/2] gitweb: Add second-stage matching of bug IDs in bugzilla committag Marcel M. Cary
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=1258525350-5528-4-git-send-email-marcel@oak.homeunix.org \
--to=marcel@oak.homeunix.org \
--cc=fge@one2team.net \
--cc=git@vger.kernel.org \
--cc=giuseppe.bilotta@gmail.com \
--cc=jnareb@gmail.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).