]> Sergey Matveev's repositories - public-inbox.git/commitdiff
Merge remote-tracking branch 'origin/viewvcs' into master
authorEric Wong <e@80x24.org>
Wed, 30 Jan 2019 07:40:35 +0000 (07:40 +0000)
committerEric Wong <e@80x24.org>
Wed, 30 Jan 2019 07:40:35 +0000 (07:40 +0000)
* origin/viewvcs: (66 commits)
  solvergit: deal with alternative diff prefixes
  solvergit: extract mode from diff headers properly
  solvergit: avoid "Wide character" warnings
  solvergit: do not show full path names to "git apply"
  css/216dark: add comments and tweak highlight colors
  viewvcs: avoid segfault with highlight.pm at shutdown
  solvergit: do not solve blobs twice
  t/check-www-inbox: disable history
  t/check-www-inbox: don't follow mboxes
  t/check-www-inbox: replace IPC::Run with PublicInbox::Spawn
  hval: add src_escape for highlight post-processing
  viewvcs: wire up syntax-highlighting for blobs
  hlmod: disable enclosing <pre> tag
  t/hl_mod: extra check to ensure we escape HTML
  wwwhighlight: read_in_full returns undef on errors
  solver: crank up max patches to 9999
  viewvcs: do not show final error message twice
  qspawn: decode $? for user-friendliness
  solver: reduce "git apply" invocations
  solver: hold patches in temporary directory
  ...

1  2 
lib/PublicInbox/View.pm

diff --combined lib/PublicInbox/View.pm
index 4c1c6705135e3b87ed41644208717b0fb306a794,5aaa72ba1fd9be0c8f8b5b69329fc34757732aa4..ca9b95505f6c767784d77023d8ec5fe500cf1a7e
@@@ -14,6 -14,7 +14,7 @@@ use PublicInbox::MsgIter
  use PublicInbox::Address;
  use PublicInbox::WwwStream;
  use PublicInbox::Reply;
+ use PublicInbox::ViewDiff qw(flush_diff);
  require POSIX;
  use Time::Local qw(timegm);
  
@@@ -28,7 -29,7 +29,7 @@@ sub msg_html 
        my ($ctx, $mime, $more, $smsg) = @_;
        my $hdr = $mime->header_obj;
        my $ibx = $ctx->{-inbox};
