user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/3] viewvcs: use git(1) for coderepo access
Date: Fri, 13 Jan 2023 10:35:49 +0000	[thread overview]
Message-ID: <20230113103550.3020126-3-e@80x24.org> (raw)
In-Reply-To: <20230113103550.3020126-1-e@80x24.org>

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);

  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 ` Eric Wong [this message]
2023-01-13 10:35 ` [PATCH 3/3] coderepo: consolidate git --batch-check users Eric Wong

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-3-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).