summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-07-13 16:25:59 +0200
committerYorhel <git@yorhel.nl>2019-07-13 16:26:00 +0200
commit3780cc63d7e5e07beb72a2e652715c29cd0de492 (patch)
treea0a124b0d01bf3470c3b88aa8ab2b49275806c6a
parentb7ff5a2c7719f421494854df18c72f33ebcfcd16 (diff)
Reduce context in large diffs
This is mainly useful for doc changes.
-rw-r--r--lib/VNDB/Util/CommonHTML.pm12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index e12024c1..6d0225e0 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -259,10 +259,20 @@ sub revdiff {
$ser1 = $ser2 = '';
my @d = compact_diff(\@ser1, \@ser2);
- for my $i (0..($#d-2)/2) {
+ my $lastchunk = int (($#d-2)/2);
+ for my $i (0..$lastchunk) {
# $i % 2 == 0 -> equal, otherwise it's different
my $a = join($o{join}, @ser1[ $d[$i*2] .. $d[$i*2+2]-1 ]);
my $b = join($o{join}, @ser2[ $d[$i*2+1] .. $d[$i*2+3]-1 ]);
+ # Reduce context if we have too much
+ if($i % 2 == 0 && length($a) > 300) {
+ my $sep = '<b class="standout">&lt;...&gt;</b>';
+ my $ctx = 100;
+ $a = $i == 0 ? $sep.'<br>'.substr $a, -$ctx :
+ $i == $lastchunk ? substr($a, 0, $ctx).'<br>'.$sep :
+ substr($a, 0, $ctx)."<br><br>$sep<br><br>".substr($a, -$ctx);
+ $b = $a;
+ }
$ser1 .= ($ser1?$o{join}:'').($i % 2 ? qq|<b class="diff_del">$a</b>| : $a) if $a ne '';
$ser2 .= ($ser2?$o{join}:'').($i % 2 ? qq|<b class="diff_add">$b</b>| : $b) if $b ne '';
}