about summary refs log tree commit homepage
path: root/lib/PublicInbox/Git.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-01-26 04:27:02 +0000
committerEric Wong <e@80x24.org>2017-01-26 07:55:23 +0000
commitc3288fb27efcca73ba87e27c2c2b41b4a1dfbd46 (patch)
treea4afdc4f8aefc341ad5bbc6c5f7495592e6183c0 /lib/PublicInbox/Git.pm
parent9877e27be55f7a8d00a613630875d647d97d7bb3 (diff)
downloadpublic-inbox-c3288fb27efcca73ba87e27c2c2b41b4a1dfbd46.tar.gz
This shortens the code quite a bit at a negligible performance cost,
and the diffstat agrees.
Diffstat (limited to 'lib/PublicInbox/Git.pm')
-rw-r--r--lib/PublicInbox/Git.pm10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 648aaaf0..caca3b09 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -50,6 +50,11 @@ sub err ($) {
         $buf;
 }
 
+sub cmd {
+        my $self = shift;
+        [ 'git', "--git-dir=$self->{git_dir}", @_ ];
+}
+
 sub _bidi_pipe {
         my ($self, $batch, $in, $out, $pid) = @_;
         return if $self->{$pid};
@@ -58,9 +63,8 @@ sub _bidi_pipe {
         pipe($in_r, $in_w) or fail($self, "pipe failed: $!");
         pipe($out_r, $out_w) or fail($self, "pipe failed: $!");
 
-        my @cmd = ('git', "--git-dir=$self->{git_dir}", qw(cat-file), $batch);
         my $redir = { 0 => fileno($out_r), 1 => fileno($in_w) };
-        my $p = spawn(\@cmd, undef, $redir);
+        my $p = spawn(cmd($self, qw(cat-file), $batch), undef, $redir);
         defined $p or fail($self, "spawn failed: $!");
         $self->{$pid} = $p;
         $out_w->autoflush(1);
@@ -167,7 +171,7 @@ sub fail {
 
 sub popen {
         my ($self, @cmd) = @_;
-        my $cmd = [ 'git', "--git-dir=$self->{git_dir}" ];
+        my $cmd = cmd($self);
         my ($env, $opt);
         if (ref $cmd[0]) {
                 push @$cmd, @{$cmd[0]};