user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH] viewdiff: do not generate "a=" parameter if "b=" matches
Date: Sun, 16 Feb 2020 04:07:30 -0600	[thread overview]
Message-ID: <20200216100730.20021-1-e@yhbt.net> (raw)

Long URLs waste bandwidth and redundant query parameters
make caching more difficult and expensive.

Fixes: ddec19694cbf0e1d ("viewdiff: rewrite and simplify")
---
 lib/PublicInbox/ViewDiff.pm | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

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('&amp;', @q);

                 reply	other threads:[~2020-02-16 10:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200216100730.20021-1-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).