about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-01-13 10:35:49 +0000
committerEric Wong <e@80x24.org>2023-01-13 19:14:25 +0000
commitd967c043322e636fd6ff810d54b70d8cd9fe91df (patch)
treec2da41aab7fab575e875449eff6991b66de3b1a4
parentaff26bf4657de76d77da4a1328ac5c4defc8ccfd (diff)
downloadpublic-inbox-d967c043322e636fd6ff810d54b70d8cd9fe91df.tar.gz
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.
-rw-r--r--lib/PublicInbox/ViewVCS.pm36
-rw-r--r--lib/PublicInbox/WwwCoderepo.pm9
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);