Skip to content

Commit f4a8102

Browse files
mkiedrowiczgitster
authored andcommitted
gitweb: Push formatting diff lines to print_diff_chunk()
Now lines are formatted closer to place where we actually use HTML formatted output. This means that we put raw lines in the @chunk accumulator, rather than formatted lines. Because we still need to know class (type) of line when accumulating data to post-process and print, process_diff_line() subroutine was retired and replaced by diff_line_class() used in git_patchset_body() and new restructured format_diff_line() used in print_diff_chunk(). As a side effect, we have to pass \%from and \%to down to callstack. This is a preparation patch for diff refinement highlightning. It's not meant to change gitweb output. [jn: wrote commit message] Signed-off-by: Michał Kiedrowicz <[email protected]> Acked-by: Jakub Narębski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 44185f9 commit f4a8102

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

gitweb/gitweb.perl

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,26 +2430,26 @@ sub format_cc_diff_chunk_header {
24302430
}
24312431

24322432
# process patch (diff) line (not to be used for diff headers),
2433-
# returning class and HTML-formatted (but not wrapped) line
2434-
sub process_diff_line {
2435-
my $line = shift;
2436-
my ($from, $to) = @_;
2437-
2438-
my $diff_class = diff_line_class($line, $from, $to);
2433+
# returning HTML-formatted (but not wrapped) line
2434+
sub format_diff_line {
2435+
my ($line, $diff_class, $from, $to) = @_;
24392436

24402437
chomp $line;
24412438
$line = untabify($line);
24422439

24432440
if ($from && $to && $line =~ m/^\@{2} /) {
24442441
$line = format_unidiff_chunk_header($line, $from, $to);
2445-
return $diff_class, $line;
2446-
24472442
} elsif ($from && $to && $line =~ m/^\@{3}/) {
24482443
$line = format_cc_diff_chunk_header($line, $from, $to);
2449-
return $diff_class, $line;
2450-
2444+
} else {
2445+
$line = esc_html($line, -nbsp=>1);
24512446
}
2452-
return $diff_class, esc_html($line, -nbsp=>1);
2447+
2448+
my $diff_classes = "diff";
2449+
$diff_classes .= " $diff_class" if ($diff_class);
2450+
$line = "<div class=\"$diff_classes\">$line</div>\n";
2451+
2452+
return $line;
24532453
}
24542454

24552455
# Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
@@ -5068,7 +5068,7 @@ sub print_diff_lines {
50685068
}
50695069

50705070
sub print_diff_chunk {
5071-
my ($diff_style, $is_combined, @chunk) = @_;
5071+
my ($diff_style, $is_combined, $from, $to, @chunk) = @_;
50725072
my (@ctx, @rem, @add);
50735073

50745074
# The class of the previous line.
@@ -5090,6 +5090,8 @@ sub print_diff_chunk {
50905090
foreach my $line_info (@chunk) {
50915091
my ($class, $line) = @$line_info;
50925092

5093+
$line = format_diff_line($line, $class, $from, $to);
5094+
50935095
# print chunk headers
50945096
if ($class && $class eq 'chunk_header') {
50955097
print $line;
@@ -5243,22 +5245,19 @@ sub git_patchset_body {
52435245

52445246
next PATCH if ($patch_line =~ m/^diff /);
52455247

5246-
my ($class, $line) = process_diff_line($patch_line, \%from, \%to);
5247-
my $diff_classes = "diff";
5248-
$diff_classes .= " $class" if ($class);
5249-
$line = "<div class=\"$diff_classes\">$line</div>\n";
5248+
my $class = diff_line_class($patch_line, \%from, \%to);
52505249

52515250
if ($class eq 'chunk_header') {
5252-
print_diff_chunk($diff_style, $is_combined, @chunk);
5251+
print_diff_chunk($diff_style, $is_combined, \%from, \%to, @chunk);
52535252
@chunk = ();
52545253
}
52555254

5256-
push @chunk, [ $class, $line ];
5255+
push @chunk, [ $class, $patch_line ];
52575256
}
52585257

52595258
} continue {
52605259
if (@chunk) {
5261-
print_diff_chunk($diff_style, $is_combined, @chunk);
5260+
print_diff_chunk($diff_style, $is_combined, \%from, \%to, @chunk);
52625261
@chunk = ();
52635262
}
52645263
print "</div>\n"; # class="patch"

0 commit comments

Comments
 (0)