]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_store: quiet down "git var" failures
authorEric Wong <e@80x24.org>
Fri, 1 Jan 2021 09:20:59 +0000 (19:20 -1400)
committerEric Wong <e@80x24.org>
Fri, 1 Jan 2021 20:55:31 +0000 (20:55 +0000)
$git->qx and $git->popen now $env and $opt for redirects
like lower-level popen_rd.  This may be beneficial in other
places.

lib/PublicInbox/Git.pm
lib/PublicInbox/LeiStore.pm

index 49c0d5d60760c7c3d0a7c2149df22fc4c53811bc..f7332bb60e29a82b84ce49aacbe280ef01f0e665 100644 (file)
@@ -352,15 +352,19 @@ sub fail { # may be augmented in subclasses
        croak(ref($self) . ' ' . ($self->{git_dir} // '') . ": $msg");
 }
 
+# $git->popen(qw(show f00)); # or
+# $git->popen(qw(show f00), { GIT_CONFIG => ... }, { 2 => ... });
 sub popen {
-       my ($self, @cmd) = @_;
-       @cmd = ('git', "--git-dir=$self->{git_dir}", @cmd);
-       popen_rd(\@cmd);
+       my ($self, $cmd) = splice(@_, 0, 2);
+       $cmd = [ 'git', "--git-dir=$self->{git_dir}",
+               ref($cmd) ? @$cmd : ($cmd, grep { defined && !ref } @_) ];
+       popen_rd($cmd, grep { !defined || ref } @_); # env and opt
 }
 
+# same args as popen above
 sub qx {
-       my ($self, @cmd) = @_;
-       my $fh = $self->popen(@cmd);
+       my $self = shift;
+       my $fh = $self->popen(@_);
        local $/ = wantarray ? "\n" : undef;
        <$fh>;
 }
index a23efed55198e96c4ac5446c7681af235b58781c..7c62ffea0900155b72348eede2287ba599340c28 100644 (file)
@@ -54,7 +54,9 @@ sub git_epoch_max  {
 
 sub git_ident ($) {
        my ($git) = @_;
-       chomp(my $i = $git->qx(qw(var GIT_COMMITTER_IDENT)));
+       open my $null, '>', '/dev/null' or die "open /dev/null: $!";
+       my $opt = { 2 => $null };
+       chomp(my $i = $git->qx(qw(var GIT_COMMITTER_IDENT), undef, $opt));
        warn "$git->{git_dir} GIT_COMMITTER_IDENT failed\n" if $?;
        $i =~ /\A(.+) <([^>]+)> [0-9]+ [-\+]?[0-9]+$/ ? ($1, $2) :
                ('lei user', 'x@example.com')