X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FViewDiff.pm;h=124a723a5fb465247963a5d01fd5c40fda593c11;hb=refs%2Fheads%2Fmaster;hp=5d23881b55c1e9a2c74b2d6afd3c1b0c04954488;hpb=ab9c03ff4aa369b397dc1a8c8936153c8565fd05;p=public-inbox.git diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm index 5d23881b..124a723a 100644 --- a/lib/PublicInbox/ViewDiff.pm +++ b/lib/PublicInbox/ViewDiff.pm @@ -7,8 +7,7 @@ # (or reconstruct) blobs. package PublicInbox::ViewDiff; -use strict; -use v5.10.1; +use v5.12; use parent qw(Exporter); our @EXPORT_OK = qw(flush_diff uri_escape_path); use URI::Escape qw(uri_escape_utf8); @@ -124,12 +123,8 @@ sub diff_header ($$$) { $dctx->{Q} = '?b='.uri_escape_path($pb); } else { my @q; - if ($pb ne '/dev/null') { - push @q, 'b='.uri_escape_path($pb); - } - if ($pa ne '/dev/null') { - push @q, 'a='.uri_escape_path($pa); - } + push @q, 'b='.uri_escape_path($pb) if $pb ne '/dev/null'; + push @q, 'a='.uri_escape_path($pa) if $pa ne '/dev/null'; $dctx->{Q} = '?'.join('&', @q); } @@ -159,16 +154,16 @@ sub diff_header ($$$) { sub diff_before_or_after ($$) { my ($ctx, $x) = @_; - if (exists $ctx->{-anchors} && $$x =~ /\A(.*?) # likely "---\n" # \$1 - # diffstat lines: - ((?:^\x20(?:[^\n]+?)(?:\x20+\|\x20[^\n]*\n))+) - (\x20[0-9]+\x20files?\x20)changed,([^\n]+\n) - (.*?)\z/msx) { # notes, commit message, etc - my @x = ($5, $4, $3, $2, $1); - undef $$x; + if (exists $ctx->{-anchors} && $$x =~ # diffstat lines: + /((?:^\x20(?:[^\n]+?)(?:\x20+\|\x20[^\n]*\n))+) + (\x20[0-9]+\x20files?\x20)changed,/msx) { + my $pre = substr($$x, 0, $-[0]); # (likely) short prefix + substr($$x, 0, $+[0], ''); # sv_chop on $$x ($$x may be long) + my @x = ($2, $1); my $lnk = $ctx->{-linkify}; my $zfh = $ctx->{zfh}; - print $zfh $lnk->to_html(pop @x); # $1 uninteresting prefix + # uninteresting prefix + print $zfh $lnk->to_html($pre); for my $l (split(/^/m, pop(@x))) { # $2 per-file stat lines $l =~ /^ (.+)( +\| .*\z)/s and anchor0($ctx, $1, $2) and next; @@ -177,8 +172,8 @@ sub diff_before_or_after ($$) { my $ch = $ctx->{changed_href} // '#related'; print $zfh pop(@x), # $3 /^ \d+ files? / qq(changed,), - ascii_html(pop @x), # insertions/deletions - $lnk->to_html(@x); # notes, commit message, etc + # insertions/deletions, notes, commit message, etc: + $lnk->to_html($$x); } else { print { $ctx->{zfh} } $ctx->{-linkify}->to_html($$x); } @@ -201,7 +196,8 @@ sub flush_diff ($$) { $top[0] =~ $IS_OID) { $dctx = diff_header(\$x, $ctx, \@top); } elsif ($dctx) { - open(my $afh, '>>', \(my $after='')) or die "open: $!"; + open(my $afh, '>>:utf8', \(my $after='')) or + die "open: $!"; # Quiet "Complex regular subexpression recursion limit" # warning. Perl will truncate matches upon hitting @@ -216,6 +212,7 @@ sub flush_diff ($$) { for my $s (split(/((?:(?:^\+[^\n]*\n)+)| (?:(?:^-[^\n]*\n)+)| (?:^@@ [^\n]+\n))/xsm, $x)) { + undef $x; if (!defined($dctx)) { print $afh $s; } elsif ($s =~ s/\A@@ (\S+) (\S+) @@//) { @@ -238,7 +235,10 @@ sub flush_diff ($$) { print $zfh $lnk->to_html($s); } } - diff_before_or_after($ctx, \$after) if !$dctx; + if (!$dctx) { + utf8::decode($after); + diff_before_or_after($ctx, \$after); + } } else { diff_before_or_after($ctx, \$x); }