* [PATCH 2/3] viewvcs: use git(1) for coderepo access
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 ` Eric Wong
2023-01-13 10:35 ` [PATCH 3/3] coderepo: consolidate git --batch-check users Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2023-01-13 10:35 UTC (permalink / raw)
To: meta
libgit2 development has fallen behind git.git and I've been
using objectformat=sha256 somewhere else for over 18 months.
Hoist out do_cat_async() into it's own sub to hide generic PSGI
vs -httpd differences while we're at it to save us some code.
---
lib/PublicInbox/ViewVCS.pm | 36 +++++++++++++---------------------
lib/PublicInbox/WwwCoderepo.pm | 9 +--------
2 files changed, 15 insertions(+), 30 deletions(-)
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index e0fdf639..eae5b7f4 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -125,6 +125,17 @@ sub cmt_title { # git->cat_async callback
cmt_finalize($ctx);
}
+sub do_cat_async {
+ my ($ctx, $cb, @oids) = @_;
+ # favor git(1) over Gcf2 (libgit2) for SHA-256 support
+ $ctx->{git}->cat_async($_, $cb, $ctx) for @oids;
+ if ($ctx->{env}->{'pi-httpd.async'}) {
+ PublicInbox::GitAsyncCat::watch_cat($ctx->{git});
+ } else { # synchronous, generic PSGI
+ $ctx->{git}->cat_async_wait;
+ }
+}
+
sub show_commit_start { # ->psgi_qx callback
my ($bref, $ctx) = @_;
if (my $qsp_err = delete $ctx->{-qsp_err}) {
@@ -142,16 +153,7 @@ sub show_commit_start { # ->psgi_qx callback
return cmt_finalize($ctx) if !$P;
@{$ctx->{-cmt_P}} = split(/ /, $P);
@{$ctx->{-cmt_p}} = split(/ /, $p); # abbreviated
- if ($ctx->{env}->{'pi-httpd.async'}) {
- for (@{$ctx->{-cmt_P}}) {
- ibx_async_cat($ctx, $_, \&cmt_title, $ctx);
- }
- } else { # synchronous
- for (@{$ctx->{-cmt_P}}) {
- $ctx->{git}->cat_async($_, \&cmt_title, $ctx);
- }
- $ctx->{git}->cat_async_wait;
- }
+ do_cat_async($ctx, \&cmt_title, @{$ctx->{-cmt_P}});
}
sub ibx_url_for {
@@ -473,12 +475,7 @@ sub show_tag ($$) {
my ($ctx, $res) = @_;
my ($git, $oid) = @$res;
$ctx->{git} = $git;
- if ($ctx->{env}->{'pi-httpd.async'}) {
- ibx_async_cat($ctx, $oid, \&show_tag_result, $ctx);
- } else { # synchronous (generic PSGI)
- $git->cat_async($oid, \&show_tag_result, $ctx);
- $git->cat_async_wait;
- }
+ do_cat_async($ctx, \&show_tag_result, $oid);
}
# user_cb for SolverGit, called as: user_cb->($result_or_error, $uarg)
@@ -508,12 +505,7 @@ EOM
}
bless $ctx, 'PublicInbox::WwwStream'; # for DESTROY
$ctx->{git} = $git;
- if ($ctx->{env}->{'pi-httpd.async'}) {
- ibx_async_cat($ctx, $oid, \&show_blob, $ctx);
- } else { # synchronous
- $git->cat_async($oid, \&show_blob, $ctx);
- $git->cat_async_wait;
- }
+ do_cat_async($ctx, \&show_blob, $oid);
}
sub show_blob { # git->cat_async callback
diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm
index f9c150c0..5ca8ef55 100644
--- a/lib/PublicInbox/WwwCoderepo.pm
+++ b/lib/PublicInbox/WwwCoderepo.pm
@@ -11,8 +11,6 @@ use File::Temp 0.19 (); # newdir
use PublicInbox::ViewVCS;
use PublicInbox::WwwStatic qw(r);
use PublicInbox::GitHTTPBackend;
-use PublicInbox::Git;
-use PublicInbox::GitAsyncCat;
use PublicInbox::WwwStream;
use PublicInbox::Hval qw(ascii_html);
use PublicInbox::ViewDiff qw(uri_escape_path);
@@ -199,12 +197,7 @@ sub summary {
$tip //= 'HEAD';
my @try = ("$tip:README", "$tip:README.md"); # TODO: configurable
$ctx->{-nr_readme_tries} = [ @try ];
- $ctx->{git}->cat_async($_, \&set_readme, $ctx) for @try;
- if ($ctx->{env}->{'pi-httpd.async'}) {
- PublicInbox::GitAsyncCat::watch_cat($ctx->{git});
- } else { # synchronous
- $ctx->{git}->cat_async_wait;
- }
+ PublicInbox::ViewVCS::do_cat_async($ctx, \&set_readme, @try);
sub { # $_[0] => PublicInbox::HTTP::{Identity,Chunked}
$ctx->{env}->{'qspawn.wcb'} = $_[0];
$qsp->psgi_qx($ctx->{env}, undef, \&capture_refs, $ctx);
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] coderepo: consolidate git --batch-check users
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
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2023-01-13 10:35 UTC (permalink / raw)
To: meta
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}) {
^ permalink raw reply related [flat|nested] 4+ messages in thread