-# Copyright (C) 2014-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: GPLv2 or later <https://www.gnu.org/licenses/gpl-2.0.txt>
#
# Used to read files from a git repository without excessive forking.
sub git_path ($$) {
my ($self, $path) = @_;
- $self->{-git_path}->{$path} ||= do {
+ $self->{-git_path}->{$path} //= do {
local $/ = "\n";
chomp(my $str = $self->qx(qw(rev-parse --git-path), $path));
$self->{alt_st} = $st; # always a true value
}
+sub object_format {
+ $_[0]->{object_format} //= do {
+ my $fmt = $_[0]->qx(qw(config extensions.objectformat));
+ $fmt eq "sha256\n" ? \'sha256' : \undef;
+ }
+}
+
sub last_check_err {
my ($self) = @_;
my $fh = $self->{err_c} or return;
return;
}
pipe(my ($out_r, $out_w)) or $self->fail("pipe failed: $!");
- my $rdr = { 0 => $out_r };
+ my $rdr = { 0 => $out_r, pgid => 0 };
my $gd = $self->{git_dir};
if ($gd =~ s!/([^/]+/[^/]+)\z!/!) {
$rdr->{-C} = $gd;
return; # unrecoverable error
}
}
- \substr($$rbuf, 0, $len, '');
+ my $no_pad = substr($$rbuf, 0, $len, '');
+ \$no_pad;
}
sub my_readline ($$) {
while (scalar(@{$self->{inflight_c} // []}) ||
scalar(@{$self->{inflight} // []})) {
for my $c ('', '_c') {
- my $q = $self->{"inflight$c"};
+ my $q = $self->{"inflight$c"} or next;
while (@$q) {
my ($req, $cb, $arg) = splice(@$q, 0, 3);
$req = $$req if ref($req);
sub DESTROY { cleanup(@_) }
sub local_nick ($) {
- my ($self) = @_;
- my $ret = '???';
# don't show full FS path, basename should be OK:
- if ($self->{git_dir} =~ m!/([^/]+)(?:/*\.git/*)?\z!) {
- $ret = "$1.git";
- }
- wantarray ? ($ret) : $ret;
+ $_[0]->{git_dir} =~ m!/([^/]+?)(?:/*\.git/*)?\z! ? "$1.git" : '???';
}
sub host_prefix_url ($$) {
if (my $urls = $self->{cgit_url}) {
return map { host_prefix_url($env, $_) } @$urls;
}
- local_nick($self);
+ (local_nick($self));
}
sub cat_async_begin {