From 54c10e3aac3020b83a3be0b9578894154bd3de6a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 22 Dec 2015 02:30:28 +0000 Subject: hval: introduce new_bin for raw data 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 | 11 +++++++++++ lib/PublicInbox/RepoBrowse.pm | 2 +- lib/PublicInbox/RepoBrowseGitCommit.pm | 12 ++++++------ lib/PublicInbox/RepoBrowseGitTree.pm | 5 +---- 4 files changed, 19 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm index 70bae7c6..2e8b1d60 100644 --- a/lib/PublicInbox/Hval.pm +++ b/lib/PublicInbox/Hval.pm @@ -18,8 +18,19 @@ our @EXPORT_OK = qw/ascii_html/; use constant STYLE => ''; use constant PRE => ""; # 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) = @_; diff --git a/lib/PublicInbox/RepoBrowse.pm b/lib/PublicInbox/RepoBrowse.pm index fcecf472..ef3bcf87 100644 --- a/lib/PublicInbox/RepoBrowse.pm +++ b/lib/PublicInbox/RepoBrowse.pm @@ -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) }; diff --git a/lib/PublicInbox/RepoBrowseGitCommit.pm b/lib/PublicInbox/RepoBrowseGitCommit.pm index 1e2109ec..324c60a1 100644 --- a/lib/PublicInbox/RepoBrowseGitCommit.pm +++ b/lib/PublicInbox/RepoBrowseGitCommit.pm @@ -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(''); } diff --git a/lib/PublicInbox/RepoBrowseGitTree.pm b/lib/PublicInbox/RepoBrowseGitTree.pm index b176bb3f..5744b474 100644 --- a/lib/PublicInbox/RepoBrowseGitTree.pm +++ b/lib/PublicInbox/RepoBrowseGitTree.pm @@ -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); } -- cgit v1.2.3-24-ge0c7