]> Sergey Matveev's repositories - public-inbox.git/commitdiff
viewdiff: do not generate "a=" parameter if "b=" matches
authorEric Wong <e@yhbt.net>
Sun, 16 Feb 2020 10:07:30 +0000 (04:07 -0600)
committerEric Wong <e@yhbt.net>
Mon, 17 Feb 2020 07:54:49 +0000 (07:54 +0000)
Long URLs waste bandwidth and redundant query parameters
make caching more difficult and expensive.

Fixes: ddec19694cbf0e1d ("viewdiff: rewrite and simplify")
lib/PublicInbox/ViewDiff.pm

index b2dcbf8fedd3f599a71473e446ef962e02b2729e..604b1f23e5dbe9d509416b28914444005adece2b 100644 (file)
@@ -106,17 +106,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('&amp;', @q);