From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: John 'Warthog9' Hawley <warthog9@kernel.org>,
admin@repo.or.cz, Petr Baudis <pasky@ucw.cz>
Subject: [PATCH/RFC 7/6] gitweb: Use esc_html_match_hl in 'grep' search
Date: Sat, 30 Jul 2011 16:57:47 +0200 [thread overview]
Message-ID: <201107301657.48678.jnareb@gmail.com> (raw)
In-Reply-To: <1311940379-9608-1-git-send-email-jnareb@gmail.com>
Use newly introduced esc_html_match_hl() subroutine in
git_search_files() ('grep' search), instead of handcrafted code using
captures, which highlighted only first match in line.
This required to enhance esc_html_match_hl() to be able to pass-thru
options for esc_html like -nbsp=>1.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Note: because untabify() is run before match, some regexp might not
show match; this is not regression, because earlier versions had the
same behavior.
Code is shorter, and behavior is improved.
gitweb/gitweb.perl | 22 +++++++---------------
1 files changed, 7 insertions(+), 15 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 6bc68c5..d489640 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1692,24 +1692,24 @@ sub chop_and_escape_str {
# highlight match (if any), and escape HTML
sub esc_html_match_hl {
- my ($str, $regexp) = @_;
- return esc_html($str) unless defined $regexp;
+ my ($str, $regexp, @opts) = @_;
+ return esc_html($str, @opts) unless defined $regexp;
my @matches;
while ($str =~ /$regexp/g) {
push @matches, [$-[0], $+[0]];
}
- return esc_html($str) unless @matches;
+ return esc_html($str, @opts) unless @matches;
my $out = '';
my $pos = 0;
for my $m (@matches) {
- $out .= esc_html(substr $str, $pos, $m->[0] - $pos);
+ $out .= esc_html(substr($str, $pos, $m->[0] - $pos), @opts);
$out .= $cgi->span({-class => 'match'},
- esc_html(substr $str, $m->[0], $m->[1] -
$m->[0]));
+ esc_html(substr($str, $m->[0], $m->[1] - $m->[0]),
@opts));
$pos = $m->[1];
}
- $out .= esc_html(substr $str, $pos);
+ $out .= esc_html(substr($str, $pos), @opts);
return $out;
}
@@ -5796,15 +5796,7 @@ sub git_search_files {
print "<div class=\"binary\">Binary file</div>\n";
} else {
$ltext = untabify($ltext);
- if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
- $ltext = esc_html($1, -nbsp=>1);
- $ltext .= '<span class="match">';
- $ltext .= esc_html($2, -nbsp=>1);
- $ltext .= '</span>';
- $ltext .= esc_html($3, -nbsp=>1);
- } else {
- $ltext = esc_html($ltext, -nbsp=>1);
- }
+ esc_html_match_hl($ltext, $search_regexp, -nbsp => 1);
print "<div class=\"pre\">" .
$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
file_name=>"$file").'#l'.$lno,
--
1.7.5
prev parent reply other threads:[~2011-07-30 14:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-29 11:52 [PATCH/RFC 0/6] gitweb: Improve project search Jakub Narebski
2011-07-29 11:52 ` [PATCH/RFC 1/6] gitweb: Allow underscore in $searchtype ('st') Jakub Narebski
2011-07-29 11:52 ` [PATCH/RFC 2/6] gitweb: Improve projects search form Jakub Narebski
2011-07-29 11:52 ` [PATCH/RFC 3/6] gitweb: Option for filling only specified info in fill_project_list_info Jakub Narebski
2011-07-29 11:52 ` [PATCH/RFC 4/6] gitweb: Faster project search Jakub Narebski
2011-07-29 11:52 ` [PATCH/RFC 5/6] gitweb: Highlight matched part of project name when searching projects Jakub Narebski
2011-07-29 11:52 ` [RFC/PATCH 6/6] gitweb: Highlight matched part of project description " Jakub Narebski
2011-07-30 14:57 ` Jakub Narebski [this message]
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=201107301657.48678.jnareb@gmail.com \
--to=jnareb@gmail.com \
--cc=admin@repo.or.cz \
--cc=git@vger.kernel.org \
--cc=pasky@ucw.cz \
--cc=warthog9@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.