Now we're ready to insert highlightning to diff output. The call to untabify() remains in the main loop in print_diff_chunk(). The motivation is that it must be called before any call to esc_html() (because that converts spaces to ) and to call it only once. This is a refactoring patch. It's not meant to change gitweb output. Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@xxxxxxxxx> --- gitweb/gitweb.perl | 42 +++++++++++++++++++++++++++++++----------- 1 files changed, 31 insertions(+), 11 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index cae9dfa..db61553 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -2319,13 +2319,22 @@ sub format_cc_diff_chunk_header { return $line; } -# process patch (diff) line (not to be used for diff headers), -# returning HTML-formatted (but not wrapped) line +# wrap patch (diff) line into a <div> (not to be used for diff headers), +# the line must be esc_html()'ed sub format_diff_line { my ($line, $diff_class, $from, $to) = @_; - chomp $line; - $line = untabify($line); + my $diff_classes = "diff"; + $diff_classes .= " $diff_class" if ($diff_class); + $line = "<div class=\"$diff_classes\">$line</div>\n"; + + return $line; +} + +# format diff chunk header line (not to be used for diff headers), +# returning HTML-formatted line +sub format_diff_chunk_header { + my ($line, $diff_class, $from, $to) = @_; if ($from && $to && $line =~ m/^\@{2} /) { $line = format_unidiff_chunk_header($line, $from, $to); @@ -2336,11 +2345,7 @@ sub format_diff_line { $line = esc_html($line, -nbsp=>1); } - my $diff_classes = "diff"; - $diff_classes .= " $diff_class" if ($diff_class); - $line = "<div class=\"$diff_classes\">$line</div>\n"; - - return $line; + return format_diff_line($line, $diff_class); } # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)", @@ -4918,10 +4923,24 @@ sub print_inline_diff_lines { print foreach (@$add); } +# HTML-format diff context, removed and added lines. +sub format_ctx_rem_add_lines { + my ($ctx, $rem, $add) = @_; + my (@new_ctx, @new_rem, @new_add); + + @new_ctx = map { format_diff_line(esc_html($_, -nbsp=>1), 'ctx') } @$ctx; + @new_rem = map { format_diff_line(esc_html($_, -nbsp=>1), 'rem') } @$rem; + @new_add = map { format_diff_line(esc_html($_, -nbsp=>1), 'add') } @$add; + + return (\@new_ctx, \@new_rem, \@new_add); +} + # Print context lines and then rem/add lines. sub print_diff_lines { my ($ctx, $rem, $add, $diff_style, $is_combined) = @_; + ($ctx, $rem, $add) = format_ctx_rem_add_lines($ctx, $rem, $add); + if ($diff_style eq 'sidebyside' && !$is_combined) { print_sidebyside_diff_lines($ctx, $rem, $add); } else { @@ -4951,11 +4970,12 @@ sub print_diff_chunk { foreach my $line_info (@chunk) { my ($class, $line) = @$line_info; - $line = format_diff_line($line, $class, $from, $to); + $line = untabify($line); # print chunk headers if ($class && $class eq 'chunk_header') { - print $line; + print format_diff_chunk_header($line, $class, $from, + $to); next; } -- 1.7.3.4 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html