]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
rename 'GitCatFile' package to 'Git'
[public-inbox.git] / lib / PublicInbox / View.pm
index 2506c95417fc267b6e6436ca0e0bf7175922104b..2ca7f95ceb8c77caea34323c749632b724a8e082 100644 (file)
@@ -21,7 +21,6 @@ require POSIX;
 # TODO: make these constants tunable
 use constant MAX_INLINE_QUOTED => 12; # half an 80x24 terminal
 use constant MAX_TRUNC_LEN => 72;
-use constant PRE_WRAP => "<pre\nstyle=\"white-space:pre-wrap\">";
 use constant T_ANCHOR => '#u';
 use constant INDENT => '  ';
 
@@ -39,7 +38,7 @@ sub msg_html {
        }
        headers_to_html_header($mime, $full_pfx, $ctx) .
                multipart_text_as_html($mime, $full_pfx) .
-               '</pre><hr />' . PRE_WRAP .
+               '</pre><hr />' . PublicInbox::Hval::PRE .
                html_footer($mime, 1, $full_pfx, $ctx) .
                $footer .
                '</pre></body></html>';
@@ -48,7 +47,8 @@ sub msg_html {
 sub feed_entry {
        my ($class, $mime, $full_pfx) = @_;
 
-       PRE_WRAP . multipart_text_as_html($mime, $full_pfx) . '</pre>';
+       PublicInbox::Hval::PRE .
+               multipart_text_as_html($mime, $full_pfx) . '</pre>';
 }
 
 sub in_reply_to {
@@ -88,7 +88,6 @@ sub index_entry {
 
        $from = PublicInbox::Hval->new_oneline($from)->as_html;
        $subj = PublicInbox::Hval->new_oneline($subj)->as_html;
-       my $more = 'permalink';
        my $root_anchor = $state->{root_anchor} || '';
        my $path = $root_anchor ? '../../' : '';
        my $href = $mid->as_href;
@@ -108,7 +107,7 @@ sub index_entry {
        if ($level) {
                $rv .= '<td><pre>' . (INDENT x $level) . '</pre></td>';
        }
-       $rv .= "<td\nid=s$midx>" . PRE_WRAP;
+       $rv .= "<td\nid=s$midx>" . PublicInbox::Hval::PRE;
        $rv .= "<b\nid=\"$id\">$subj</b>\n";
        $rv .= "- $from @ $ts UTC - ";
        $rv .= "<a\nhref=\"#s$next\">next</a>";
@@ -119,9 +118,11 @@ sub index_entry {
 
        my ($fhref, $more_ref);
        my $mhref = "${path}$href/";
+       my $more = 'permalink';
 
        # show full message if it's our root message
-       if ($root_anchor ne $id || ($level != 0 && !$ctx->{flat})) {
+       my $neq = $root_anchor ne $id;
+       if ($neq || ($neq && $level != 0 && !$ctx->{flat})) {
                $fhref = "${path}$href/f/";
                $more_ref = \$more;
        }
@@ -182,8 +183,8 @@ sub emit_thread_html {
                anchor_idx => 0,
        };
 
-       require PublicInbox::GitCatFile;
-       my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+       require PublicInbox::Git;
+       my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
        if ($flat) {
                pre_anchor_entry($seen, $_) for (@$msgs);
                __thread_entry(\$cb, $git, $state, $_, 0) for (@$msgs);
@@ -205,8 +206,8 @@ sub emit_thread_html {
        $next .= "\ndownload thread: ";
        $next .= "<a\n$MBOX_TITLE\nhref=\"../t.mbox.gz\">mbox.gz</a>";
        $next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>";
-       $cb->write("<hr />" . PRE_WRAP . $next . "\n\n". $foot .
-                  "</pre></body></html>");
+       $cb->write("<hr />" . PublicInbox::Hval::PRE . $next . "\n\n".
+               $foot .  "</pre></body></html>");
        $cb->close;
 }
 
@@ -215,12 +216,14 @@ sub index_walk {
        my $s = add_text_body($enc, $part, $part_nr, $fhref);
 
        if ($more) {
+               my $m = 0;
                # drop the remainder of git patches, they're usually better
                # to review when the full message is viewed
-               $s =~ s!^---+\n.*\z!!ms and $$more = 'more...';
+               $s =~ s!^---+\n.*\z!!ms and $m = 1;
 
                # Drop signatures
-               $s =~ s/^-- \n.*\z//ms and $$more = 'more...';
+               $s =~ s/^-- \n.*\z//ms and $m = 1;
+               $$more = "<b>More...</b>\n\n$$more" if $m;
        }
 
        # kill any leading or trailing whitespace lines
@@ -454,7 +457,7 @@ sub headers_to_html_header {
        $rv .= "\n";
 
        ("<html><head><title>".  join(' - ', @title) .
-        "</title>$atom</head><body>" . PRE_WRAP . $rv);
+        "</title>$atom</head><body>" . PublicInbox::Hval::PRE . $rv);
 }
 
 sub thread_inline {
@@ -631,7 +634,7 @@ sub ghost_table {
        my ($upfx, $mid, $level) = @_;
        "<table\nsummary=ghost><tr><td>" .
                (INDENT x $level) . "</td><td>" .
-               PRE_WRAP . ghost_parent($upfx, $mid) .
+               PublicInbox::Hval::PRE . ghost_parent($upfx, $mid) .
                '</pre></td></table>';
 }