]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
git: move async detection to runtime
authorEric Wong <e@80x24.org>
Fri, 24 Feb 2017 00:47:45 +0000 (00:47 +0000)
committerEric Wong <e@80x24.org>
Fri, 24 Feb 2017 01:59:33 +0000 (01:59 +0000)
We don't actually know what context we'll be called under,
so detecting the mere use-ability of Danga::Socket is not
sufficient.

lib/PublicInbox/Git.pm
t/git_async.t

index caca3b093148d43c3cf9d5acf34774bf69cc3bd0..3ca0b680d1aafebff36bfbb617c479ba736c63fb 100644 (file)
@@ -274,12 +274,13 @@ sub cat_async_compat ($$$) {
        fail($self, 'newline missing after blob') if ($r != 1 || $buf ne "\n");
 }
 
-if ($have_async) {
-       *check_async = *check_async_ds;
-       *cat_async = *cat_async_ds;
-} else {
-       *check_async = *check_async_compat;
-       *cat_async = *cat_async_compat;
+sub check_async {
+       my ($self, $env, $obj, $cb) = @_;
+       if ($env->{'pi-httpd.async'}) {
+               check_async_ds($self, $obj, $cb);
+       } else {
+               check_async_compat($self, $obj, $cb);
+       }
 }
 
 1;
index c20d48e3bcb702528bb81c57367cbdaebb01a542..4f7e4ebe9ba67a1339d7653f4cd672156ce8d106 100644 (file)
@@ -41,7 +41,7 @@ my $dir = "$tmpdir/git.git";
                }
                0
        });
-       $git->check_async($f, sub {
+       $git->check_async_ds($f, sub {
                $n++;
                @args = @_;
                $git = undef;
@@ -58,7 +58,7 @@ my $dir = "$tmpdir/git.git";
        my $m = 0;
        for my $i (0..$max) {
                my $k = "HEAD:m$i";
-               $git->check_async($k, sub {
+               $git->check_async_ds($k, sub {
                        my ($info) = @_;
                        ++$n;
                        ++$m if $info->[1] eq 'missing' && $info->[0] eq $k;
@@ -70,18 +70,18 @@ my $dir = "$tmpdir/git.git";
                }
        }
        is($m, $n, 'everything expected missing is missing');
-       $git->check_async($f, sub { $git = undef });
+       $git->check_async_ds($f, sub { $git = undef });
        Danga::Socket->EventLoop;
 
        $git = PublicInbox::Git->new($dir);
        my $info;
        my $str = '';
        my @missing;
-       $git->cat_async('HEAD:miss', sub {
+       $git->cat_async_ds('HEAD:miss', sub {
                my ($miss) = @_;
                push @missing, $miss;
        });
-       $git->cat_async($f, sub {
+       $git->cat_async_ds($f, sub {
                my $res = $_[0];
                if (ref($res) eq 'ARRAY') {
                        is($info, undef, 'info unset, setting..');