about summary refs log tree commit homepage
path: root/lib/PublicInbox/Git.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-31 19:20:59 -1400
committerEric Wong <e@80x24.org>2021-01-01 20:55:31 +0000
commit171a9c24022ad7efef9248fc51fc357eed6aeb8a (patch)
tree7501b50755de45f76f42063fd4d5b698b592fe9c /lib/PublicInbox/Git.pm
parentaf0b0fb7a454470a32c452119d0392e0dedb3fe1 (diff)
downloadpublic-inbox-171a9c24022ad7efef9248fc51fc357eed6aeb8a.tar.gz
$git->qx and $git->popen now $env and $opt for redirects
like lower-level popen_rd.  This may be beneficial in other
places.
Diffstat (limited to 'lib/PublicInbox/Git.pm')
-rw-r--r--lib/PublicInbox/Git.pm14
1 files changed, 9 insertions, 5 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>;
 }