From: Eric Wong Date: Sun, 16 Feb 2020 10:07:30 +0000 (-0600) Subject: viewdiff: do not generate "a=" parameter if "b=" matches X-Git-Tag: v1.4.0~110 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=7efca6c8a2b98d97056fc933165df82e4b825725 viewdiff: do not generate "a=" parameter if "b=" matches Long URLs waste bandwidth and redundant query parameters make caching more difficult and expensive. Fixes: ddec19694cbf0e1d ("viewdiff: rewrite and simplify") --- diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm index b2dcbf8f..604b1f23 100644 --- a/lib/PublicInbox/ViewDiff.pm +++ b/lib/PublicInbox/ViewDiff.pm @@ -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('&', @q);