]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ViewDiff.pm
update copyrights for 2021
[public-inbox.git] / lib / PublicInbox / ViewDiff.pm
index 34df8ad447c53a78460eb04c479f97be7c033262..8fe7261ff2909220b7e3e28c6f7f07b97c9e173f 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2019-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # used by PublicInbox::View
@@ -18,8 +18,8 @@ use PublicInbox::Git qw(git_unquote);
 
 sub UNSAFE () { "^A-Za-z0-9\-\._~/" }
 
-my $OID_NULL = '0{7,40}';
-my $OID_BLOB = '[a-f0-9]{7,40}';
+my $OID_NULL = '0{7,}';
+my $OID_BLOB = '[a-f0-9]{7,}';
 my $LF = qr!\n!;
 my $ANY = qr![^\n]!;
 my $FN = qr!(?:"?[^/\n]+/[^\n]+|/dev/null)!;
@@ -50,12 +50,12 @@ sub diff_hunk ($$$$) {
 
        if (defined($spfx) && defined($oid_a) && defined($oid_b)) {
                my ($n) = ($ca =~ /^-([0-9]+)/);
-               $n = defined($n) ? do { ++$n; "#n$n" } : '';
+               $n = defined($n) ? "#n$n" : '';
 
                $$dst .= qq(@@ <a\nhref="$spfx$oid_a/s/$dctx->{Q}$n">$ca</a>);
 
                ($n) = ($cb =~ /^\+([0-9]+)/);
-               $n = defined($n) ? do { ++$n; "#n$n" } : '';
+               $n = defined($n) ? "#n$n" : '';
                $$dst .= qq( <a\nhref="$spfx$oid_b/s/$dctx->{Q}$n">$cb</a> @@);
        } else {
                $$dst .= "@@ $ca $cb @@";
@@ -165,10 +165,12 @@ sub diff_before_or_after ($$) {
        my ($ctx, $x) = @_;
        my $linkify = $ctx->{-linkify};
        my $dst = $ctx->{obuf};
+       my $anchors = exists($ctx->{-anchors}) ? 1 : 0;
        for my $y (split(/(^---\n)/sm, $$x)) {
                if ($y =~ /\A---\n\z/s) {
                        $$dst .= "---\n"; # all HTML is "\r\n" => "\n"
-               } elsif ($y =~ /^ [0-9]+ files? changed, /sm) {
+                       $anchors |= 2;
+               } elsif ($anchors == 3 && $y =~ /^ [0-9]+ files? changed, /sm) {
                        # ok, looks like a diffstat, go line-by-line:
                        for my $l (split(/^/m, $y)) {
                                if ($l =~ /^ (.+)( +\| .*\z)/s) {