about summary refs log tree commit homepage
path: root/lib/PublicInbox/View.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-05-07 21:05:45 +0000
committerEric Wong <e@yhbt.net>2020-05-09 08:59:10 +0000
commit453dee4881a9c764b09d33f3a827879f2cd3669d (patch)
treee1c5d2fcb1b5e4a7571e9eaf59d6ce6660f3e200 /lib/PublicInbox/View.pm
parent8d1b87f498ea47bb752ea24900372df192d322fb (diff)
downloadpublic-inbox-453dee4881a9c764b09d33f3a827879f2cd3669d.tar.gz
This doesn't make any difference for most multipart
messages (or any single part messages).  However,
this starts having space savings when parts start
nesting.

It also slightly simplifies callers.
Diffstat (limited to 'lib/PublicInbox/View.pm')
-rw-r--r--lib/PublicInbox/View.pm18
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index e42fb362..3328c865 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -482,9 +482,8 @@ sub multipart_text_as_html {
 
 sub attach_link ($$$$;$) {
         my ($ctx, $ct, $p, $fn, $err) = @_;
-        my ($part, $depth, @idx) = @$p;
-        my $nl = $idx[-1] > 1 ? "\n" : '';
-        my $idx = join('.', @idx);
+        my ($part, $depth, $idx) = @$p;
+        my $nl = substr($idx, -2) eq '.1' ? '' : "\n"; # like join("\n", ...)
         my $size = bytes::length($part->body);
 
         # hide attributes normally, unless we want to aid users in
@@ -519,8 +518,8 @@ sub add_text_body { # callback for each_part
         my ($p, $ctx) = @_;
         my $upfx = $ctx->{mhref};
         my $ibx = $ctx->{-inbox};
-        # $p - from each_part: [ Email::MIME-like, depth, @idx ]
-        my ($part, $depth, @idx) = @$p;
+        # $p - from each_part: [ Email::MIME-like, depth, $idx ]
+        my ($part, $depth, $idx) = @$p;
         my $ct = $part->content_type || 'text/plain';
         my $fn = $part->filename;
         my ($s, $err) = msg_part_text($part, $ct);
@@ -537,13 +536,14 @@ sub add_text_body { # callback for each_part
         # headers for solver unless some coderepo are configured:
         my $diff;
         if ($s =~ /^--- [^\n]+\n\+{3} [^\n]+\n@@ /ms) {
-                # diffstat anchors do not link across attachments or messages:
-                $idx[0] = $upfx . $idx[0] if $upfx ne '';
-                $ctx->{-apfx} = join('/', @idx);
+                # diffstat anchors do not link across attachments or messages,
+                # -apfx is just a stable prefix for making diffstat anchors
+                # linkable to the first diff hunk w/o crossing attachments
+                $idx =~ tr!.!/!; # compatibility with previous versions
+                $ctx->{-apfx} = $upfx . $idx;
 
                 # do attr => filename mappings for diffstats in git diffs:
                 $ctx->{-anchors} = {} if $s =~ /^diff --git /sm;
-
                 $diff = 1;
                 delete $ctx->{-long_path};
                 my $spfx;