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 4/6] gitweb: Allow committag pattern matches to span multiple lines
Date: Tue, 17 Nov 2009 22:22:28 -0800 [thread overview]
Message-ID: <1258525350-5528-5-git-send-email-marcel@oak.homeunix.org> (raw)
In-Reply-To: <1258525350-5528-4-git-send-email-marcel@oak.homeunix.org>
Committags cannot currently span multiple lines. Since some committag
patterns match multiple words. If some of those words wrap to the
next line, the committag would miss an opportunity to match.
Eliminate the for-loop over @log and pull the signoff transformation
from that loop into a committag.
The message will still get cut into pieces as committags are applied,
but at least newlines no longer force a cut.
Signed-off-by: Marcel M. Cary <marcel@oak.homeunix.org>
---
gitweb/gitweb.perl | 67 +++++++++++++++++++-----------------------
t/t9502-gitweb-committags.sh | 8 +++++
2 files changed, 38 insertions(+), 37 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 8f4480e..7f7d3a3 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -255,6 +255,21 @@ our %committags = (
esc_html($match[0], -nbsp=>1));
},
},
+ # Facilitate styling of common header/footer lines, suppressing
+ # any trailing newlines
+ 'signoff' => {
+ 'options' => {
+ 'pattern' =>
+ qr/^( *(?:signed[ \-]off[ \-]by|acked[ \-]by|cc)[ :].*)\n*$/mi,
+ },
+ 'override' => 0,
+ 'sub' => sub {
+ my ($opts, @match) = @_;
+ return (\$cgi->span({'class' => 'signoff'},
+ esc_html($match[1], -nbsp=>1)),
+ "\n");
+ },
+ },
# Link bug/features to Mantis bug tracker using Mantis-style
# contextual cues
'mantis' => {
@@ -542,7 +557,7 @@ our %feature = (
'committags' => {
'sub' => sub { feature_list('committags', @_) },
'override' => 0,
- 'default' => ['sha1']},
+ 'default' => ['signoff', 'sha1']},
);
sub gitweb_get_feature {
@@ -1619,8 +1634,8 @@ sub file_type_long {
## which don't belong to other sections
# format line of commit message.
-sub format_log_line_html {
- my $line = shift;
+sub format_log_html {
+ my $text = shift;
# Merge project configs with site default committag definitions if
# it hasn't been done yet
@@ -1629,7 +1644,7 @@ sub format_log_line_html {
# In this list of log message fragments, a string ref indicates
# HTML, and a string indicates plain text. The string refs are
# also currently not processed by subsequent committags.
- my @message_fragments = ( $line );
+ my @message_fragments = ( $text );
COMMITTAG:
foreach my $ctname (@committags) {
@@ -1671,7 +1686,9 @@ COMMITTAG:
if (ref($fragment)) {
$html .= $$fragment;
} else {
- $html .= esc_html($fragment, -nbsp=>1);
+ # Don't let esc_html turn "\n" into "\\n"
+ $html .= join("<br/>\n", map { esc_html($_, -nbsp=>1) }
+ split("\n", $fragment, -1));
}
}
@@ -3776,40 +3793,16 @@ sub git_print_log {
shift @$log;
}
- # print log
- my $signoff = 0;
- my $empty = 0;
- foreach my $line (@$log) {
- if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
- $signoff = 1;
- $empty = 0;
- if (! $opts{'-remove_signoff'}) {
- print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
- next;
- } else {
- # remove signoff lines
- next;
- }
- } else {
- $signoff = 0;
- }
-
- # print only one empty line
- # do not print empty line after signoff
- if ($line eq "") {
- next if ($empty || $signoff);
- $empty = 1;
- } else {
- $empty = 0;
- }
-
- print format_log_line_html($line) . "<br/>\n";
- }
-
if ($opts{'-final_empty_line'}) {
- # end with single empty line
- print "<br/>\n" unless $empty;
+ # If we already have a trailing newline, this will be
+ # coalesced with it later.
+ push @$log, "";
}
+
+ # print log
+ my $text = join("\n", @$log) . "\n";
+ $text =~ s{\n\n+}{\n\n}g;
+ print format_log_html($text);
}
# return link target (what link points to)
diff --git a/t/t9502-gitweb-committags.sh b/t/t9502-gitweb-committags.sh
index e13ac47..0753630 100755
--- a/t/t9502-gitweb-committags.sh
+++ b/t/t9502-gitweb-committags.sh
@@ -138,6 +138,10 @@ Fix memory leak in confabulator from bug 123.
Based on history from bugs 223, 224, and 225,
fix bug 323 or 324.
+Bugs:
+1234,
+1235
+
Bug: 423,424,425,426,427,428,429,430,431,432,435
Resolves-bugs: #523 #524
END
@@ -167,6 +171,10 @@ test_expect_success 'bugzilla: fancy defaults: space-separated with hash' '
"-bugs: <a[^>]*>#523</a> <a[^>]*>#524</a>" \
gitweb.output
'
+test_expect_success 'bugzilla: fancy defaults: spanning newlines' '
+ grep -q -e "<a[^>]*>1234</a>,<br" gitweb.output &&
+ grep -q -e "<a[^>]*>1235</a><br" gitweb.output
+'
test_debug 'cat gitweb.log'
test_debug 'grep 23 gitweb.output'
--
1.6.4.4
next prev parent reply other threads:[~2009-11-18 6:29 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 ` [RFC PATCH 3/6] gitweb: Allow finer-grained override controls for committags Marcel M. Cary
2009-11-18 6:22 ` Marcel M. Cary [this message]
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-5-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).