$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)
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
$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);
(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;
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) = @_;
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;
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 {
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 {
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;
} // [];
}
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);
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;
$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;
}
$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";
}
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) = @_;
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) = @_;
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) = @_;
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);
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
}
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/)) {
}
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;
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) };
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, '<', '.';
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) = @_;
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 {
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 ($) {
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;
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>';
};
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;
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);
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);
$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'},
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;
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();
$state = 'commit';
} elsif (/^data ([0-9]+)/) {
print $io $_ or $im->wfail;
- print $io PublicInbox::Git::read_all($rd, $1) or $im->wfail;
+ print $io PublicInbox::IO::read_all($rd, $1) or $im->wfail;
next;
} elsif ($state eq 'commit') {
if (m{^M 100644 :([0-9]+) (${h}{2}/${h}{38})}o) {
use PublicInbox::Eml;
use PublicInbox::InboxWritable qw(eml_from_path);
use PublicInbox::Import;
-use PublicInbox::Git qw(read_all);
my $help = <<'EOF';
usage: public-inbox-edit -m MESSAGE-ID [--all] [INBOX_DIRS]
# rename/relink $edit_fn
open my $new_fh, '<', $edit_fn or
die "can't read edited file ($edit_fn): $!\n";
- my $new_raw = read_all($new_fh);
+ my $new_raw = PublicInbox::IO::read_all $new_fh;
if (!$opt->{raw}) {
PublicInbox::Eml::strip_from($new_raw);
my $perm = 0644 & ~umask;
my %seen;
if (-e $pi_config) {
- require PublicInbox::Git;
+ require PublicInbox::IO;
open(my $oh, '<', $pi_config);
my @st = stat($oh) or die "(f)stat failed on $pi_config: $!\n";
$perm = $st[2];
chmod($perm & 07777, $fh);
- print $fh PublicInbox::Git::read_all($oh);
+ print $fh PublicInbox::IO::read_all($oh);
close $oh;
# yes, this conflict checking is racy if multiple instances of this
# (see c4201214cbf10636e2c1ab9131573f735b42c8d4 in linux.git)
my $zp = create_coderepo 'NUL in patch', sub {
require PublicInbox::Git;
- my $src = PublicInbox::Git::try_cat("$pwd/COPYING");
+ my $src = PublicInbox::IO::try_cat("$pwd/COPYING");
xsys_e([qw(git init -q)]);
# needs to be further than FIRST_FEW_BYTES (8000) in git.git
"\xc4\x80lice\n", 'a.git gitweb.owner set');
is(xqx([qw(git config gitweb.owner)], { GIT_DIR => "$tmpdir/dst/b.git" }),
"Bob\n", 'b.git gitweb.owner set');
-my $desc = PublicInbox::Git::try_cat("$tmpdir/dst/a.git/description");
+my $desc = PublicInbox::IO::try_cat("$tmpdir/dst/a.git/description");
is($desc, "\xc4\x80lice's repo\n", 'description set');
my $dst_pl = "$tmpdir/dst/projects.list";
my $r = $read_manifest->($dst_mf);
is_deeply($r, $m, 'manifest matches');
-is(PublicInbox::Git::try_cat($dst_pl), "a.git\nb.git\n",
+is(PublicInbox::IO::try_cat($dst_pl), "a.git\nb.git\n",
'wrote projects.list');
{ # check symlinks
utime($t0, $t0, $dst_mf) or xbail "utime: $!";
ok(run_script($cmd), 'clone again +symlinks');
ok(-l "$tmpdir/dst/old/a.git", 'symlink created');
- is(PublicInbox::Git::try_cat($dst_pl), "a.git\nb.git\n",
+ is(PublicInbox::IO::try_cat($dst_pl), "a.git\nb.git\n",
'projects.list does not include symlink by default');
$r = $read_manifest->($dst_mf);
utime($t0, $t0, $dst_mf) or xbail "utime: $!";
my $rdr = { 2 => \(my $err = '') };
ok(run_script($cmd, undef, $rdr), 'clone again for expired gone.git');
- is(PublicInbox::Git::try_cat($dst_pl), "a.git\nb.git\n",
+ is(PublicInbox::IO::try_cat($dst_pl), "a.git\nb.git\n",
'project list cleaned');
like($err, qr/no longer exist.*\bgone\.git\b/s, 'gone.git noted');
}
my $rdr = { 2 => \(my $err = '') };
my $xcmd = [ @$cmd, '--purge' ];
ok(run_script($xcmd, undef, $rdr), 'clone again for expired gone.git');
- is(PublicInbox::Git::try_cat($dst_pl), "a.git\nb.git\n",
+ is(PublicInbox::IO::try_cat($dst_pl), "a.git\nb.git\n",
'project list cleaned');
like($err, qr!ignored/gone.*?\bgone-rdonly\.git\b!s,
'gone-rdonly.git noted');
umask($umask) // xbail "umask: $!";
ok(-d "$tmpdir/a/b/c/d", 'directory created');
my $desc = "$tmpdir/a/b/c/d/description";
- is(PublicInbox::Git::try_cat($desc),
+ is(PublicInbox::IO::try_cat($desc),
"public inbox for abcd\@example.com\n", 'description set');
my $mode = (stat($desc))[2];
is(sprintf('0%03o', $mode & 0777), '0644',
lei_ok('add-external', $t1, '--mirror', "$http/t1/", \'--mirror v1');
my $mm_dup = "$t1/public-inbox/msgmap.sqlite3";
ok(-f $mm_dup, 't1-mirror indexed');
- is(PublicInbox::Git::try_cat("$t1/description"),
+ is(PublicInbox::IO::try_cat("$t1/description"),
"mirror of $http/t1/\n", 'description set');
ok(-f "$t1/Makefile", 'convenience Makefile added (v1)');
SKIP: {
ok(-f $mm_dup, 't2-mirror indexed');
ok(-f "$t2/description", 't2 description');
ok(-f "$t2/Makefile", 'convenience Makefile added (v2)');
- is(PublicInbox::Git::try_cat("$t2/description"),
+ is(PublicInbox::IO::try_cat("$t2/description"),
"mirror of $http/t2/\n", 'description set');
$tb = PublicInbox::Msgmap->new_file($mm_dup)->created_at;
is($tb, $created{v2}, 'created_at matched in v2 mirror');
my $exp = "mirror of https://example.com/src/\n";
my $f = "$tmpdir/description";
PublicInbox::LeiMirror::set_description($mrr);
- is(PublicInbox::Git::try_cat($f), $exp, 'description set on ENOENT');
+ is(PublicInbox::IO::try_cat($f), $exp, 'description set on ENOENT');
my $fh;
(open($fh, '>', $f) and close($fh)) or xbail $!;
PublicInbox::LeiMirror::set_description($mrr);
- is(PublicInbox::Git::try_cat($f), $exp, 'description set on empty');
+ is(PublicInbox::IO::try_cat($f), $exp, 'description set on empty');
(open($fh, '>', $f) and print $fh "x\n" and close($fh)) or xbail $!;
- is(PublicInbox::Git::try_cat($f), "x\n",
+ is(PublicInbox::IO::try_cat($f), "x\n",
'description preserved if non-default');
}