From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id E4D6F1F526 for ; Sat, 8 Oct 2022 08:24:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1665217490; bh=k8UkyELJQB+ZDVPp+PrvYKlHaTeoDfD5aWE5tOcr7fA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ysetbmr3otRyLCVx0udxQ82W3y8X8SPrV2Y6QrpGawodcUHUYNer1uOBE+ymuuBYt lstp2pRFRA0lDj6Fn4uwx8zZ25ZRL4Wq7t3cTQOamjE2Y967ujcL5AzZoHanV4WGyr 0yiYVa97mFZMhBYwJhlj2FxXhkEwjL8g+X7zcKmI= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/5] www_coderepo: allow searching one extindex|inbox Date: Sat, 8 Oct 2022 08:24:48 +0000 Message-Id: <20221008082448.9856-6-e@80x24.org> In-Reply-To: <20221008082448.9856-1-e@80x24.org> References: <20221008082448.9856-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: I'm not sure how to best make a UI for one coderepo to many inboxes/extindices, yet; but at least allow a simple 1:1 mapping, for now. This ensures /$CODEREPO/$OID/s/ can work as effectively as /$INBOX/$OID/s/ when looking for emails associated with a git commit. --- lib/PublicInbox/Config.pm | 5 +++++ lib/PublicInbox/Inbox.pm | 3 ++- lib/PublicInbox/ViewVCS.pm | 31 +++++++++++++++++++++++++++---- lib/PublicInbox/WwwCoderepo.pm | 14 ++++++++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index a430cd5c..c27928de 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -404,6 +404,11 @@ sub repo_objs { push @repo_objs, $repo if $repo; } if (scalar @repo_objs) { + require Scalar::Util; + for (@repo_objs) { + push @{$_->{-ibxs}}, $ibxish; + Scalar::Util::weaken($_->{-ibxs}->[-1]); + } $ibxish->{-repo_objs} = \@repo_objs; } else { delete $ibxish->{coderepo}; diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 3532bb58..cb98d2ad 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -205,7 +205,8 @@ sub base_url { $url .= '/' if $url !~ m!/\z!; return $url .= $self->{name} . '/'; } - # called from a non-PSGI environment (e.g. NNTP/POP3): + # called from a non-PSGI environment or cross-inbox environment + # where multiple inboxes can have different domains my $url = $self->{url} // return undef; $url = $url->[0] // return undef; # expand protocol-relative URLs to HTTPS if we're diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm index 6ada03e6..72b79ab7 100644 --- a/lib/PublicInbox/ViewVCS.pm +++ b/lib/PublicInbox/ViewVCS.pm @@ -25,7 +25,7 @@ use PublicInbox::ViewDiff qw(flush_diff uri_escape_path); use PublicInbox::View; use PublicInbox::Eml; use Text::Wrap qw(wrap); -use PublicInbox::Hval qw(ascii_html to_filename); +use PublicInbox::Hval qw(ascii_html to_filename prurl); my $hl = eval { require PublicInbox::HlMod; PublicInbox::HlMod->new; @@ -152,6 +152,25 @@ sub show_commit_start { # ->psgi_qx callback } } +sub ibx_url_for { + my ($ctx) = @_; + $ctx->{ibx} and return; # just fall back to $upfx + $ctx->{git} or return; # /$CODEREPO/$OID/s/ to (eidx|ibx) + if (my $ALL = $ctx->{www}->{pi_cfg}->ALL) { + $ALL->base_url // $ALL->base_url($ctx->{env}); + } elsif (my $ibxs = $ctx->{git}->{-ibxs}) { + for my $ibx (@$ibxs) { + if ($ibx->isrch) { + return defined($ibx->{url}) ? + prurl($ctx->{env}, $ibx->{url}) : + "../../../$ibx->{name}/"; + } + } + } else { + undef; + } +} + sub cmt_finalize { my ($ctx) = @_; $ctx->{-linkify} //= PublicInbox::Linkify->new; @@ -227,12 +246,16 @@ EOM $q = wrap('', '', $q); my $rows = ($q =~ tr/\n/\n/) + 1; $q = ascii_html($q); + my $ibx_url = ibx_url_for($ctx); + my $alt = $ibx_url ? ' '.ascii_html($ibx_url) : ''; + $ibx_url = ascii_html($ibx_url) if defined $ibx_url; + $ibx_url //= $upfx; print $zfh <
find related emails, including ancestors/descendants/conflicts
 
-\t(help)
+\t(help) EOM } } diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm index 2184e89d..99df39ef 100644 --- a/lib/PublicInbox/WwwCoderepo.pm +++ b/lib/PublicInbox/WwwCoderepo.pm @@ -35,6 +35,20 @@ sub prepare_coderepos { $k = substr($k, length('coderepo.'), -length('.dir')); $code_repos->{$k} //= $pi_cfg->fill_code_repo($k); } + + # associate inboxes and extindices with coderepos for search: + for my $k (grep(/\Apublicinbox\.(?:.+)\.coderepo\z/, keys %$pi_cfg)) { + $k = substr($k, length('publicinbox.'), -length('.coderepo')); + my $ibx = $pi_cfg->lookup_name($k) // next; + $pi_cfg->repo_objs($ibx); + push @{$self->{-strong}}, $ibx; # strengthen {-ibxs} weakref + } + for my $k (grep(/\Aextindex\.(?:.+)\.coderepo\z/, keys %$pi_cfg)) { + $k = substr($k, length('extindex.'), -length('.coderepo')); + my $eidx = $pi_cfg->lookup_ei($k) // next; + $pi_cfg->repo_objs($eidx); + push @{$self->{-strong}}, $eidx; # strengthen {-ibxs} weakref + } while (my ($nick, $repo) = each %$code_repos) { $self->{"\0$nick"} = $repo; }