From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 811AF1FD66 for ; Sat, 25 Jan 2020 04:45:14 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 20/22] viewdiff: add "b=" param when missing "diff --git" line Date: Sat, 25 Jan 2020 04:45:08 +0000 Message-Id: <20200125044510.13769-21-e@yhbt.net> In-Reply-To: <20200125044510.13769-1-e@yhbt.net> References: <20200125044510.13769-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: <2841d2de-32ad-eae8-6039-9251a40bb00e@tngtech.com> as posted to git@vger contained an otherwise valid diff without a "diff --git" line. Generate a "b=" parameter in that case using the "+++" line instead of the "diff --git" line. SearchIdx.pm no longer uses the "diff --git" line for filename information, either. --- lib/PublicInbox/ViewDiff.pm | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm index 6a60d0dc..ff7d85f5 100644 --- a/lib/PublicInbox/ViewDiff.pm +++ b/lib/PublicInbox/ViewDiff.pm @@ -133,6 +133,17 @@ sub anchor1 ($$$$$) { undef } +sub missing_diff_git_line ($$) { + my ($dctx, $pb) = @_; + # missing "diff --git ..." + $dctx->{path_b} = $pb; + $dctx->{Q} = '?b='.uri_escape_utf8($pb, UNSAFE); + my $pa = $dctx->{path_a}; + if (defined($pa) && $pa ne $pb) { + $dctx->{Q} .= '&a='. uri_escape_utf8($pa, UNSAFE); + } +} + sub flush_diff ($$$) { my ($dst, $ctx, $linkify) = @_; my $diff = $ctx->{-diff}; @@ -192,8 +203,24 @@ sub flush_diff ($$$) { $$dst .= ''; $state = DSTATE_CTX; $$dst .= $linkify->to_html($s); - } elsif ($s =~ m!^--- (?:$PATH_X)!o || - $s =~ m!^\+{3} (?:$PATH_X)!o) { + } elsif ($s =~ m!^--- ($PATH_X)!o) { + my $pa = $1; + $pa = (split('/', git_unquote($pa), 2))[1]; + if (($dctx->{path_a} // '') ne $pa) { + # missing "diff --git ..." ? + $dctx->{path_a} = $pa; + } + # color only (no oid link) if missing dctx->{oid_*} + $state <= DSTATE_STAT and + to_state($dst, $state, DSTATE_HEAD); + $$dst .= $linkify->to_html($s); + } elsif ($s =~ m!^\+{3} ($PATH_X)!o) { + my $pb = $1; + $pb = (split('/', git_unquote($pb), 2))[1]; + if (($dctx->{path_b} // '') ne $pb) { + missing_diff_git_line($dctx, $pb); + } + # color only (no oid link) if missing dctx->{oid_*} $state <= DSTATE_STAT and to_state($dst, $state, DSTATE_HEAD);