diff options
author | Yorhel <git@yorhel.nl> | 2010-11-26 09:04:35 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2010-11-26 09:04:35 +0100 |
commit | dd0ebd6963f42dc00eedc5d896ed3c60b99b72f1 (patch) | |
tree | 5f07cf150f7a28a4dae66d9c34c6d6b511bf3fff /lib/VNDB | |
parent | 625871cba8a2fe71c70b3d2946a5f37993d1f263 (diff) |
Use word-level (instead of character-level) diff for large fields
Primary reason for this change is because Algorithm::Diff::Fast isn't
all that fast for character-level diffs. :-/
Diffstat (limited to 'lib/VNDB')
-rw-r--r-- | lib/VNDB/Handler/Producers.pm | 4 | ||||
-rw-r--r-- | lib/VNDB/Handler/Releases.pm | 2 | ||||
-rw-r--r-- | lib/VNDB/Handler/VNPage.pm | 4 | ||||
-rw-r--r-- | lib/VNDB/Util/CommonHTML.pm | 9 |
4 files changed, 10 insertions, 9 deletions
diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm index 2931e25f..f743b4ca 100644 --- a/lib/VNDB/Handler/Producers.pm +++ b/lib/VNDB/Handler/Producers.pm @@ -60,13 +60,13 @@ sub page { [ type => serialize => sub { mt "_ptype_$_[0]" } ], [ name => diff => 1 ], [ original => diff => 1 ], - [ alias => diff => 1 ], + [ alias => diff => qr/[ ,\n\.]/ ], [ lang => serialize => sub { "$_[0] (".mt("_lang_$_[0]").')' } ], [ website => diff => 1 ], [ l_wp => htmlize => sub { $_[0] ? sprintf '<a href="http://en.wikipedia.org/wiki/%s">%1$s</a>', xml_escape $_[0] : mt '_revision_nolink' }], - [ desc => diff => 1 ], + [ desc => diff => qr/[ ,\n\.]/ ], [ relations => join => '<br />', split => sub { my @r = map sprintf('%s: <a href="/p%d" title="%s">%s</a>', mt("_prodrel_$_->{relation}"), $_->{id}, xml_escape($_->{original}||$_->{name}), xml_escape shorten $_->{name}, 40 diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm index 36378212..8cc252c0 100644 --- a/lib/VNDB/Handler/Releases.pm +++ b/lib/VNDB/Handler/Releases.pm @@ -51,7 +51,7 @@ sub page { [ 'website' ], [ released => htmlize => sub { $self->{l10n}->datestr($_[0]) } ], [ minage => serialize => \&minage ], - [ notes => diff => 1 ], + [ notes => diff => qr/[ ,\n\.]/ ], [ platforms => join => ', ', split => sub { map mt("_plat_$_"), @{$_[0]} } ], [ media => join => ', ', split => sub { map $self->{media}{$_->{medium}} ? $_->{qty}.' '.mt("_med_$_->{medium}", $_->{qty}) : mt("_med_$_->{medium}",1), @{$_[0]} diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm index 4a4b3f4f..1a3eb514 100644 --- a/lib/VNDB/Handler/VNPage.pm +++ b/lib/VNDB/Handler/VNPage.pm @@ -191,8 +191,8 @@ sub _revision { $self->htmlRevision('v', $prev, $v, [ title => diff => 1 ], [ original => diff => 1 ], - [ alias => diff => 1 ], - [ desc => diff => 1 ], + [ alias => diff => qr/[ ,\n\.]/ ], + [ desc => diff => qr/[ ,\n\.]/ ], [ length => serialize => sub { mt '_vnlength_'.$_[0] } ], [ l_wp => htmlize => sub { $_[0] ? sprintf '<a href="http://en.wikipedia.org/wiki/%s">%1$s</a>', xml_escape $_[0] : mt '_revision_nolink' diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm index a862911d..280ceddb 100644 --- a/lib/VNDB/Util/CommonHTML.pm +++ b/lib/VNDB/Util/CommonHTML.pm @@ -153,7 +153,7 @@ sub htmlHiddenMessage { # Where @fields is a list of fields as arrayrefs with: # [ shortname, displayname, %options ], # Where %options: -# diff => 1/0, whether do show a diff on this field +# diff => 1/0/regex, whether to show a diff on this field, and what to split it with (1 = character-level diff) # serialize => coderef, should convert the field into a readable string, no HTML allowed # htmlize => same as serialize, but HTML is allowed and this can't be diff'ed # split => coderef, should return an array of HTML strings that can be diff'ed. (implies diff => 1) @@ -226,7 +226,7 @@ sub revdiff { my($i, $type, $old, $new, $short, %o) = @_; $o{serialize} ||= $o{htmlize}; - $o{diff}++ if $o{split}; + $o{diff} = 1 if $o{split}; $o{join} ||= ''; my $ser1 = $o{serialize} ? $o{serialize}->($old->{$short}, $old) : $old->{$short}; @@ -234,8 +234,9 @@ sub revdiff { return if $ser1 eq $ser2; if($o{diff} && $ser1 && $ser2) { - my @ser1 = $o{split} ? $o{split}->($ser1) : map xml_escape($_), split //, $ser1; - my @ser2 = $o{split} ? $o{split}->($ser2) : map xml_escape($_), split //, $ser2; + my $sep = ref $o{diff} ? qr/($o{diff})/ : qr//; + my @ser1 = $o{split} ? $o{split}->($ser1) : map xml_escape($_), split $sep, $ser1; + my @ser2 = $o{split} ? $o{split}->($ser2) : map xml_escape($_), split $sep, $ser2; return if $o{split} && $#ser1 == $#ser2 && !grep $ser1[$_] ne $ser2[$_], 0..$#ser1; $ser1 = $ser2 = ''; |