X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSearchView.pm;h=fbef4116e9623f2838f17cf0c4fc31c9ff31acaf;hb=5c5dfb7d5558ff248477fa57aef08e2a8bbd9800;hp=d4c44bab277d3578e2228551086d08c2a213db6c;hpb=3b620d93cdc3bcf8eab02fd874a34db7ae013775;p=public-inbox.git diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index d4c44bab..fbef4116 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -8,7 +8,7 @@ use warnings; use PublicInbox::SearchMsg; use PublicInbox::Hval qw/ascii_html/; use PublicInbox::View; -use PublicInbox::MID qw(mid2path mid_clean mid_mime); +use PublicInbox::MID qw(mid2path mid_mime); use Email::MIME; require PublicInbox::Git; require PublicInbox::Thread; @@ -151,7 +151,6 @@ sub tdump { $m; } ($mset->items); - my @rootset; my $th = PublicInbox::Thread->new(@m); $th->thread; if ($q->{r}) { # order by relevance @@ -164,50 +163,34 @@ sub tdump { } else { # order by time (default for threaded view) $th->order(*PublicInbox::View::sort_ts); } - @rootset = $th->rootset; - my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir}); + my $skel = ''; my $state = { + -inbox => $ctx->{-inbox}, + anchor_idx => 1, ctx => $ctx, - anchor_idx => 0, - pct => \%pct, cur_level => 0, + dst => \$skel, fh => $fh, + mapping => {}, + pct => \%pct, + prev_attr => '', + prev_level => 0, + seen => {}, + srch => $ctx->{srch}, + upfx => './', }; $ctx->{searchview} = 1; - tdump_ent($git, $state, $_, 0) for @rootset; - PublicInbox::View::thread_adj_level($state, 0); + PublicInbox::View::walk_thread($th, $state, + *PublicInbox::View::pre_thread); - $fh->write(search_nav_bot($mset, $q). "\n\n" . + PublicInbox::View::thread_entry($state, $_, 0) for @m; + + $fh->write(search_nav_bot($mset, $q). "\n\n" . $skel . "\n" . foot($ctx). ''); $fh->close; } -sub tdump_ent { - my ($git, $state, $node, $level) = @_; - return unless $node; - my $mime = $node->message; - - if ($mime) { - # lazy load the full message from mini_mime: - my $mid = mid_mime($mime); - $mime = eval { - my $path = mid2path(mid_clean($mid)); - Email::MIME->new($git->cat_file('HEAD:'.$path)); - }; - } - if ($mime) { - my $end = PublicInbox::View::thread_adj_level($state, $level); - PublicInbox::View::index_entry($mime, $level, $state); - $state->{fh}->write($end) if $end; - } else { - my $mid = $node->messageid; - PublicInbox::View::ghost_flush($state, '', $mid, $level); - } - tdump_ent($git, $state, $node->child, $level + 1); - tdump_ent($git, $state, $node->next, $level); -} - sub foot { my ($ctx) = @_; my $foot = $ctx->{footer} || ''; @@ -237,7 +220,7 @@ sub html_start { sub adump { my ($cb, $mset, $q, $ctx) = @_; my $fh = $cb->([ 200, ['Content-Type' => 'application/atom+xml']]); - my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir}); + my $ibx = $ctx->{-inbox}; my $feed_opts = PublicInbox::Feed::get_feedopts($ctx); my $x = ascii_html($q->{'q'}); $x = qq{$x - search results}; @@ -249,7 +232,7 @@ sub adump { for ($mset->items) { $x = PublicInbox::SearchMsg->load_doc($_->get_document)->mid; $x = mid2path($x); - my $s = PublicInbox::Feed::feed_entry($feed_opts, $x, $git); + my $s = PublicInbox::Feed::feed_entry($feed_opts, $x, $ibx); $fh->write($s) if defined $s; } PublicInbox::Feed::end_feed($fh);