-       my $obfs_ibx = $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
+       $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
        my $tip = _msg_html_prepare($hdr, $ctx, $more, 0);
        my $end = 2;
        PublicInbox::WwwStream->response($ctx, 200, sub {
@@@ -36,7 -37,7 +37,7 @@@
                if ($nr == 1) {
                        # $more cannot be true w/o $smsg being defined:
                        my $upfx = $more ? '../'.mid_escape($smsg->mid).'/' : '';
-                       $tip . multipart_text_as_html($mime, $upfx, $obfs_ibx) .
+                       $tip . multipart_text_as_html($mime, $upfx, $ibx) .
                                '</pre><hr>'
                } elsif ($more && @$more) {
                        ++$end;
@@@ -81,15 -82,15 +82,15 @@@ sub msg_html_more 
        my $str = eval {
                my ($id, $prev, $smsg) = @$more;
                my $mid = $ctx->{mid};
-               $smsg = $ctx->{-inbox}->smsg_mime($smsg);
+               my $ibx = $ctx->{-inbox};
+               $smsg = $ibx->smsg_mime($smsg);
                my $next = $ctx->{srch}->next_by_mid($mid, \$id, \$prev);
                @$more = $next ? ($id, $prev, $next) : ();
                if ($smsg) {
                        my $mime = $smsg->{mime};
                        my $upfx = '../' . mid_escape($smsg->mid) . '/';
                        _msg_html_prepare($mime->header_obj, $ctx, $more, $nr) .
-                               multipart_text_as_html($mime, $upfx,
-                                                       $ctx->{-obfs_ibx}) .
+                               multipart_text_as_html($mime, $upfx, $ibx) .
                                '</pre><hr>'
                } else {
                        '';
@@@ -260,7 -261,8 +261,8 @@@ sub index_entry 
        $rv .= "\n";
  
        # scan through all parts, looking for displayable text
-       msg_iter($mime, sub { $rv .= add_text_body($mhref, $obfs_ibx, $_[0]) });
+       my $ibx = $ctx->{-inbox};
+       msg_iter($mime, sub { $rv .= add_text_body($mhref, $ibx, $_[0]) });
  
        # add the footer
        $rv .= "\n<a\nhref=#$id_m\nid=e$id>^</a> ".
@@@ -488,11 -490,11 +490,11 @@@ sub thread_html 
  }
  
  sub multipart_text_as_html {
-       my ($mime, $upfx, $obfs_ibx) = @_;
+       my ($mime, $upfx, $ibx) = @_;
        my $rv = "";
  
        # scan through all parts, looking for displayable text
-       msg_iter($mime, sub { $rv .= add_text_body($upfx, $obfs_ibx, $_[0]) });
+       msg_iter($mime, sub { $rv .= add_text_body($upfx, $ibx, $_[0]) });
        $rv;
  }
  
@@@ -545,7 -547,8 +547,8 @@@ sub attach_link ($$$$;$) 
  }
  
  sub add_text_body {
-       my ($upfx, $obfs_ibx, $p) = @_;
+       my ($upfx, $ibx, $p) = @_;
+       my $obfs_ibx = $ibx->{obfuscate} ? $ibx : undef;
        # $p - from msg_iter: [ Email::MIME, depth, @idx ]
        my ($part, $depth) = @$p; # attachment @idx is unused
        my $ct = $part->content_type || 'text/plain';
  
        return attach_link($upfx, $ct, $p, $fn) unless defined $s;
  
+       # makes no difference to browsers, and don't screw up filename
+       # link generation in diffs with the extra '%0D'
+       $s =~ s/\r\n/\n/sg;
+       my ($diff, $spfx);
+       if ($s =~ /^(?:diff|---|\+{3}) /ms) {
+               $diff = [];
+               if ($ibx->{-repo_objs}) {
+                       my $n_slash = $upfx =~ tr!/!/!;
+                       if ($n_slash == 0) {
+                               $spfx = '../';
+                       } elsif ($n_slash == 1) {
+                               $spfx = '';
+                       } else { # nslash == 2
+                               $spfx = '../../';
+                       }
+               }
+       };
        my @lines = split(/^/m, $s);
        $s = '';
        if (defined($fn) || $depth > 0 || $err) {
                        # show the previously buffered quote inline
                        flush_quote(\$s, $l, \@quot) if @quot;
  
-                       # regular line, OK
-                       $l->linkify_1($cur);
-                       $s .= $l->linkify_2(ascii_html($cur));
+                       if ($diff) {
+                               push @$diff, $cur;
+                       } else {
+                               # regular line, OK
+                               $l->linkify_1($cur);
+                               $s .= $l->linkify_2(ascii_html($cur));
+                       }
                } else {
+                       flush_diff(\$s, $spfx, $l, $diff) if $diff && @$diff;
                        push @quot, $cur;
                }
        }
  
        if (@quot) { # ugh, top posted
                flush_quote(\$s, $l, \@quot);
+               flush_diff(\$s, $spfx, $l, $diff) if $diff && @$diff;
                obfuscate_addrs($obfs_ibx, $s) if $obfs_ibx;
                $s;
        } else {
+               flush_diff(\$s, $spfx, $l, $diff) if $diff && @$diff;
                obfuscate_addrs($obfs_ibx, $s) if $obfs_ibx;
                if ($s =~ /\n\z/s) { # common, last line ends with a newline
                        $s;
@@@ -867,6 -896,11 +896,6 @@@ sub missing_thread 
        PublicInbox::ExtMsg::ext_msg($ctx);
  }
  
 -sub _msg_date {
 -      my ($hdr) = @_;
 -      fmt_ts(msg_datestamp($hdr));
 -}
 -
  sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
  
  sub dedupe_subject {
@@@ -1070,7 -1104,7 +1099,7 @@@ sub dump_topics 
  
                my $mbox = qq(<a\nhref="$href/t.mbox.gz">mbox.gz</a>);
                my $atom = qq(<a\nhref="$href/t.atom">Atom</a>);
-               my $s = "<a\nhref=\"$href/T/$anchor\"><b>$top</b></a>\n" .
+               my $s = "<a\nhref=\"$href/T/$anchor\">$top</a>\n" .
                        " $ds UTC $n - $mbox / $atom\n";
                for (my $i = 0; $i < scalar(@ex); $i += 2) {
                        my $level = $ex[$i];