X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FViewDiff.pm;h=57a1b5d66dd9dda27de87c3106da22fb3f385355;hb=a7c58d0ce022671c9170401054a1131b9ec15bfa;hp=8c37c139c6201391c93477c82a924bf127c29431;hpb=ddec19694cbf0e1d94fb56c0fc4bd90eae540884;p=public-inbox.git diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm index 8c37c139..57a1b5d6 100644 --- a/lib/PublicInbox/ViewDiff.pm +++ b/lib/PublicInbox/ViewDiff.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2019 all contributors +# Copyright (C) 2019-2020 all contributors # License: AGPL-3.0+ # # used by PublicInbox::View @@ -20,6 +20,9 @@ sub UNSAFE () { "^A-Za-z0-9\-\._~/" } my $OID_NULL = '0{7,40}'; my $OID_BLOB = '[a-f0-9]{7,40}'; +my $LF = qr!\n!; +my $ANY = qr![^\n]!; +my $FN = qr!(?:"?[^/\n]+/[^\n]+|/dev/null)!; # cf. git diff.c :: get_compact_summary my $DIFFSTAT_COMMENT = qr/\((?:new|gone|(?:(?:new|mode) [\+\-][lx]))\)/; @@ -106,17 +109,18 @@ sub diff_header ($$$$) { my (undef, undef, $pa, $pb) = splice(@$top, 0, 4); # ignore oid_{a,b} my $spfx = $ctx->{-spfx}; my $dctx = { spfx => $spfx }; + + # get rid of leading "a/" or "b/" (or whatever --{src,dst}-prefix are) + $pa = (split('/', git_unquote($pa), 2))[1] if $pa ne '/dev/null'; + $pb = (split('/', git_unquote($pb), 2))[1] if $pb ne '/dev/null'; if ($pa eq $pb && $pb ne '/dev/null') { - $pa = $pb = (split('/', git_unquote($pb), 2))[1]; $dctx->{Q} = "?b=".uri_escape_utf8($pb, UNSAFE); } else { my @q; if ($pb ne '/dev/null') { - $pb = (split('/', git_unquote($pb), 2))[1]; push @q, 'b='.uri_escape_utf8($pb, UNSAFE); } if ($pa ne '/dev/null') { - $pa = (split('/', git_unquote($pa), 2))[1]; push @q, 'a='.uri_escape_utf8($pa, UNSAFE); } $dctx->{Q} = '?'.join('&', @q); @@ -149,8 +153,8 @@ sub diff_header ($$$$) { sub diff_before_or_after ($$$) { my ($dst, $ctx, $x) = @_; my $linkify = $ctx->{-linkify}; - for my $y (split(/(^---\r?\n)/sm, $$x)) { - if ($y =~ /\A---\r?\n\z/s) { + for my $y (split(/(^---\n)/sm, $$x)) { + if ($y =~ /\A---\n\z/s) { $$dst .= "---\n"; # all HTML is "\r\n" => "\n" } elsif ($y =~ /^ [0-9]+ files? changed, /sm) { # ok, looks like a diffstat, go line-by-line: @@ -166,11 +170,9 @@ sub diff_before_or_after ($$$) { } } +# callers must do CRLF => LF conversion before calling this sub flush_diff ($$$) { my ($dst, $ctx, $cur) = @_; - state $LF = qr!\r?\n!; - state $ANY = qr![^\r\n]!; - state $FN = qr!(?:"?[^/\n]+/[^\r\n]+|/dev/null)!; my @top = split(/( (?: # begin header stuff, don't capture filenames, here,