From: Eric Wong Date: Fri, 5 Jul 2019 04:03:11 +0000 (+0000) Subject: viewdiff: do not anchor using diffstat comments X-Git-Tag: v1.2.0~127 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=d7944a9f28c41a160099c98923f503655c952e5a 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/ --- diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm index b7dab819..4669e874 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);