]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
hval: introduce new_bin for raw data
authorEric Wong <e@80x24.org>
Tue, 22 Dec 2015 02:30:28 +0000 (02:30 +0000)
committerEric Wong <e@80x24.org>
Tue, 5 Apr 2016 18:58:27 +0000 (18:58 +0000)
Since we no longer get our data from Email::MIME when reading
non-email, we need to explicitly specify it as such.

lib/PublicInbox/Hval.pm
lib/PublicInbox/RepoBrowse.pm
lib/PublicInbox/RepoBrowseGitCommit.pm
lib/PublicInbox/RepoBrowseGitTree.pm

index 70bae7c67db9bfc59e36779016e1842a3292a7ff..2e8b1d60c5054b3e5d18670f9b97518072fb46f4 100644 (file)
@@ -18,8 +18,19 @@ our @EXPORT_OK = qw/ascii_html/;
 use constant STYLE => '<style>pre{white-space:pre-wrap}</style>';
 use constant PRE => "<pre\nstyle=\"white-space:pre-wrap\">"; # legacy
 
+my $enc_utf8 = find_encoding('UTF-8');
 my $enc_ascii = find_encoding('us-ascii');
 
+sub new_bin {
+       my ($class, $raw, $href) = @_;
+
+       $raw = $enc_utf8->decode($raw);
+       bless {
+               raw => $raw,
+               href => defined $href ? $href : $raw,
+       }, $class;
+}
+
 sub new {
        my ($class, $raw, $href) = @_;
 
index fcecf472de13374ec50e3c848c91776e56d957ad..ef3bcf8783d35c797f5ad7d32900bb9bd58ab54f 100644 (file)
@@ -69,7 +69,7 @@ sub run {
                $mod = "PublicInbox::RepoBrowse$vcs$mod";
                unless ($LOADED{$mod}) {
                        eval "require $mod";
-                       $LOADED{$mod} = 1;
+                       $LOADED{$mod} = 1 unless $@;
                }
                $req->{relcmd} = '../' x scalar(@extra);
                my $rv = eval { $mod->new->call($cmd, $req) };
index 1e2109ecd48c73335255d4b3e4d94a7bf0037775..324c60a1f27e6bf5917cd026f78d3a9176fab765 100644 (file)
@@ -58,28 +58,28 @@ sub git_commit_stream {
                        my @l = ($1, $2);
                        @href = git_blob_hrefs($rel, @l);
                        @l = git_blob_links(\@href, \@l);
-                       $l = "index $l[0]..$l[1]$end";
+                       $l = "index $l[0]..$l[1]$end\n";
                } elsif ($l =~ /^@@ (\S+) (\S+) @@(.*)$/) { # regular
                        my $ctx = $3;
                        my @l = ($1, $2);
                        @l = git_blob_links(\@href, \@l);
-                       $l = "@@ $l[0] $l[1] @@".$ctx;
+                       $l = "@@ $l[0] $l[1] \@\@$ctx\n";
                } elsif ($l =~ /^index ($cmt,[^\.]+)\.\.($cmt)(.*)$/o) { # --cc
                        my @l = (split(',', $1), $2);
                        my $end = $3;
                        @href = git_blob_hrefs($rel, @l);
                        @l = git_blob_links(\@href, \@l);
                        my $res = pop @l;
-                       $l = 'index '.join(',', @l)."..$res$end";
+                       $l = 'index '.join(',', @l)."..$res$end\n";
                } elsif ($l =~ /^(@@@+) (\S+.*\S+) @@@+(.*)$/) { # --cc
                        my ($at, $ctx) = ($1, $3);
                        my @l = split(' ', $2);
                        @l = git_blob_links(\@href, \@l);
-                       $l = join(' ', $at, @l, $at) . $ctx;
+                       $l = join(' ', $at, @l, $at) . $ctx . "\n";
                } else {
-                       $l = PublicInbox::Hval->new($l)->as_html;
+                       $l = PublicInbox::Hval->new_bin($l)->as_html;
                }
-               $fh->write($l . "\n");
+               $fh->write($l);
        }
        $fh->write('</pre></body></html>');
 }
index b176bb3f7687f6a04f4963f8b6fdeb1a817be145..5744b4740dbfa09a0db112e1bfa1682949906153 100644 (file)
@@ -6,8 +6,6 @@ use warnings;
 use base qw(PublicInbox::RepoBrowseBase);
 use PublicInbox::Git;
 use URI::Escape qw(uri_escape_utf8);
-use Encode qw/find_encoding/;
-my $enc_utf8 = find_encoding('UTF-8');
 
 my %GIT_MODE = (
        '100644' => ' ', # blob
@@ -86,8 +84,7 @@ sub blob_show {
                        $buf = pop @buf; # last line, careful...
                        $n += scalar @buf;
                        foreach my $l (@buf) {
-                               $l = $enc_utf8->decode($l);
-                               $l = PublicInbox::Hval::ascii_html($l);
+                               $l = PublicInbox::Hval->new_bin($l)->as_html;
                                $l .= "\n";
                                $fh->write($l);
                        }