From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/3] coderepo: consolidate git --batch-check users
Date: Fri, 13 Jan 2023 10:35:50 +0000 [thread overview]
Message-ID: <20230113103550.3020126-4-e@80x24.org> (raw)
In-Reply-To: <20230113103550.3020126-1-e@80x24.org>
And another opportunity to simplify our code between different
PSGI-ish implementations. The snapshot retrieval is simpler,
but potentially slower since we waste cycles scanning for tags
even after we've found one. It's probably not a big deal since
it's only short info lines and we can utilize pipelining.
---
lib/PublicInbox/RepoSnapshot.pm | 51 +++++++++++++--------------------
lib/PublicInbox/RepoTree.pm | 8 +-----
lib/PublicInbox/ViewVCS.pm | 14 +++++++--
3 files changed, 33 insertions(+), 40 deletions(-)
diff --git a/lib/PublicInbox/RepoSnapshot.pm b/lib/PublicInbox/RepoSnapshot.pm
index 826392a8..93ba4db6 100644
--- a/lib/PublicInbox/RepoSnapshot.pm
+++ b/lib/PublicInbox/RepoSnapshot.pm
@@ -4,9 +4,8 @@
# cgit-compatible /snapshot/ endpoint for WWW coderepos
package PublicInbox::RepoSnapshot;
use v5.12;
-use PublicInbox::Git;
use PublicInbox::Qspawn;
-use PublicInbox::GitAsyncCat;
+use PublicInbox::ViewVCS;
use PublicInbox::WwwStatic qw(r);
# Not using standard mime types since the compressed tarballs are
@@ -42,31 +41,25 @@ sub archive_hdr { # parse_hdr for Qspawn
'ETag', qq("$ctx->{etag}") ] ];
}
-sub archive_cb {
- my ($ctx) = @_;
- my @cfg;
- if (my $cmd = $FMT_CFG{$ctx->{snap_fmt}}) {
- @cfg = ('-c', "tar.$ctx->{snap_fmt}.command=$cmd");
- }
- my $qsp = PublicInbox::Qspawn->new(['git', @cfg,
- "--git-dir=$ctx->{git}->{git_dir}", 'archive',
- "--prefix=$ctx->{snap_pfx}/",
- "--format=$ctx->{snap_fmt}", $ctx->{treeish}]);
- $qsp->psgi_return($ctx->{env}, undef, \&archive_hdr, $ctx);
-}
-
sub ver_check { # git->check_async callback
my ($oid, $type, $size, $ctx) = @_;
- if ($type eq 'missing') { # try 'v' and 'V' prefixes
- my $pfx = shift @{$ctx->{try_pfx}} or return
+ return if defined $ctx->{etag};
+ my $treeish = shift @{$ctx->{-try}} // die 'BUG: no {-try}';
+ if ($type eq 'missing') {
+ scalar(@{$ctx->{-try}}) or
delete($ctx->{env}->{'qspawn.wcb'})->(r(404));
- my $v = $ctx->{treeish} = $pfx.$ctx->{snap_ver};
- return $ctx->{env}->{'pi-httpd.async'} ?
- async_check($ctx, $v, \&ver_check, $ctx) :
- $ctx->{git}->check_async($v, \&ver_check, $ctx);
+ } else { # found, done:
+ $ctx->{etag} = $oid;
+ my @cfg;
+ if (my $cmd = $FMT_CFG{$ctx->{snap_fmt}}) {
+ @cfg = ('-c', "tar.$ctx->{snap_fmt}.command=$cmd");
+ }
+ my $qsp = PublicInbox::Qspawn->new(['git', @cfg,
+ "--git-dir=$ctx->{git}->{git_dir}", 'archive',
+ "--prefix=$ctx->{snap_pfx}/",
+ "--format=$ctx->{snap_fmt}", $treeish]);
+ $qsp->psgi_return($ctx->{env}, undef, \&archive_hdr, $ctx);
}
- $ctx->{etag} = $oid;
- archive_cb($ctx);
}
sub srv {
@@ -81,16 +74,12 @@ sub srv {
substr($fn, 0, length($pfx)) eq $pfx or return;
$ctx->{snap_pfx} = $fn;
my $v = $ctx->{snap_ver} = substr($fn, length($pfx), length($fn));
- $ctx->{treeish} = $v; # try without [vV] prefix, first
- @{$ctx->{try_pfx}} = qw(v V); # cf. cgit:ui-snapshot.c
+ # try without [vV] prefix, first
+ my @try = map { "$_$v" } ('', 'v', 'V'); # cf. cgit:ui-snapshot.c
+ @{$ctx->{-try}} = @try;
sub {
$ctx->{env}->{'qspawn.wcb'} = $_[0];
- if ($ctx->{env}->{'pi-httpd.async'}) {
- async_check($ctx, $v, \&ver_check, $ctx);
- } else {
- $ctx->{git}->check_async($v, \&ver_check, $ctx);
- $ctx->{git}->check_async_wait;
- }
+ PublicInbox::ViewVCS::do_check_async($ctx, \&ver_check, @try);
}
}
diff --git a/lib/PublicInbox/RepoTree.pm b/lib/PublicInbox/RepoTree.pm
index 84e20589..7434e9b2 100644
--- a/lib/PublicInbox/RepoTree.pm
+++ b/lib/PublicInbox/RepoTree.pm
@@ -5,7 +5,6 @@
package PublicInbox::RepoTree;
use v5.12;
use PublicInbox::ViewDiff qw(uri_escape_path);
-use PublicInbox::GitAsyncCat;
use PublicInbox::WwwStatic qw(r);
use PublicInbox::Qspawn;
use PublicInbox::WwwStream qw(html_oneshot);
@@ -78,12 +77,7 @@ sub srv_tree {
return if index($obj, "\n") >= 0;
sub {
$ctx->{-wcb} = $_[0]; # HTTP::{Chunked,Identity}
- if ($ctx->{env}->{'pi-httpd.async'}) {
- async_check($ctx, $obj, \&tree_show, $ctx);
- } else {
- $ctx->{git}->check_async($obj, \&tree_show, $ctx);
- $ctx->{git}->async_wait_all;
- }
+ PublicInbox::ViewVCS::do_check_async($ctx, \&tree_show, $obj);
};
}
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index eae5b7f4..37b688ed 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -126,9 +126,9 @@ sub cmt_title { # git->cat_async callback
}
sub do_cat_async {
- my ($ctx, $cb, @oids) = @_;
+ my ($ctx, $cb, @req) = @_;
# favor git(1) over Gcf2 (libgit2) for SHA-256 support
- $ctx->{git}->cat_async($_, $cb, $ctx) for @oids;
+ $ctx->{git}->cat_async($_, $cb, $ctx) for @req;
if ($ctx->{env}->{'pi-httpd.async'}) {
PublicInbox::GitAsyncCat::watch_cat($ctx->{git});
} else { # synchronous, generic PSGI
@@ -136,6 +136,16 @@ sub do_cat_async {
}
}
+sub do_check_async {
+ my ($ctx, $cb, @req) = @_;
+ if ($ctx->{env}->{'pi-httpd.async'}) {
+ async_check($ctx, $_, $cb, $ctx) for @req;
+ } else { # synchronous, generic PSGI
+ $ctx->{git}->check_async($_, $cb, $ctx) for @req;
+ $ctx->{git}->check_async_wait;
+ }
+}
+
sub show_commit_start { # ->psgi_qx callback
my ($bref, $ctx) = @_;
if (my $qsp_err = delete $ctx->{-qsp_err}) {
prev parent reply other threads:[~2023-01-13 10:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 10:35 [PATCH 0/3] coderepo-related cleanups + sha256 Eric Wong
2023-01-13 10:35 ` [PATCH 1/3] qspawn: import Scalar::Util::blessed properly Eric Wong
2023-01-13 10:35 ` [PATCH 2/3] viewvcs: use git(1) for coderepo access Eric Wong
2023-01-13 10:35 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230113103550.3020126-4-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).