]> Sergey Matveev's repositories - public-inbox.git/commitdiff
viewvcs: use git(1) for coderepo access
authorEric Wong <e@80x24.org>
Fri, 13 Jan 2023 10:35:49 +0000 (10:35 +0000)
committerEric Wong <e@80x24.org>
Fri, 13 Jan 2023 19:14:25 +0000 (19:14 +0000)
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
lib/PublicInbox/WwwCoderepo.pm

index e0fdf63999c20aaf7e3ce58442d1a12b3b3d15f2..eae5b7f416cf88f8c35823dc5647ef01b0c415ca 100644 (file)
@@ -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
index f9c150c0604a6f6c1b8146b503c9715b5b16c85a..5ca8ef554774a6131560a7406423782e0acb5cb5 100644 (file)
@@ -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);