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 5A2FF1F461; Fri, 5 Jul 2019 04:03:11 +0000 (UTC) Date: Fri, 5 Jul 2019 04:03:11 +0000 From: Eric Wong To: SZEDER =?utf-8?B?R8OhYm9y?= Cc: meta@public-inbox.org Subject: [PATCH] viewdiff: do not anchor using diffstat comments Message-ID: <20190705040311.GA2896@dcvr> References: <20190704231123.GF20404@szeder.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190704231123.GF20404@szeder.dev> List-Id: SZEDER Gábor wrote: > Hi, > > being able to jump around from diffstat to the diff of a particular > file and back by simply clicking on links is great, but it doesn't > seem to work with newly added files. Consider this message: Glad you noticed this feature :) I keep forgetting to do more work on it (fixing interdiffs and such), and also writing automated tests to catch it. > https://public-inbox.org/git/20190624130226.17293-2-pclouds@gmail.com/ > > Clicking on the link that is the name of the doc source file or any of > the C source of header files in the diffstat jumps to the diff of the > particular file, but clicking on the link of any of the two new test > files doesn't go anywhere. Conversely, in the "diff --git a/... > b/..." lines of the doc and source files the word "diff" is a link > pointing back to the diffstat, but in the diff lines of those two new > test files there is no link. Thanks for the bug report. The following should fix it, it's also deployed on public-inbox.org ---------8<-------- Subject: [PATCH] viewdiff: do not anchor using diffstat comments Diffstat summary comments were added to git last year and we need to filter them out to get anchors working properly. Reported-by: SZEDER Gábor https://public-inbox.org/meta/20190704231123.GF20404@szeder.dev/ --- lib/PublicInbox/ViewDiff.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm index b7dab81..4669e87 100644 --- a/lib/PublicInbox/ViewDiff.pm +++ b/lib/PublicInbox/ViewDiff.pm @@ -41,6 +41,9 @@ my $OID_BLOB = '[a-f0-9]{7,40}'; my $PATH_A = '"?a/.+|/dev/null'; my $PATH_B = '"?b/.+|/dev/null'; +# cf. git diff.c :: get_compact_summary +my $DIFFSTAT_COMMENT = qr/\((?:new|gone|(?:(?:new|mode) [\+\-][lx]))\)/; + sub to_html ($$) { $_[0]->linkify_1($_[1]); $_[0]->linkify_2(ascii_html($_[1])); @@ -89,7 +92,7 @@ sub anchor0 ($$$$$) { # So only do best-effort handling of renames for common cases; # which works well in practice. If projects put "=>", or trailing # spaces in filenames, oh well :P - $fn =~ s/ +\z//s; + $fn =~ s/(?: *$DIFFSTAT_COMMENT)? *\z//so; $fn =~ s/{(?:.+) => (.+)}/$1/ or $fn =~ s/.* => (.+)/$1/; $fn = git_unquote($fn); -- EW