about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/Gcf2.pm2
-rw-r--r--lib/PublicInbox/Git.pm24
-rw-r--r--lib/PublicInbox/IO.pm26
-rw-r--r--lib/PublicInbox/IdxStack.pm2
-rw-r--r--lib/PublicInbox/Import.pm2
-rw-r--r--lib/PublicInbox/Inbox.pm2
-rw-r--r--lib/PublicInbox/InboxWritable.pm2
-rw-r--r--lib/PublicInbox/LeiALE.pm6
-rw-r--r--lib/PublicInbox/LeiBlob.pm3
-rw-r--r--lib/PublicInbox/LeiConfig.pm2
-rw-r--r--lib/PublicInbox/LeiMailSync.pm3
-rw-r--r--lib/PublicInbox/LeiMirror.pm11
-rw-r--r--lib/PublicInbox/LeiSucks.pm2
-rw-r--r--lib/PublicInbox/MultiGit.pm2
-rw-r--r--lib/PublicInbox/TestCommon.pm4
-rw-r--r--lib/PublicInbox/ViewVCS.pm6
-rw-r--r--lib/PublicInbox/WWW.pm2
-rw-r--r--lib/PublicInbox/XapHelper.pm7
-rw-r--r--lib/PublicInbox/XapHelperCxx.pm3
19 files changed, 54 insertions, 57 deletions
diff --git a/lib/PublicInbox/Gcf2.pm b/lib/PublicInbox/Gcf2.pm
index 6ee0d7d9..5490049d 100644
--- a/lib/PublicInbox/Gcf2.pm
+++ b/lib/PublicInbox/Gcf2.pm
@@ -37,7 +37,7 @@ BEGIN {
                 $vals->{$k} = $val;
         }
         my $f = "$dir/gcf2_libgit2.h";
-        $c_src = PublicInbox::Git::try_cat($f) or die "cat $f: $!";
+        $c_src = PublicInbox::IO::try_cat $f or die "cat $f: $!";
         # append pkg-config results to the source to ensure Inline::C
         # can rebuild if there's changes (it doesn't seem to detect
         # $CFG{CCFLAGSEX} nor $CFG{CPPFLAGS} changes)
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index d00f576e..11712db2 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -18,16 +18,14 @@ use Errno qw(EINTR EAGAIN);
 use File::Glob qw(bsd_glob GLOB_NOSORT);
 use File::Spec ();
 use PublicInbox::Spawn qw(spawn popen_rd run_qx which);
-use PublicInbox::IO;
+use PublicInbox::IO qw(poll_in read_all try_cat);
 use PublicInbox::Tmpfile;
-use IO::Poll qw(POLLIN);
 use Carp qw(croak carp);
 use PublicInbox::SHA qw(sha_all);
 our %HEXLEN2SHA = (40 => 1, 64 => 256);
 our %OFMT2HEXLEN = (sha1 => 40, sha256 => 64);
-our @EXPORT_OK = qw(git_unquote git_quote %HEXLEN2SHA %OFMT2HEXLEN read_all);
+our @EXPORT_OK = qw(git_unquote git_quote %HEXLEN2SHA %OFMT2HEXLEN);
 our $in_cleanup;
-our $RDTIMEO = 60_000; # milliseconds
 our $async_warn; # true in read-only daemons
 
 # committerdate:unix is git 2.9.4+ (2017-05-05), so using raw instead
@@ -168,8 +166,6 @@ sub _sock_cmd {
         $self->{sock} = PublicInbox::IO::attach_pid($s1, $pid);
 }
 
