]> Sergey Matveev's repositories - public-inbox.git/commitdiff
viewdiff: do not anchor using diffstat comments
authorEric Wong <e@80x24.org>
Fri, 5 Jul 2019 04:03:11 +0000 (04:03 +0000)
committerEric Wong <e@80x24.org>
Fri, 5 Jul 2019 04:04:10 +0000 (04:04 +0000)
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 <szeder.dev@gmail.com>
  https://public-inbox.org/meta/20190704231123.GF20404@szeder.dev/

lib/PublicInbox/ViewDiff.pm

index b7dab81946efe9372fa0a433740d1bd331b206a1..4669e8746f043ac7ca840f5e699cbb478a85a4ac 100644 (file)
@@ -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);