about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-07-05 04:03:11 +0000
committerEric Wong <e@80x24.org>2019-07-05 04:04:10 +0000
commitd7944a9f28c41a160099c98923f503655c952e5a (patch)
tree68fbc1bf4ac6219161bc43f27a63ac16adc42e80
parentf97f84ecbe02223af61fc5ea5074a90b1194cdd2 (diff)
downloadpublic-inbox-d7944a9f28c41a160099c98923f503655c952e5a.tar.gz
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/
-rw-r--r--lib/PublicInbox/ViewDiff.pm5
1 files changed, 4 insertions, 1 deletions
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);