X-Git-Url: https://git.ladys.computer/Gitweb/blobdiff_plain/32be0fe6462f8e3186fbb2a3e5f3b10189d47cde1dd79a51ade9622241a8e6a4..a2a9fe5a6916fd20cd2a18e0eb8e663b14a1db26474d7a57aac40860faecfbbe:/gitweb.perl
diff --git a/gitweb.perl b/gitweb.perl
index 144b968..1829f56 100755
--- a/gitweb.perl
+++ b/gitweb.perl
@@ -1733,20 +1733,29 @@ sub chop_and_escape_str {
# 'foobar'
sub esc_html_hl_regions {
my ($str, $css_class, @sel) = @_;
- return esc_html($str) unless @sel;
+ my %opts = grep { ref($_) ne 'ARRAY' } @sel;
+ @sel = grep { ref($_) eq 'ARRAY' } @sel;
+ return esc_html($str, %opts) unless @sel;
my $out = '';
my $pos = 0;
for my $s (@sel) {
- $out .= esc_html(substr($str, $pos, $s->[0] - $pos))
- if ($s->[0] - $pos > 0);
- $out .= $cgi->span({-class => $css_class},
- esc_html(substr($str, $s->[0], $s->[1] - $s->[0])));
+ my ($begin, $end) = @$s;
- $pos = $s->[1];
+ # Don't create empty elements.
+ next if $end <= $begin;
+
+ my $escaped = esc_html(substr($str, $begin, $end - $begin),
+ %opts);
+
+ $out .= esc_html(substr($str, $pos, $begin - $pos), %opts)
+ if ($begin - $pos > 0);
+ $out .= $cgi->span({-class => $css_class}, $escaped);
+
+ $pos = $end;
}
- $out .= esc_html(substr($str, $pos))
+ $out .= esc_html(substr($str, $pos), %opts)
if ($pos < length($str));
return $out;
@@ -4995,6 +5004,52 @@ sub git_difftree_body {
print "\n";
}
+# Print context lines and then rem/add lines in a side-by-side manner.
+sub print_sidebyside_diff_lines {
+ my ($ctx, $rem, $add) = @_;
+
+ # print context block before add/rem block
+ if (@$ctx) {
+ print join '',
+ '',
+ '
',
+ @$ctx,
+ '
',
+ '
',
+ @$ctx,
+ '
',
+ '
';
+ }
+
+ if (!@$add) {
+ # pure removal
+ print join '',
+ '',
+ '
',
+ @$rem,
+ '
',
+ '
';
+ } elsif (!@$rem) {
+ # pure addition
+ print join '',
+ '',
+ '
',
+ @$add,
+ '
',
+ '
';
+ } else {
+ print join '',
+ '',
+ '
',
+ @$rem,
+ '
',
+ '
',
+ @$add,
+ '
',
+ '
';
+ }
+}
+
sub print_sidebyside_diff_chunk {
my @chunk = @_;
my (@ctx, @rem, @add);
@@ -5021,51 +5076,11 @@ sub print_sidebyside_diff_chunk {
next;
}
- ## print from accumulator when type of class of lines change
- # empty contents block on start rem/add block, or end of chunk
- if (@ctx && (!$class || $class eq 'rem' || $class eq 'add')) {
- print join '',
- '',
- '
',
- @ctx,
- '
',
- '
',
- @ctx,
- '
',
- '
';
- @ctx = ();
- }
- # empty add/rem block on start context block, or end of chunk
- if ((@rem || @add) && (!$class || $class eq 'ctx')) {
- if (!@add) {
- # pure removal
- print join '',
- '',
- '
',
- @rem,
- '
',
- '
';
- } elsif (!@rem) {
- # pure addition
- print join '',
- '',
- '
',
- @add,
- '
',
- '
';
- } else {
- # assume that it is change
- print join '',
- '',
- '
',
- @rem,
- '
',
- '
',
- @add,
- '
',
- '
';
- }
- @rem = @add = ();
+ ## print from accumulator when have some add/rem lines or end
+ # of chunk (flush context lines)
+ if (!$class || ((@rem || @add) && $class eq 'ctx')) {
+ print_sidebyside_diff_lines(\@ctx, \@rem, \@add);
+ @ctx = @rem = @add = ();
}
## adding lines to accumulator