-sub poll_in ($) { IO::Poll::_poll($RDTIMEO, fileno($_[0]), my $ev = POLLIN) }
-
 sub my_read ($$$) {
         my ($fh, $rbuf, $len) = @_;
         my $left = $len - length($$rbuf);
@@ -555,22 +551,6 @@ sub modified ($;$) {
         (split(/ /, <$fh> // time))[0] + 0; # integerize for JSON
 }
 
-# read_all/try_cat can probably be moved somewhere else...
-
-sub read_all ($;$$) {
-        my ($fh, $len, $bref) = @_;
-        $bref //= \(my $buf);
-        my $r = read($fh, $$bref, $len //= -s $fh);
-        croak("$fh read ($r != $len)") if $len != $r;
-        $$bref;
-}
-
-sub try_cat {
-        my ($path) = @_;
-        open(my $fh, '<', $path) or return '';
-        read_all($fh);
-}
-
 sub cat_desc ($) {
         my $desc = try_cat($_[0]);
         chomp $desc;
diff --git a/lib/PublicInbox/IO.pm b/lib/PublicInbox/IO.pm
index 4c92566d..0d303500 100644
--- a/lib/PublicInbox/IO.pm
+++ b/lib/PublicInbox/IO.pm
@@ -6,10 +6,9 @@ package PublicInbox::IO;
 use v5.12;
 use parent qw(IO::Handle Exporter);
 use PublicInbox::DS qw(awaitpid);
-our @EXPORT_OK = qw(write_file);
-
-# TODO: this can probably be the new home for read_all, try_cat
-# and maybe even buffered read/readline...
+our @EXPORT_OK = qw(poll_in read_all try_cat write_file);
+use Carp qw(croak);
+use IO::Poll qw(POLLIN);
 
 sub waitcb { # awaitpid callback
         my ($pid, $errref, $cb, @args) = @_;
@@ -59,4 +58,23 @@ sub write_file ($$@) { # mode, filename, LIST (for print)
         defined(wantarray) && !wantarray ? $fh : close $fh;
 }
 
+sub poll_in ($;$) {
+        IO::Poll::_poll($_[1] // -1, fileno($_[0]), my $ev = POLLIN);
+}
+
+sub read_all ($;$$) {
+        use autodie qw(read);
+        my ($io, $len, $bref) = @_;
+        $bref //= \(my $buf);
+        my $r = read($io, $$bref, $len //= -s $io);
+        croak("read($io) ($r != $len)") if $len != $r;
+        $$bref;
+}
+
+sub try_cat ($) {
+        my ($path) = @_;
+        open(my $fh, '<', $path) or return '';
+        read_all $fh;
+}
+
 1;
diff --git a/lib/PublicInbox/IdxStack.pm b/lib/PublicInbox/IdxStack.pm
index cc9e0125..7681ee6f 100644
--- a/lib/PublicInbox/IdxStack.pm
+++ b/lib/PublicInbox/IdxStack.pm
@@ -8,7 +8,7 @@ use v5.12;
 use Fcntl qw(:seek);
 use constant PACK_FMT => eval { pack('Q', 1) } ? 'A1QQH*H*' : 'A1IIH*H*';
 use autodie qw(open seek);
-use PublicInbox::Git qw(read_all);
+use PublicInbox::IO qw(read_all);
 
 # start off in write-only mode
 sub new {
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 5b0201c6..2d60db55 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -21,7 +21,7 @@ use POSIX qw(strftime);
 use autodie qw(socketpair);
 use Carp qw(croak);
 use Socket qw(AF_UNIX SOCK_STREAM);
-use PublicInbox::Git qw(read_all);
+use PublicInbox::IO qw(read_all);
 
 sub default_branch () {
         state $default_branch = do {
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index b31f3fff..e71ef6d2 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -189,7 +189,7 @@ sub cloneurl {
         my ($self) = @_;
         $self->{cloneurl} // do {
                 my @urls = split(/\s+/s,
-                  PublicInbox::Git::try_cat("$self->{inboxdir}/cloneurl"));
+                        PublicInbox::IO::try_cat "$self->{inboxdir}/cloneurl");
                 scalar(@urls) ? ($self->{cloneurl} = \@urls) : undef;
         } // [];
 }
diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index 6af72e71..8e95cb28 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -7,7 +7,7 @@ use strict;
 use v5.10.1;
 use parent qw(PublicInbox::Inbox PublicInbox::Umask Exporter);
 use PublicInbox::Import;
-use PublicInbox::Git qw(read_all);
+use PublicInbox::IO qw(read_all);
 use PublicInbox::Filter::Base qw(REJECT);
 use Errno qw(ENOENT);
 our @EXPORT_OK = qw(eml_from_path);
diff --git a/lib/PublicInbox/LeiALE.pm b/lib/PublicInbox/LeiALE.pm
index 674d897e..528de22c 100644
--- a/lib/PublicInbox/LeiALE.pm
+++ b/lib/PublicInbox/LeiALE.pm
@@ -8,7 +8,7 @@
 package PublicInbox::LeiALE;
 use v5.12;
 use parent qw(PublicInbox::LeiSearch PublicInbox::Lock);
-use PublicInbox::Git qw(read_all);
+use PublicInbox::Git;
 use autodie qw(close open rename seek truncate);
 use PublicInbox::Import;
 use PublicInbox::LeiXSearch;
@@ -54,7 +54,7 @@ sub refresh_externals {
         $self->git->cleanup;
         my $lk = $self->lock_for_scope;
         my $cur_lxs = ref($lxs)->new;
-        my $orig = read_all($self->{lockfh});
+        my $orig = PublicInbox::IO::read_all $self->{lockfh};
         my $new = '';
         my $old = '';
         my $gone = 0;
@@ -86,7 +86,7 @@ sub refresh_externals {
         }
         $new = '';
         my $f = $self->git->{git_dir}.'/objects/info/alternates';
-        $old = PublicInbox::Git::try_cat($f);
+        $old = PublicInbox::IO::try_cat $f;
         for my $x (@ibxish) {
                 $new .= $lei->canonpath_harder($x->git->{git_dir})."/objects\n";
         }
diff --git a/lib/PublicInbox/LeiBlob.pm b/lib/PublicInbox/LeiBlob.pm
index 648d35b6..127cc81e 100644
--- a/lib/PublicInbox/LeiBlob.pm
+++ b/lib/PublicInbox/LeiBlob.pm
@@ -10,7 +10,8 @@ use parent qw(PublicInbox::IPC);
 use PublicInbox::Spawn qw(run_wait run_qx which);
 use PublicInbox::DS;
 use PublicInbox::Eml;
-use PublicInbox::Git qw(read_all);
+use PublicInbox::Git;
+use PublicInbox::IO qw(read_all);
 
 sub get_git_dir ($$) {
         my ($lei, $d) = @_;
diff --git a/lib/PublicInbox/LeiConfig.pm b/lib/PublicInbox/LeiConfig.pm
index b915d787..a50ff2b6 100644
--- a/lib/PublicInbox/LeiConfig.pm
+++ b/lib/PublicInbox/LeiConfig.pm
@@ -5,7 +5,7 @@ use v5.12;
 use PublicInbox::PktOp;
 use Fcntl qw(SEEK_SET);
 use autodie qw(open seek);
-use PublicInbox::Git qw(read_all);
+use PublicInbox::IO qw(read_all);
 
 sub cfg_do_edit ($;$) {
         my ($self, $reason) = @_;
diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm
index 74ef1362..17254a82 100644
--- a/lib/PublicInbox/LeiMailSync.pm
+++ b/lib/PublicInbox/LeiMailSync.pm
@@ -10,7 +10,8 @@ use PublicInbox::Compat qw(uniqstr);
 use DBI qw(:sql_types); # SQL_BLOB
 use PublicInbox::ContentHash qw(git_sha);
 use Carp ();
-use PublicInbox::Git qw(%HEXLEN2SHA read_all);
+use PublicInbox::Git qw(%HEXLEN2SHA);
+use PublicInbox::IO qw(read_all);
 
 sub dbh_new {
         my ($self) = @_;
diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index e4914f75..49febe9e 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -17,7 +17,6 @@ use Carp qw(croak);
 use URI;
 use PublicInbox::Config qw(glob2re);
 use PublicInbox::Inbox;
-use PublicInbox::Git qw(read_all);
 use PublicInbox::LeiCurl;
 use PublicInbox::OnDestroy;
 use PublicInbox::SHA qw(sha256_hex sha_all);
@@ -174,7 +173,7 @@ sub _get_txt_done { # returns true on error (non-fatal), undef on success
         return warn("# @$cmd failed (non-fatal)\n") if $cerr;
         seek($fh, 0, SEEK_SET);
         $self->{"mtime.$endpoint"} = (stat($fh))[9];
-        $self->{"txt.$endpoint"} = read_all($fh, -s _);
+        $self->{"txt.$endpoint"} = PublicInbox::IO::read_all $fh, -s _;
         undef; # success
 }
 
@@ -207,7 +206,7 @@ sub _write_inbox_config {
 sub set_description ($) {
         my ($self) = @_;
         my $dst = $self->{cur_dst} // $self->{dst};
-        chomp(my $orig = PublicInbox::Git::try_cat("$dst/description"));
+        chomp(my $orig = PublicInbox::IO::try_cat("$dst/description"));
         my $d = $orig;
         while (defined($d) && ($d =~ m!^\(\$INBOX_DIR/description missing\)! ||
                         $d =~ /^Unnamed repository/ || $d !~ /\S/)) {
@@ -806,7 +805,7 @@ sub update_ent {
         }
         if (defined(my $t = $self->{-ent}->{modified})) {
                 my ($dn, $bn) = ("$dst/info/web", 'last-modified');
-                my $orig = PublicInbox::Git::try_cat("$dn/$bn");
+                my $orig = PublicInbox::IO::try_cat("$dn/$bn");
                 $t = strftime('%F %T', gmtime($t))." +0000\n";
                 File::Path::mkpath($dn);
                 atomic_write($dn, $bn, $t) if $orig ne $t;
@@ -936,7 +935,7 @@ failed to extract epoch number from $src
 sub decode_manifest ($$$) {
         my ($fh, $fn, $uri) = @_;
         my $js;
-        my $gz = read_all($fh);
+        my $gz = PublicInbox::IO::read_all $fh;
         gunzip(\$gz => \$js, MultiStream => 1) or
                 die "gunzip($uri): $GunzipError\n";
         my $m = eval { PublicInbox::Config->json->decode($js) };
@@ -1083,7 +1082,7 @@ sub dump_manifest ($$) {
 sub dump_project_list ($$) {
         my ($self, $m) = @_;
         my $f = $self->{'-project-list'};
-        my $old = defined($f) ? PublicInbox::Git::try_cat($f) : '';
+        my $old = defined($f) ? PublicInbox::IO::try_cat($f) : '';
         my %new;
 
         open my $dh, '<', '.';
diff --git a/lib/PublicInbox/LeiSucks.pm b/lib/PublicInbox/LeiSucks.pm
index 82aea8d4..ddb3faf7 100644
--- a/lib/PublicInbox/LeiSucks.pm
+++ b/lib/PublicInbox/LeiSucks.pm
@@ -12,7 +12,7 @@ use Config;
 use POSIX ();
 use PublicInbox::Config;
 use PublicInbox::IPC;
-use PublicInbox::Git qw(read_all);
+use PublicInbox::IO qw(read_all);
 
 sub lei_sucks {
         my ($lei, @argv) = @_;
diff --git a/lib/PublicInbox/MultiGit.pm b/lib/PublicInbox/MultiGit.pm
index 1e8eb47a..b7691806 100644
--- a/lib/PublicInbox/MultiGit.pm
+++ b/lib/PublicInbox/MultiGit.pm
@@ -9,7 +9,7 @@ use PublicInbox::Spawn qw(run_die run_qx);
 use PublicInbox::Import;
 use File::Temp 0.19;
 use List::Util qw(max);
-use PublicInbox::Git qw(read_all);
+use PublicInbox::IO qw(read_all);
 use autodie qw(chmod close rename);
 
 sub new {
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 5ad12942..83e99b42 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -48,8 +48,8 @@ sub require_bsd (;$) {
 sub xbail (@) { BAIL_OUT join(' ', map { ref() ? (explain($_)) : ($_) } @_) }
 
 sub read_all ($;$$) {
-        require PublicInbox::Git;
-        PublicInbox::Git::read_all($_[0], $_[1], $_[2])
+        require PublicInbox::IO;
+        PublicInbox::IO::read_all($_[0], $_[1], $_[2])
 }
 
 sub eml_load ($) {
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 6c588ddf..be062f36 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -17,7 +17,7 @@ use strict;
 use v5.10.1;
 use File::Temp 0.19 (); # newdir
 use PublicInbox::SolverGit;
-use PublicInbox::Git qw(read_all);
+use PublicInbox::Git;
 use PublicInbox::GitAsyncCat;
 use PublicInbox::WwwStream qw(html_oneshot);
 use PublicInbox::Linkify;
@@ -62,7 +62,7 @@ sub dbg_log ($) {
                 warn "seek(log): $!";
                 return '<pre>debug log seek error</pre>';
         }
-        $log = eval { read_all($log) } // do {
+        $log = eval { PublicInbox::IO::read_all $log } // do {
                 warn "read(log): $@";
                 return '<pre>debug log read error</pre>';
         };
@@ -248,7 +248,7 @@ EOM
         if (-s $fh > $MAX_SIZE) {
                 print $zfh "---\n patch is too large to show\n";
         } else { # prepare flush_diff:
-                read_all($fh, -s _, \$x);
+                PublicInbox::IO::read_all $fh, -s _, \$x;
                 utf8_maybe($x);
                 $ctx->{-apfx} = $ctx->{-spfx} = $upfx;
                 $x =~ s/\r?\n/\n/gs;
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 183c5df7..d2bd68ea 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -588,7 +588,7 @@ sub stylesheets_prepare ($$) {
                                 next;
                         };
                         my $ctime = 0;
-                        my $local = PublicInbox::Git::read_all($fh, -s $fh);
+                        my $local = PublicInbox::IO::read_all $fh; # sets _
                         if ($local =~ /\S/) {
                                 $ctime = sprintf('%x',(stat(_))[10]);
                                 $local = $mini->($local);
diff --git a/lib/PublicInbox/XapHelper.pm b/lib/PublicInbox/XapHelper.pm
index 41c66a12..1ee918e3 100644
--- a/lib/PublicInbox/XapHelper.pm
+++ b/lib/PublicInbox/XapHelper.pm
@@ -10,7 +10,7 @@ $GLP->configure(qw(require_order bundling no_ignore_case no_auto_abbrev));
 use PublicInbox::Search qw(xap_terms);
 use PublicInbox::CodeSearch;
 use PublicInbox::IPC;
-use PublicInbox::Git qw(read_all);
+use PublicInbox::IO qw(read_all);
 use Socket qw(SOL_SOCKET SO_TYPE SOCK_SEQPACKET AF_UNIX);
 use PublicInbox::DS qw(awaitpid);
 use autodie qw(open getsockopt);
@@ -125,9 +125,8 @@ sub cmd_dump_roots {
         $req->{A} or return warn('dump_roots requires -A PREFIX');
         open my $fh, '<', $root2id_file;
         my $root2id; # record format: $OIDHEX "\0" uint32_t
-        my @x = split(/\0/, read_all($fh));
-        while (@x) {
-                my $oidhex = shift @x;
+        my @x = split(/\0/, read_all $fh);
+        while (defined(my $oidhex = shift @x)) {
                 $root2id->{$oidhex} = shift @x;
         }
         my $opt = { relevance => -1, limit => $req->{'m'},
diff --git a/lib/PublicInbox/XapHelperCxx.pm b/lib/PublicInbox/XapHelperCxx.pm
index 83503035..908a71f4 100644
--- a/lib/PublicInbox/XapHelperCxx.pm
+++ b/lib/PublicInbox/XapHelperCxx.pm
@@ -8,7 +8,6 @@
 package PublicInbox::XapHelperCxx;
 use v5.12;
 use PublicInbox::Spawn qw(run_qx which);
-use PublicInbox::Git qw(read_all);
 use PublicInbox::Search;
 use Fcntl qw(SEEK_SET);
 use Config;
@@ -67,7 +66,7 @@ sub build () {
         for (@srcs) {
                 say $fh qq(# line 1 "$_");
                 open my $rfh, '<', $_;
-                print $fh read_all($rfh);
+                print $fh PublicInbox::IO::read_all $rfh;
         }
         print $fh PublicInbox::Search::generate_cxx();
         print $fh PublicInbox::CodeSearch::generate_cxx();