From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 421461F4B4 for ; Fri, 1 Jan 2021 09:20:59 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] lei_store: quiet down "git var" failures Date: Thu, 31 Dec 2020 19:20:59 -1400 Message-Id: <20210101092059.31667-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: $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 | 14 +++++++++----- lib/PublicInbox/LeiStore.pm | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 49c0d5d6..f7332bb6 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -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>; } diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm index a23efed5..7c62ffea 100644 --- a/lib/PublicInbox/LeiStore.pm +++ b/lib/PublicInbox/LeiStore.pm @@ -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')